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: RFC1123{,Z} format strings appear to be very slightly wrong #67887

Closed
dburkart opened this issue Jun 7, 2024 · 3 comments
Closed

time: RFC1123{,Z} format strings appear to be very slightly wrong #67887

dburkart opened this issue Jun 7, 2024 · 3 comments
Labels
Documentation Issues describing a change to documentation. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dburkart
Copy link
Contributor

dburkart commented Jun 7, 2024

Go version

go version go1.22.1 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/dburkart/Library/Caches/go-build'
GOENV='/Users/dburkart/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/dburkart/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/dburkart/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/1m/2p4knn216k755wpkh1vlz4_00000gn/T/go-build1317344447=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

We have been using time.RFC1123Z to parse the Date header of emails.

We found that sometimes this would work, and sometimes it would not. I tracked this down to "the time of the month". Specifically, if you try to parse an email date from days 1 - 9 of the month, time.Parse() with time.RFC1123Z throws an error, but on days 10 - 3x, it parses just fine.

Specifically, it seems that this part of RFC 1123 indicates that the day can only be 2 digits if the first is a '1' one or two digits:

date = 1*2DIGIT month 2*4DIGIT

This means that a Date string (that I pulled from one of my emails) like this doesn't parse:

Fri, 7 Jun 2024 13:04:42 -0400

But this will:

Fri, 31 May 2024 09:57:48 +0000

What did you see happen?

Most of the time this works, but sometimes it does not.

What did you expect to see?

It should always work, since RFC 1123 defines the date / time expected in an email header.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/591335 mentions this issue: time: remove the leading 0 from the day in time.RFC1123{,Z}

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 7, 2024
@mknyszek mknyszek added this to the Backlog milestone Jun 7, 2024
@gabyhelp
Copy link

gabyhelp commented Jun 8, 2024

@rsc
Copy link
Contributor

rsc commented Jun 8, 2024

Duplicate of #34459.

In particular note #34459 (comment), which points out that the doc comment already 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 and they do accept time formats not formally
defined.

@rsc rsc closed this as completed Jun 8, 2024
gopherbot pushed a commit that referenced this issue Jun 11, 2024
…for parsing

When using time.RFC1123Z to parse the date header value out of an email,
an error is returned for dates that occur in the first 9 days of a
month. This is because the format strings for RFC 1123 defined in the
time package indicate that the day should be prefixed with a leading 0.

Reading the spec, the line that talks about it seems to indicate that
days can be either 1 or 2 digits:

  `date = 1*2DIGIT month 2*4DIGIT`

So a date header with a day like `7` with no leading zero should be
accepted.

Fixes #67887

Change-Id: Ie7ee40d94da2c8c0417957e8b89f9987314949c8
GitHub-Last-Rev: 22a5a52
GitHub-Pull-Request: #67888
Reviewed-on: https://go-review.googlesource.com/c/go/+/591335
LUCI-TryBot-Result: Go LUCI <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Michael Pratt <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
@dmitshur dmitshur modified the milestones: Backlog, Go1.23 Jun 11, 2024
@dmitshur dmitshur added Documentation Issues describing a change to documentation. NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues describing a change to documentation. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants