Skip to content

time: time zone parsing when format includes time zone seconds fails #68263

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

Closed
darinkrauss opened this issue Jul 1, 2024 · 4 comments
Closed
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@darinkrauss
Copy link
Contributor

Go version

go version go1.22.4 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/deke/Library/Caches/go-build'
GOENV='/Users/deke/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/deke/.gvm/pkgsets/go1.22.4/global/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/deke/.gvm/pkgsets/go1.22.4/global'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/deke/.gvm/gos/go1.22.4'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/deke/.gvm/gos/go1.22.4/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
GOAMD64='v1'
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 x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/kx/hbhfkyvn3d903_g_1hwrx3h80000gn/T/go-build236193593=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Parsing a time string with a "Z" time zone using a time format that includes time zone seconds fails.

https://go.dev/play/p/FgeEzRinnL8

What did you see happen?

The call to time.Parse returned an error. For example, this code:

tm, err = time.Parse("2006-01-02T15:04:05Z070000", "2024-07-01T12:34:56Z")
fmt.Println(tm)
fmt.Println(err)

outputs:

0001-01-01 00:00:00 +0000 UTC
parsing time "2024-07-01T12:34:56Z" as "2006-01-02T15:04:05Z070000": cannot parse "Z" as "Z070000"

What did you expect to see?

The call to time.Parse to succeed and return a time with the UTC time zone location. For example, this code:

tm, err = time.Parse("2006-01-02T15:04:05Z070000", "2024-07-01T12:34:56Z")
fmt.Println(tm)
fmt.Println(err)

SHOULD output:

2024-07-01 12:34:56 +0000 UTC
<nil>
@darinkrauss darinkrauss changed the title time: fix time zone parsing when format includes time zone seconds time: time zone parsing when format includes time zone seconds fails Jul 1, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/595897 mentions this issue: time: fix time zone parsing when format includes time zone seconds

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 2, 2024
@thanm
Copy link
Contributor

thanm commented Jul 2, 2024

HI @darinkrauss , have you looked at #56528 (comment) ? Seems related to me. Thanks.

@darinkrauss
Copy link
Contributor Author

Hi @thanm! I had not seen that comment. After reviewing, though, I'm not sure I see how it is related. This issue is related to parsing the ISO-8601 "Z" abbreviation for UTC when using the "Z070000" and "Z07:00:00" time formats. Parsing currently works for the other "Z"-related time formats (without seconds) such as "Z0700" and "Z07:00". What am I missing?

Mchnan pushed a commit to Mchnan/go-sylixos that referenced this issue Jul 9, 2024
The current implementation fails to parse a time string with a "Z"
time zone using a time format that includes time zone seconds. This
fix correctly parses the "Z" time zone for any Z-base time format
that includes seconds (i.e. "Z070000" or "Z07:00:00").

Fixes golang#68263

Change-Id: Idf8fa06b5f96383f050c4ffbd2bc5804fd408650
Reviewed-on: https://go-review.googlesource.com/c/go/+/595897
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Than McIntosh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants