Skip to content

time: Parse inappropriately sets Location() to Local in some circumstances #19750

@lupine

Description

@lupine

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8 darwin/amd64

I can also see this on go1.6.2 darwin/amd64 and go.7.4 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lupine/.gvm/pkgsets/go1.8/global"
GORACE=""
GOROOT="/Users/lupine/.gvm/gos/go1.8"
GOTOOLDIR="/Users/lupine/.gvm/gos/go1.8/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lh/4xp9ym5137vdbpg81jw192dm0000gn/T/go-build598903070=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

Here's an example on the playground: https://play.golang.org/p/ND8CEYOKcT

The correct behaviour is actually seen when this example is run on playground, so I've included the output I see on my own machine.

What did you expect to see?

time.Parse("-0700", "+0000") should return a time.Time with a Location() with an offset of +0000 in all cases

What did you see instead?

time.Local was used instead, resulting in the timezone changing from +0000 to +0100 on my local machine.

Adding the year to the parse string is enough to get the desired behaviour

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions