You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Time.new(..., "UTC") and localtime("UTC") are not utc? when ENV["TZ"] is "UTC" #10065
When the TZ environment variable is "UTC", a Time made with the "UTC" zone argument is not a UTC time: Time.new(2022, 1, 1, 0, 0, 0, "UTC").utc?, Time.now.localtime("UTC").utc?, and the same with in: "UTC" or getlocal("UTC"), return false, and inspect shows +0000 instead of UTC. With TZ unset or set to another zone they return true, and "Z" and "-00:00" give a UTC time under every TZ. In CRuby the "UTC" zone argument always gives a UTC time; only times made in the local zone, like Time.now, are not utc? when TZ is "UTC" (Time#utc?).
JRuby 10.1.3.0 (jruby 10.1.3.0 (4.0.9) 2026-11-05 3db52d02f9 OpenJDK 64-Bit Server VM 21.0.13+9-LTS on 21.0.13+9-LTS +indy +jit [aarch64-linux]) and a build of master (54dd973) print the same.
The wrong zone stays for the rest of the process: once Time.now has run with TZ set to "UTC", Time.new(2022, 1, 1, 0, 0, 0, "UTC").utc? is still false after TZ is changed to "Asia/Seoul".
getTimeZoneFromTZString caches the zone for a TZ value in the runtime's timezone cache under the TZ string (RubyTime.java#L189-L195), and maps "UTC" to Etc/UTC on purpose so that Time.now is not utc? (L220-L225). getTimeZoneFromUtcOffset, which handles the zone argument, first looks up arg.toString() in the same cache (L255-L257), so it returns Etc/UTC before it reaches its "UTC" check that returns DateTimeZone.UTC (L289). isUTC() requires DateTimeZone.UTC (L661-L662). Master has the same code (L254-L257, L653-L654). In CRuby, utc_offset_arg returns UTC_ZONE for "UTC" whatever TZ is (time.c#L2247-L2248).
ruby/spec's "does treat time with 'UTC' offset as UTC" (utc_spec.rb#L20-L27) checks these calls, but it fails only when the spec process runs with TZ=UTC. #9436 is a different case (times in the local zone reported as utc? when TZ is unset and the system zone is UTC).
Found while comparing JRuby with CRuby on ruby/spec-based checks.
Activity
headius commentedon Nov 17, 2026
Fixed by #10069. Thanks!