Description
Hello π With the following code:
<?php
$date = new DateTime('2024-11-03 01:30:00 America/Toronto -0500');
echo $date->format('Y-m-d H:i:s e O');
Resulted in this output:
2024-11-03 01:30:00 America/Toronto -0400
https://3v4l.org/qg4aN
But I expected this output instead:
2024-11-03 01:30:00 America/Toronto -0500
Both exist, and it's possible to obtain the first with:
$date = new DateTime('@1730611800');
$date->setTimezone(new DateTimeZone('America/Toronto'));
As per the test above, it sounds like whatever offset coming after a named timezone like "America/Toronto" is ignored, so we can have the timezone set by name or by offset but we cannot have both while it's actually needed to distinguish 2 possibly different moments during DST such as Nov 3rd 1:30 -0400 and Nov 3rd 1:30 -0500 which both exist in America/Toronto.
A possible implementation would to:
- Detect both named timezone and offset timezone,
- if only one is present:
- no change: keep current behavior
- if both are present:
- and the current date-time + timezone offset exist in the given timezone city
- but the current date-time + timezone offset is invalid
- ignore offset (i.e. current behavior)
Thanks π
PHP Version
PHP 8.3.12 and also 8.4.0-dev (78767de)
Description
Hello π With the following code:
Resulted in this output:
https://3v4l.org/qg4aN
But I expected this output instead:
Both exist, and it's possible to obtain the first with:
As per the test above, it sounds like whatever offset coming after a named timezone like "America/Toronto" is ignored, so we can have the timezone set by name or by offset but we cannot have both while it's actually needed to distinguish 2 possibly different moments during DST such as
Nov 3rd 1:30 -0400andNov 3rd 1:30 -0500which both exist inAmerica/Toronto.A possible implementation would to:
Thanks π
PHP Version
PHP 8.3.12 and also 8.4.0-dev (78767de)