Repository navigation
Keep the UTC offset in Time#change for times with a zone object - #59617
Open
thomasklemm wants to merge 1 commit into
Open
thomasklemm wants to merge 1 commit into
thomasklemm wants to merge 1 commit into
Conversation
Time#change built the new time with Time.new(..., zone) and then moved it to the second occurrence of a repeated hour when that matched the original offset. For a TZInfo::Timezone with TZInfo's default ambiguity settings, Time.new raises TZInfo::AmbiguousTime for a local time in the repeated hour, so change(nsec:), change(hour:) and Active Model's datetime cast, when precision truncation is needed, raised there. Where the zone picks the other occurrence, as ActiveSupport::TimeZone does for Europe/Dublin (whose winter time counts as DST), the original offset was missed and change returned a time one hour later. It now tries the original UTC offset first and keeps it when the zone gives that offset for the new local time, which is the occurrence change already meant to pick, and builds the time from the zone as before otherwise. When neither occurrence of the new local time has the original offset, the zone picks as before, so a TZInfo zone still raises there; a time in a skipped hour still raises as before.
thomasklemm
force-pushed
the
thomasklemm/time-change-zone-offset
branch
from
November 4, 2026 14:29
d5252fa to
553f926
Compare
This branch has not been deployed
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.
On a
Timewhose zone is an object (TZInfo::TimezoneorActiveSupport::TimeZone),changecouldn't stay in the hour that repeats when clocks go back. TZInfo zones raisedTZInfo::AmbiguousTime, also from Active Model's datetime cast when it truncates precision.ActiveSupport::TimeZonecould jump to the other occurrence of that hour.changenow tries the time's own UTC offset first and keeps it when the zone agrees. Otherwise the zone decides, as before.At 00:30 UTC on 2026-10-25, both zones are in the first of two identical local hours:
change(sec: 1)on mainTZInfo::TimezoneAmbiguousTimeActiveSupport::TimeZoneStill unchanged: an ambiguous time raises when neither occurrence has the original offset, and a time in the skipped spring hour raises
PeriodNotFound.Compared with main for every TZInfo and
ActiveSupport::TimeZonezone around each transition up to 2037, results differ only where main raised or picked the other occurrence, and the tests cover both clock changes.