Skip to content

time: Now() and time.unixTime() do not call setLoc, causing timezone to not be nil when system time is UTC #19486

@sbuss

Description

@sbuss

Please answer these questions before submitting your issue. Thanks!

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

go version devel +4cce27a3fa Sat Jan 21 03:20:55 2017 +0000 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/google/home/sbuss/workspace"
GORACE=""
GOROOT="/usr/lib/google-golang"
GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build194178423=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
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?

When running go code in a system set to UTC, or by setting time.Local = time.UTC, golang does not correctly set loc to nil when either time.Now() or time.Unix() are called. You can reproduce the issue via this play link.

What did you expect to see?

I expected the timestamps generated by Now() to have loc = nil, as stated by the docs on time.Time

What did you see instead?

The timestamps actually have this weird Location: &{UTC [] [] %!s(int64=0) %!s(int64=0) %!s(*time.zone=<nil>)}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions