Repository navigation
Use the parsed offset in ZonedDateTime::parse() when a region is present - #140
Merged
Merged
Conversation
from() discarded the parsed offset and resolved the local date-time against
the region again. In a DST overlap, the first occurrence therefore parsed
as the second one, so parse((string) $zdt) did not round-trip, and an offset
that the region does not use at that time was silently replaced:
ZonedDateTime::parse('2024-10-27T02:30+02:00[Europe/Zurich]'); // +01:00, one hour later
ZonedDateTime::parse('2024-06-01T12:00Z[Europe/Zurich]'); // 12:00+02:00, another instant
The instant is now computed from the local date-time and the offset, and a
DateTimeException is thrown when that offset is not valid for the region.
A test fixture used -07:00 for America/Los_Angeles in February, an offset
that only passed because it was ignored; it now uses -08:00.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fm9bvgKFasEGzpK48bQrxA
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #140 +/- ##
=========================================
Coverage 99.24% 99.24%
- Complexity 1141 1143 +2
=========================================
Files 48 48
Lines 2501 2517 +16
=========================================
+ Hits 2482 2498 +16
Misses 19 19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
BenMorel
reviewed
Oct 10, 2026
…rse() Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fm9bvgKFasEGzpK48bQrxA
Member
|
Thank you, @gnutix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item 1 of #137, with the stricter behaviour suggested there.
Problem
ZonedDateTime::from()parsed the offset, then discarded it and resolved the local date-time against the region again:Change
DateTimeExceptionis thrown:The offset Z is not valid for 2024-06-01T12:00 in Europe/Zurich.when the region doesn't use that offset at that time;The local date-time 2024-03-31T02:30 does not exist in Europe/Zurich.when the local date-time falls in a DST gap.toString()→parse()round-trips.This is a behaviour change: input with an offset that doesn't match the region used to be accepted silently, and now throws.
One existing fixture (
ZonedDateTimeTest,testPlusPeriod/testMinusPerioddata set #11) used-07:00for America/Los_Angeles in February. It only passed because the offset was ignored, and now uses-08:00; the expected result is unchanged.🤖 Generated with Claude Code
https://claude.ai/code/session_01Fm9bvgKFasEGzpK48bQrxA