Skip to content

time: Altered time.Time state from calling IsDST or Zone #50559

@myshkin5

Description

@myshkin5

What version of Go are you using (go version)?

$ go version
go version go1.17.6 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/dschultz/.cache/go-build"
GOENV="/home/dschultz/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/dschultz/workspace/apiserver-go/pkg/mod"
GONOPROXY="github.com/aspenmesh/*"
GONOSUMDB="github.com/aspenmesh/*"
GOOS="linux"
GOPATH="/home/dschultz/workspace/apiserver-go"
GOPRIVATE="github.com/aspenmesh/*"
GOPROXY="https://proxy.golang.org"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/dschultz/workspace/apiserver/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2743734130=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Observing bizarre state mutations around the location in an instance of time.Time. By calling IsDST (which should be read-only, right?), the state of an instance is changed. Subsequent instances instantiated after the call to IsDST have an updated location and altered state.

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

With output as follows:

before 11810389586750117723, after 12359862718078847701, new 12359862718078847701, pre 11810389586750117723

Showing that the hash of the instance changes after calling IsDST (Zone produces the same results). The hash of a new instance created after the call to IsDST on the first instance equals the new hash.

What did you expect to see?

A consistent hash and unaltered state when calling a seemingly read-only function.

What did you see instead?

A mysteriously changing hash value.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions