Skip to content

time: RFC3339 format parsing is both too lax and too strict #20869

@oschwald

Description

@oschwald

As of Go 1.8.3, the RFC3339 format has several inconsistencies with the actual RFC when parsing a string:

  1. One digit hours are incorrectly allowed, e.g., 2017-04-09T0:38:00.00Z. I assume this is because there is no stdZeroHour similar to stdZeroHour12 ("03").
  2. The format is case sensitive. The RFC says:
  NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this
 syntax may alternatively be lower case "t" or "z" respectively.

 This date/time format may be used in some environments or contexts
 that distinguish between the upper- and lower-case letters 'A'-'Z'
 and 'a'-'z' (e.g. XML).  Specifications that use this format in
 such environments MAY further limit the date/time syntax so that
 the letters 'T' and 'Z' used in the date/time syntax must always
 be upper case.  Applications that generate this format SHOULD use
 upper case letters.

Also, it does not parse leap seconds, which are explicitly allowed under the standard, but that seems more like an intentional design decision.

In reporting this, I am assuming the omission of RFC3339 from the comment:

RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs.

suggests that you should be able to parse all time formats permitted by it.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions