-
Notifications
You must be signed in to change notification settings - Fork 18k
time: document that RFC3339 accepts invalid formats when used with Parse #37616
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
Comments
As the documentation says, " RFC3339, 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." We can't change We aren't going to add a new constant just to use with |
I hear your point, but the existing documentation says only that they don't accept all formats permitted. The docs don't say that they do accept formats prohibited by the RFCs, which is what I demonstrate. If you don't want to change the existing constant (which I fully accept), or provide correct constants (which I question), what do you think about one or both of these:
I'm happy to send a PR if we can agree in advance on what it should generally contain. |
The title and description mention two digit "year". Is this intentional, or should it say "hour"? |
Yes, thanks. Fixed the title. |
I don't think it is possible to write a time format that works with I'm fine with adding a clause saying that the various formats accept invalid strings when used with |
Change https://golang.org/cl/229460 mentions this issue: |
What version of Go are you using (
go version
)?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:
What did you see instead?
The parse succeeded.
This could be fixed by changing
time.RFC3339
to2006-01-02T03:04:05Z07:00
. If this is deemed a backward incompatible change, adding a newtime.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.The text was updated successfully, but these errors were encountered: