Respect timezone offset given after timezone name
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
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
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
- apply both
- but the current date-time + timezone offset is invalid
- ignore offset (i.e. current behavior)
- and the current date-time + timezone offset exist in the given timezone city
Thanks 🙏
PHP Version
PHP 8.3.12 and also 8.4.0-dev (78767de197d1b2a6d2dd2757258b4c642bda8052)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior with the DateTime constructor using the America/Toronto name and -0500 offset, then compare it with the @timestamp and setTimezone example. Trace the date-time parsing entry point and add coverage for both valid November 3, 2024 offsets; done means the explicit offset is respected when it identifies an existing local time and current behavior remains for invalid combinations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 34/100