Skip to content

time: time.ParseInLocation can get the seconds wrong #71444

@bbp-brieuc

Description

@bbp-brieuc

Go version

go version go1.23.4 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/brieucjeunhomme/Library/Caches/go-build'
GOENV='/Users/brieucjeunhomme/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/brieucjeunhomme/go/pkg/mod'
GONOPROXY='github.com/bbp-brieuc'
GONOSUMDB='github.com/bbp-brieuc'
GOOS='darwin'
GOPATH='/Users/brieucjeunhomme/go'
GOPRIVATE='github.com/bbp-brieuc'
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.23.4'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/brieucjeunhomme/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/brieucjeunhomme/eodhd/go.mod'
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/3t/k4p_jwdd147888b91dvqm6s80000gn/T/go-build325982754=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I parsed a date with only a year and month:
fmt.Println(time.ParseInLocation("2006-05", "2025-01", time.UTC))

What did you see happen?

The resulting time had a non-0 second, the output was:
2025-01-01 00:00:01 +0000 UTC

What did you expect to see?

A result with a 0 second:
2025-01-01 00:00:00 +0000 UTC

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