New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
oschwald opened this Issue Jun 30, 2017 · 3 comments

Comments

Projects
None yet
6 participants
@oschwald
Copy link

oschwald commented Jun 30, 2017

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.

@oschwald oschwald changed the title RFC3339 format parsing is both too lax and too string RFC3339 format parsing is both too lax and too strict Jun 30, 2017

@ALTree ALTree changed the title RFC3339 format parsing is both too lax and too strict time: RFC3339 format parsing is both too lax and too strict Jun 30, 2017

@ALTree ALTree added this to the Go1.10 milestone Jul 18, 2017

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Oct 28, 2017

Change https://golang.org/cl/74231 mentions this issue: time: document valid layouts are not valid Parse values

@kennygrant

This comment has been minimized.

Copy link
Contributor

kennygrant commented Oct 29, 2017

See also #11128

gopherbot pushed a commit that referenced this issue Oct 31, 2017

time: document that valid layouts are not valid Parse values
For #9346 #22135 explicitly state under layout constants
that they are not valid time values for Parse. Also add
examples of parsing valid RFC3339 values and the layout
to the example for time.Parse.

Fix capitalisation of time.Parse and Time.Format.

For #20869 include RFC3339 in the list of layouts that do
not accept all the time formats allowed by RFCs (lowercase z).
This does not fully address #20869.

Fixes #9346
Fixes #22135

Change-Id: Ia4c13e5745de583db5ef7d5b1688d7768bc42c1b
Reviewed-on: https://go-review.googlesource.com/74231
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Nov 22, 2017

Given that generators should generate T and Z, not t and z, I'm not particularly inclined to try to fix this.

@rsc rsc modified the milestones: Go1.10, Go1.11 Nov 22, 2017

@bradfitz bradfitz modified the milestones: Go1.11, Unplanned Jun 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment