Skip to content

time: marshaling wallclock time is lossy #45958

Closed
@colin-sitehost

Description

@colin-sitehost

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

$ go version
go version go1.16.3 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/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/user/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build3471220289=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://play.golang.org/p/xLZ0iwRQ0qu

What did you expect to see?

time.Time{wall:0xbab699fc00000000, ext:1, loc:(*time.Location)(0x5676c0)} "2009-11-10T23:00:00Z" time.Time{wall:0xbab699fc00000000, ext:1, loc:(*time.Location)(nil)}
time.Time{wall:0xbab699fc00000000, ext:1, loc:(*time.Location)(0x5676c0)} "\x01\x00\x00\x00\x0e\u008b\xe7p\x00\x00\x00\x00\x00\x00" time.Time{wall:0xbab699fc00000000, ext:1, loc:(*time.Location)(0x5676c0)}

What did you see instead?

time.Time{wall:0xbab699fc00000000, ext:1, loc:(*time.Location)(0x5676c0)} "2009-11-10T23:00:00Z" time.Time{wall:0x0, ext:63393490800, loc:(*time.Location)(nil)}
time.Time{wall:0xbab699fc00000000, ext:1, loc:(*time.Location)(0x5676c0)} "\x01\x00\x00\x00\x0e\u008b\xe7p\x00\x00\x00\x00\x00\x00" time.Time{wall:0x0, ext:63393490800, loc:(*time.Location)(0x5676c0)}

Summary

There are two pieces of information that are dropped during encoding: text drops location (this is documented in godoc), and both drop monotonic clock information. I assume the former was an unfortunate consequence of using time.RFC3339Nano, but due to hyrum's law you just documented the failure. As such, I would request this too be documented, since it caught me off guard, and I assume that it is infeasible to change.

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