Skip to content

Fix "+00:00" and 0 being treated as UTC by Time#localtime and Time.at#9010

Merged
enebo merged 2 commits intojruby:masterfrom
philr:fix_time_zero_offset_non_utc
Sep 19, 2025
Merged

Fix "+00:00" and 0 being treated as UTC by Time#localtime and Time.at#9010
enebo merged 2 commits intojruby:masterfrom
philr:fix_time_zero_offset_non_utc

Conversation

@philr
Copy link
Contributor

@philr philr commented Sep 18, 2025

This PR changes Time#localtime and Time.at, so that it no longer treats a zone of "+00:00" or 0 as UTC (i.e. Time#utc? will return false). It resolves #8998.

I've included some additional test cases from ruby/spec#1285.

The fixes to both methods reset isTzRelative to false and then use handleUTCDateTimeZone to determine the time zone instead of getTimeZoneFromUtcOffset. handleUTCDateTimeZone calls getTimeZoneFromUtcOffset and contains the necessary checks to determine if the specified zone should be treated as UTC. It sets isTzRelative to true if not. The call to adjustTimeZone is then made with the newly set isTzRelative value.

@philr
Copy link
Contributor Author

philr commented Sep 18, 2025

The test failure is unrelated to this change.

@enebo enebo merged commit 18a6719 into jruby:master Sep 19, 2025
74 of 75 checks passed
@enebo enebo added this to the JRuby 10.0.3.0 milestone Sep 19, 2025
@enebo
Copy link
Member

enebo commented Sep 19, 2025

@philr not sure if you tried running mspec without ci options on Time after this fix but there are other UTC/number failures which are tagged out (spec/tags/ruby/core/time/*).

Thanks for the fix. Time and Date have been tough to address all failures.

@enebo
Copy link
Member

enebo commented Sep 19, 2025

@philr Just tried and nothing else passed as a result of this which I guess makes sense.

@headius
Copy link
Member

headius commented Sep 20, 2025

@philr Nice, thank you for the patch! This turned out easier than expected.

@philr philr deleted the fix_time_zero_offset_non_utc branch September 21, 2025 15:40
@philr
Copy link
Contributor Author

philr commented Sep 21, 2025

@enebo thanks for merging this.

I looked through the tagged out tests expecting to see something related, but found it wasn't covered. I hadn't run without the ci option, but wasn't expecting anything else to start passing.

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.

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

3 participants