Skip to content

Do not look up UTC offsets in the timezone cache shared with TZ values - #10069

Merged
headius merged 2 commits into
jruby:jruby-10.0from
taxor03:fix-time-utc-cache-10.0
Nov 17, 2026
Merged

headius merged 2 commits into
jruby:jruby-10.0from
taxor03:fix-time-utc-cache-10.0

Conversation

@taxor03

@taxor03 taxor03 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #10065.

getTimeZoneFromUtcOffset looked up arg.toString() in the runtime's timezone cache before parsing the zone argument. That cache also holds the zones for TZ values, where "UTC" is Etc/UTC so that Time.now is not utc?. With TZ=UTC, the "UTC" zone argument got Etc/UTC instead of DateTimeZone.UTC, so Time.new(2022, 1, 1, 0, 0, 0, "UTC"), localtime("UTC"), getlocal("UTC"), Time.at(t, in: "UTC") and Time.now(in: "UTC") were not utc?.

This removes the lookup and the matching put. Parsing the argument is cheap, and the zone for an offset is still cached by getTimeZoneWithOffset. ENV["TZ"] = "UTC"; Time.now.utc? stays false, as in CRuby.

The shared key also let strings through that are not valid offsets. These now raise ArgumentError like in CRuby 4.0.9 and 3.4.12:

code before after
ENV["TZ"] = "GMT"; Time.now; Time.new(2000, 1, 1, 0, 0, 0, "GMT") 2000-01-01 00:00:00 +0000 ArgumentError
Time.new(2000, 1, 1, 0, 0, 0, 3600); Time.new(2000, 1, 1, 0, 0, 0, "3600") 2000-01-01 00:00:00 +0100 ArgumentError

The second case is why "raises ArgumentError if the String argument is not of the form (+|-)HH:MM" for Time.new, Time#getlocal and Time#localtime failed in a full core/time run 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 inside with_timezone("UTC"). It fails before this change and passes after it, and passes on CRuby 4.0.9 and 3.4.12. Tested with spec/ruby/core/time, spec/ruby/library/time and spec/ruby/library/date (also with -Xjit.threshold=0 and -X-C, and core/time with TZ=UTC), test/mri/ruby/test_time.rb, test/mri/ruby/test_time_tz.rb, test/jruby/test_time.rb and the fast RubySpec suite. No new failures.

The commit cherry-picks cleanly onto master, and the new spec and spec/ruby/core/time pass there with the default parser and with -Xparser.prism.

@kares kares added this to the JRuby 10.0.9.0 milestone Nov 17, 2026

@headius headius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Would be good to try some benchmarks of TZ acquisition.

@headius
headius merged commit 110bfde into jruby:jruby-10.0 Nov 17, 2026
226 of 227 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants