Repository navigation
Do not look up UTC offsets in the timezone cache shared with TZ values - #10069
Merged
Merged
Conversation
headius
approved these changes
Nov 17, 2026
headius
left a comment
Member
There was a problem hiding this comment.
LGTM. Would be good to try some benchmarks of TZ acquisition.
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.
Fixes #10065.
getTimeZoneFromUtcOffsetlooked uparg.toString()in the runtime's timezone cache before parsing the zone argument. That cache also holds the zones forTZvalues, where"UTC"isEtc/UTCso thatTime.nowis notutc?. WithTZ=UTC, the"UTC"zone argument gotEtc/UTCinstead ofDateTimeZone.UTC, soTime.new(2022, 1, 1, 0, 0, 0, "UTC"),localtime("UTC"),getlocal("UTC"),Time.at(t, in: "UTC")andTime.now(in: "UTC")were notutc?.This removes the lookup and the matching
put. Parsing the argument is cheap, and the zone for an offset is still cached bygetTimeZoneWithOffset.ENV["TZ"] = "UTC"; Time.now.utc?staysfalse, as in CRuby.The shared key also let strings through that are not valid offsets. These now raise
ArgumentErrorlike in CRuby 4.0.9 and 3.4.12:ENV["TZ"] = "GMT"; Time.now; Time.new(2000, 1, 1, 0, 0, 0, "GMT")2000-01-01 00:00:00 +0000ArgumentErrorTime.new(2000, 1, 1, 0, 0, 0, 3600); Time.new(2000, 1, 1, 0, 0, 0, "3600")2000-01-01 00:00:00 +0100ArgumentErrorThe second case is why "raises ArgumentError if the String argument is not of the form (+|-)HH:MM" for
Time.new,Time#getlocalandTime#localtimefailed in a fullcore/timerun and were tagged. Those three tags are removed, and so is the tag for "Time#localtime raises ArgumentError if the String argument is not in an ASCII-compatible encoding", which failed in a full run for the same reason (the UTF-16LE"-01:00"found the zone cached for an earlier ASCII"-01:00") and passes now.This adds "does treat time with 'UTC' offset as UTC when the local time zone is UTC" to
spec/ruby/core/time/utc_spec.rb, which runs the existing checks insidewith_timezone("UTC"). It fails before this change and passes after it, and passes on CRuby 4.0.9 and 3.4.12. Tested withspec/ruby/core/time,spec/ruby/library/timeandspec/ruby/library/date(also with-Xjit.threshold=0and-X-C, andcore/timewithTZ=UTC),test/mri/ruby/test_time.rb,test/mri/ruby/test_time_tz.rb,test/jruby/test_time.rband the fast RubySpec suite. No new failures.The commit cherry-picks cleanly onto master, and the new spec and
spec/ruby/core/timepass there with the default parser and with-Xparser.prism.