Skip to content

Time#localtime incorrectly treats zero offset as UTC (regression in v10.0.2.0) #8998

Description

@philr

Environment Information

$ jruby -v
jruby 10.0.2.0 (3.4.2) 2025-08-07 cba6031bd0 OpenJDK 64-Bit Server VM 21.0.8+9-Ubuntu-0ubuntu122.04.1 on 21.0.8+9-Ubuntu-0ubuntu122.04.1 +indy +jit [x86_64-linux]

$ uname -a
Linux linuxdev 5.15.0-153-generic #163-Ubuntu SMP Thu Aug 7 16:37:18 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Expected Behaviour

In MRI (version 3.4.5 and earlier), using Time#localtime to set the offset to 0 does not set the time instance to UTC (the offset returned in the #to_s string representation is '+0000' and #utc? returns false):

$ ruby -e 't = Time.at(1757243858).localtime(0); puts t; puts t.utc_offset; puts t.utc?'
2025-09-07 11:17:38 +0000
0
false

Actual Behaviour

JRuby version 10.0.2.0 sets the time instance to UTC (the offset returned in the #to_s string representation is 'UTC' instead of '+0000' and #utc? returns true instead of false):

$ jruby -e 't = Time.at(1757243858).localtime(0); puts t; puts t.utc_offset; puts t.utc?'
2025-09-07 11:17:38 UTC
0
true

This has changed in version 10.0.2.0. JRuby version 10.0.1.0 matches the MRI behaviour:

jruby -e 't = Time.at(1757243858).localtime(0); puts t; puts t.utc_offset; puts t.utc?'
2025-09-07 11:17:38 +0000
0
false

Activity

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions