Skip to content
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: Parse does not cover all valid RFC1123Z dates #34459

Closed
bodqhrohro opened this issue Sep 22, 2019 · 9 comments
Closed

time: Parse does not cover all valid RFC1123Z dates #34459

bodqhrohro opened this issue Sep 22, 2019 · 9 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@bodqhrohro
Copy link

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

$ go version
go version go1.12.9 linux/amd64

Does this issue reproduce with the latest release?

Probably, as I got the same behavior at Playground.

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/bodqhrohro/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/opt/gone"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go-1.12"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.12/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/data/progs/go/smstree/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build184744936=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://play.golang.org/p/aaUf5zpzKXj

What did you expect to see?

According to the standard, a one-digit day is valid.

      5.2.14  RFC-822 Date and Time Specification: RFC-822 Section 5

         The syntax for the date is hereby changed to:

            date = 1*2DIGIT month 2*4DIGIT

What did you see instead?

parsing time "Mon, 5 Aug 2019 17:21:53 +0300" as "Mon, 02 Jan 2006 15:04:05 -0700": cannot parse "5 Aug 2019 17:21:53 +0300" as "02"
@toothrot toothrot changed the title time.RFC1123Z does not cover all valid dates time: Parse does not cover all valid RFC1123Z dates Sep 23, 2019
@gregory-m
Copy link
Contributor

RFC822 also allow day to be one or two digits:

date        =  1*2DIGIT month 2DIGIT        ; day month year

For date fix is trivial but we don't have placeholder for 2 or 4 digits year.

On another way RFC1123 say:

  All mail software SHOULD use 4-digit years in dates, to ease
         the transition to the next century.

So maybe its not needed to implement it.

@bcmills
Copy link
Contributor

bcmills commented Sep 23, 2019

This is unfortunate, but it's been that way since CL 196090, 9½(!) years ago.

CC @robpike, but I don't think we can change the constant now — at best, perhaps we could add a new constant and document the difference.

@bcmills bcmills added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Sep 23, 2019
@bcmills bcmills added this to the Go1.14 milestone Sep 23, 2019
@agnivade
Copy link
Contributor

FWIW, you can define your own constant without the zero padding. That can parse both zero padded and single digit days. https://play.golang.org/p/gTZHbhp7J5C

@bodqhrohro
Copy link
Author

@agnivade I already did bodqhrohro/smstree@5f28f5b

@robpike
Copy link
Contributor

robpike commented Sep 23, 2019

I think the compatibility guidelines make it hard to fix this constant. We could add another one, but I don't think it's worth it. As already said, it's easy to write one's own.

@bodqhrohro
Copy link
Author

Okay, but it would be good to add a notice to documentation, that the constants don't completely conform the standards and should be used with caution. I was lucky to discover it this early, but others may be less lucky.

@ianlancetaylor
Copy link
Contributor

This seems related to #20869.

Note that the documentation already explicitly 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." (https://golang.org/pkg/time/#pkg-constants).

I don't really see anything else to do here.

@bodqhrohro
Copy link
Author

the documentation already explicitly says

Didn't notice that, sorry. Then yes, there's nothing to do right now. Though, would it be added in the roadmap for a next major release, if it is planned already?

@bcmills
Copy link
Contributor

bcmills commented Sep 26, 2019

Then yes, there's nothing to do right now.

Given that at least three of us chimed in on this issue without noticing the documentation, I'd say that the documentation is not very discoverable — that particular section is so verbose that this (perhaps important) detail ended up buried.

That said, I don't see a way to make it more concise without dropping something equally important, so closing.

@bcmills bcmills closed this as completed Sep 26, 2019
@golang golang locked and limited conversation to collaborators Sep 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

7 participants