Skip to content

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

@flyn-org

Description

@flyn-org

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions