Skip to content

time: The Time object created with time.Date() in the timezone America/New_York returns incorrect information when DST is applied. #66554

@changmink

Description

@changmink

Go version

go version go1.22.1 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/user/Library/Caches/go-build'
GOENV='/Users/user/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/user/.gvm/pkgsets/go1.22.1/global/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/user/.gvm/pkgsets/go1.22.1/global'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/user/.gvm/gos/go1.22.1'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/user/.gvm/gos/go1.22.1/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/user/Projects/cronexpr/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/ds/8q7h4w3j0wggmj73zn46gt240000gn/T/go-build2556637787=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

When the timezone is set to America/New_York and the time is set to 2 o'clock using time.Date(), DST should be applied, resulting in an output of 3 o'clock, but it returns 1 o'clock instead. However, in other timezones, it works correctly.
Please Check. https://go.dev/play/p/kN_Cmgp8zny

What did you see happen?

I got the following result. It's the same response as the playground link attached above.

go run main.go
Sun, 10 Mar 2024 01:00:00 EST
Sun, 10 Mar 2024 01:00:00 EST
Sun, 31 Mar 2024 01:00:00 CET
Sun, 31 Mar 2024 03:00:00 CEST

What did you expect to see?

The response I consider to be correct is as follows.

Sun, 10 Mar 2024 01:00:00 EST
Sun, 10 Mar 2024 03:00:00 EDT
Sun, 31 Mar 2024 01:00:00 CET
Sun, 31 Mar 2024 03:00:00 CEST

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