Skip to content

time: document that RFC3339 accepts invalid formats when used with Parse #37616

@xdg

Description

@xdg

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

$ go version
go version go1.13 darwin/amd64

Does this issue reproduce with the latest release?

It reproduces on play.golang.org and the underlying issue is still present in the source.

What operating system and processor architecture are you using (go env)?

darwin/amd64

What did you do?

Parsed a faulty ISO 8601 string with a single-digit hour using time.RFC3339. E.g. 2020-02-02T2:02:02Z.

What did you expect to see?

I expected this parse to error because RFC-3339 sec 5.6 defines the following token, requiring two digits for the hour:

time-hour       = 2DIGIT  ; 00-23

What did you see instead?

The parse succeeded.

This could be fixed by changing time.RFC3339 to 2006-01-02T03:04:05Z07:00. If this is deemed a backward incompatible change, adding a new time.RFC3339Strict constant would also be an acceptable option.

See https://play.golang.org/p/6qyFYfx6pMr for example with one and two-digit years with time.Parse3339 and the stricter version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions