golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.38k stars 17.7k forks source link

time: Incorrect zonebounds on location based on POSIX TZ string #70633

Open Achilleshiel opened 9 hours ago

Achilleshiel commented 9 hours ago

Go version

go version go1.23.3 linux/amd64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='amd64'
GOBIN='/home/wouter/go/bin/'
GOCACHE='/home/wouter/.cache/go-build'
GOENV='/home/wouter/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/wouter/go/pkg/mod'
GONOPROXY='gitlab.figonet.nl'
GONOSUMDB='gitlab.figonet.nl'
GOOS='linux'
GOPATH='/home/wouter/go'
GOPRIVATE='gitlab.figonet.nl'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib64/golang'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib64/golang/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.3'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/wouter/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='x86_64-solus-linux-gcc'
CXX='x86_64-solus-linux-g++'
CGO_ENABLED='1'
GOMOD='/home/wouter/Development/modules/sw_bca/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2766243939=/tmp/go-build -gno-record-gcc-switches'

What did you do?

My goal was to check if a posix tz string has the same time zone transitions as a given time.Location. Via an empty Time zone information format string I loaded a Posix timezone string as location: https://go.dev/play/p/iRKJ1idPNz6. Using the loaded location I call ZoneBounds().

What did you see happen?

As from the go.dev/play example: it returns the end of DST and the end of the year.

What did you expect to see?

I expected to see get the end of DST and the start of the DST in the next year.

Debugging

I dug through the time library and found this comment:

    // The start and end values that we return are accurate
    // close to a daylight savings transition, but are otherwise
    // just the start and end of the year. That suffices for
    // the only caller that cares, which is Date.

This comment predates the addition of the ZoneBounds method. Which is now a second caller that cares.

gabyhelp commented 9 hours ago

Related Issues

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

mknyszek commented 6 hours ago

CC @rsc via https://dev.golang.org/owners

ianlancetaylor commented 5 hours ago

You've identified the code. Do you want to send a patch? Thanks.

Achilleshiel commented 1 hour ago

You've identified the code. Do you want to send a patch? Thanks.

Yes, I think I will be able to patch this. If not, I will let you know.

Achilleshiel commented 1 hour ago

Found that it is also possible with time.LoadLocation() and a time far enough in the future such that it is not in the explicit tz transitions. For example 2040: https://go.dev/play/p/h4ingW93eIU