Skip to content

time: Parsing of GMT+XX offsets is broken #56392

@jwebb

Description

@jwebb

What version of Go are you using (go version)?

1.19.1

Does this issue reproduce with the latest release?

Yes

What did you do?

https://go.dev/play/p/e5jcM1fIJm9?v=gotip (case 4 is the bug)

What did you expect to see?

GMT+2, if it is parsed at all, ought to be treated the same as +0200 (or -0200, according to Posix).

What did you see instead?

It causes the time to be parsed as UTC, but be labelled as though an offset were applied.

When applying a known zone abbreviation the time is shifted at https://cs.opensource.google/go/go/+/refs/tags/go1.19.2:src/time/format.go;l=1365;drc=85196fc982ead65ea56c377c2e381eabff329773;bpv=0;bpt=1 - it seems the same should be done at L1373.

However, this GMT+XX format parsing has a bunch of special-case code, supported by a single test, which checks the wrong input, and it's been this way forever without anyone noticing apparently. And as noted in #40472, it's undocumented and interacts confusingly with the ISO/RFC822 style. Further, as noted in my case 3 above, the direction of the offset in this notation has conflicting conventions. So I'd suggest just removing this from the parser entirely.

(I encountered this only because I was reading the code looking for a way to detect my case 5 and turn it into an error - which sadly seems impossible in general without separately parsing zoneinfo.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions