Skip to content

time: UnixDate is not always compatible between Format and Parse #73583

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
flyn-org opened this issue May 2, 2025 · 2 comments
Closed

time: UnixDate is not always compatible between Format and Parse #73583

flyn-org opened this issue May 2, 2025 · 2 comments
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@flyn-org
Copy link

flyn-org commented May 2, 2025

Go version

go version go1.24.2 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/mike/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/mike/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1296024709=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/mike/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/mike/go'
GOPRIVATE=''
GOPROXY='direct'
GOROOT='/usr/lib/golang'
GOSUMDB='off'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/mike/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib/golang/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I have an application that transforms between string and time.Time values using Format and Parse along with time.UnixDate. The application runs as a combination of AMD64 and WebAssembly (Go js/wasm), and it goes back and forth between these representations. A client who uses Chrome on macOS has found that Format will create strings Parse cannot parse. Here is an example:

Thu May 1 20:00:36 -0500 2025

(On the platforms I have direct access to, Format always produces CDT, not -0500.)

The problem comes when parsing. For the example that uses -0500, calling Parse with time.UnixDate causes the following error: parsing time "Thu May 1 20:00:36 -0500 2025" as "Mon Jan _2 15:04:05 MST 2006": cannot parse "-0500 2025" as "MST". Here is an example that shows this:

package main

import (
	"fmt"
	"time"
)

func main() {
	s := "Thu May  1 20:00:36 -0500 2025"
	_, err := time.Parse(time.UnixDate, s)
	if err != nil {
		fmt.Println(err)
	}
}

I have not yet been able to reproduce the Format side of this, that is, the process that results in a string with -0500. However, these comments in the Go source lead me to believe it is possible, depending on the platform:

https://cs.opensource.google/go/go/+/refs/tags/go1.24.2:src/time/format.go;l=820
https://cs.opensource.google/go/go/+/refs/tags/go1.24.2:src/time/zoneinfo_js.go;l=27

These comments seem to corroborate the claim of my client.

What did you see happen?

Under some circumstances, Parse will not process something created with Format, even when using the same layout string.

What did you expect to see?

My expectation was that Parse could parse anything Format produced, assuming the layout string is the same.

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label May 2, 2025
@seankhliao
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

No branches or pull requests

3 participants