Skip to content

time: ParseInLocation does not adjust timezone offset when seconds are not explicitly set #53919

@MarkRosemaker

Description

@MarkRosemaker

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

$ go version
go version go1.18.4 darwin/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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mark/Library/Caches/go-build"
GOENV="/Users/mark/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS="-mod=mod"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mark/go/pkg/mod"
GONOPROXY="github.com/flypay/*,github.com/faetools/*"
GONOSUMDB="github.com/flypay/*,github.com/faetools/*"
GOOS="darwin"
GOPATH="/Users/mark/go"
GOPRIVATE="github.com/flypay/*,github.com/faetools/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.18.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.18.4/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/mark/go/src/github.com/golang/go/src/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rw/2cbtm9v95bz86c0ktyjwj2_80000gn/T/go-build2898766309=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I ran into an issue where a time.Time object was seconds off after having been converted into a string using Format with RFC3339 and back using ParseInLocation.

https://go.dev/play/p/5t8wa3b_ahv

What did you expect to see?

The test above succeeding, i.e. when I explicitly state my desired location that go is smart enough to adjust the seconds.

What did you see instead?

The test failing.
This is because the parsed time zone differs mere seconds from the desired time zone and RFC3339 expresses a time zone only in hours and minutes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions