Skip to content

Time.new reads an offset of -0000 or -00 as +00:00 rather than UTC, unlike CRuby, and so does Time.iso8601 since 10.1.3.0 #10016

Open

Description

@reidmorrison

Time.new reads an offset of -0000 or -00 as a fixed offset of zero, +00:00, where CRuby reads it as UTC, as both read -00:00. This applies to the String form, such as Time.new("2026-10-31T09:30:00-0000"), and to the zone argument, such as Time.new(2026, 10, 31, 9, 30, 0, "-0000").

Up to JRuby 10.1.2.0 this did not show through Time.iso8601, since the time gem 0.4.2 read the offset itself. JRuby 10.1.3.0 bundles the time gem 0.5.0, whose Time.xmlschema (and so Time.iso8601) hands the text to Time.new on Ruby 3.2 and later (Time._xmlschema in time.rb), so Time.iso8601("2026-10-31T09:30:00-0000").utc? changed from true to false in 10.1.3.0. CRuby 4.0.7 with the time gem 0.5.0 still returns true, since its Time.new reads -0000 as UTC.

Reproduction

require "time"

%w[-0000 -00 -00:00 +0000 Z].each do |offset|
  text      = "2026-10-31T09:30:00#{offset}"
  from_new  = Time.new(text)
  from_args = Time.new(2026, 10, 31, 9, 30, 0, offset)
  iso       = Time.iso8601(text)
  puts format("%-7s Time.new(text).utc? %-5s  Time.new(..., offset).utc? %-5s  Time.iso8601(text).utc? %s",
              offset, from_new.utc?, from_args.utc?, iso.utc?)
end

Output

CRuby 3.4.11 and 4.0.7, the latter also with the time gem 0.5.0:

-0000   Time.new(text).utc? true   Time.new(..., offset).utc? true   Time.iso8601(text).utc? true
-00     Time.new(text).utc? true   Time.new(..., offset).utc? true   Time.iso8601(text).utc? true
-00:00  Time.new(text).utc? true   Time.new(..., offset).utc? true   Time.iso8601(text).utc? true
+0000   Time.new(text).utc? false  Time.new(..., offset).utc? false  Time.iso8601(text).utc? false
Z       Time.new(text).utc? true   Time.new(..., offset).utc? true   Time.iso8601(text).utc? true

JRuby 10.0.7.0 and 10.1.2.0 (time gem 0.4.2):

-0000   Time.new(text).utc? false  Time.new(..., offset).utc? false  Time.iso8601(text).utc? true
-00     Time.new(text).utc? false  Time.new(..., offset).utc? false  Time.iso8601(text).utc? true
-00:00  Time.new(text).utc? true   Time.new(..., offset).utc? true   Time.iso8601(text).utc? true
+0000   Time.new(text).utc? false  Time.new(..., offset).utc? false  Time.iso8601(text).utc? false
Z       Time.new(text).utc? true   Time.new(..., offset).utc? true   Time.iso8601(text).utc? true

JRuby 10.1.3.0 (time gem 0.5.0):

-0000   Time.new(text).utc? false  Time.new(..., offset).utc? false  Time.iso8601(text).utc? false
-00     Time.new(text).utc? false  Time.new(..., offset).utc? false  Time.iso8601(text).utc? false
-00:00  Time.new(text).utc? true   Time.new(..., offset).utc? true   Time.iso8601(text).utc? true
+0000   Time.new(text).utc? false  Time.new(..., offset).utc? false  Time.iso8601(text).utc? false
Z       Time.new(text).utc? true   Time.new(..., offset).utc? true   Time.iso8601(text).utc? true

Expected

As CRuby: -0000 and -00 are UTC, like -00:00 and Z, while +0000 keeps an offset of zero. RFC 3339 (section 4.3) and RFC 2822 (section 3.3) use -00:00 and -0000 for a time in UTC whose local offset is not known. Code that tells UTC from +00:00, for example to write Z rather than +00:00, reads the same text differently on JRuby, and since 10.1.3.0 through Time.iso8601 too.

Environment

JRuby 10.0.7.0 (3.4.5), 10.1.2.0 (4.0.0) and 10.1.3.0 (4.0.9), OpenJDK 25.0.2, macOS arm64. CRuby 3.4.11 and 4.0.7 for comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions