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.

Comment From: gopherbot

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

Comment From: gabyhelp

Related Issues

  • https://github.com/golang/go/issues/34459
  • https://github.com/golang/go/issues/39906
  • https://github.com/golang/go/issues/39260
  • https://github.com/golang/go/issues/41822
  • https://github.com/golang/go/issues/67888

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: rsc

Duplicate of #34459.

In particular note https://github.com/golang/go/issues/34459#issuecomment-534377512, 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.