Skip to content

Accept GMT/UTC-prefixed numeric offsets in Time.zone_offset - #86

Open
afurm wants to merge 1 commit into
ruby:masterfrom
afurm:fix-zone-offset-gmt-prefix
Open

afurm wants to merge 1 commit into
ruby:masterfrom
afurm:fix-zone-offset-gmt-prefix

Conversation

@afurm

@afurm afurm commented Oct 10, 2026

Copy link
Copy Markdown
Member

Summary

Time.parse and strptime with %Z ignore offsets like GMT+0300 and UTC-05:30 (the JavaScript Date#toString format) and silently fall back to local time, while DateTime.parse already handles them.

Detail

I added an optional GMT/UTC prefix on the numeric offset forms that Time.zone_offset already accepts. Single-digit forms such as GMT+3 stay unsupported because of POSIX sign ambiguity. This does not touch timezone abbreviations, unlike rejected Bug #12190.

Test

Added coverage for GMT±HHMM, UTC±HH:MM, and related prefixed numeric offsets through Time.zone_offset / Time.parse.

Time.parse and Time.strptime silently ignored offsets such as
"GMT+0300" or "UTC-05:30" and returned a local time instead, because
Time.zone_offset only recognized bare numeric offsets. This is the
format produced by JavaScript's Date#toString, e.g.
"Sat Oct 10 2026 10:47:00 GMT+0300 (Eastern European Summer Time)",
so the parsed instant was off by the difference between the given
offset and the local one. Date._parse and DateTime.parse already
handle these offsets.

Allow an optional GMT or UTC prefix before the numeric offset forms
that zone_offset already supports.

This branch has not been deployed

No deployments
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.

1 participant