Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time: marshaling wallclock time is lossy #45958

Closed
colin-sitehost opened this issue May 5, 2021 · 2 comments
Closed

time: marshaling wallclock time is lossy #45958

colin-sitehost opened this issue May 5, 2021 · 2 comments

Comments

@colin-sitehost
Copy link

colin-sitehost commented May 5, 2021

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.

@seankhliao
Copy link
Member

This is documented in the package doc

Because the monotonic clock reading has no meaning outside the current process, the serialized forms generated by t.GobEncode, t.MarshalBinary, t.MarshalJSON, and t.MarshalText omit the monotonic clock reading, and t.Format provides no format for it. Similarly, the constructors time.Date, time.Parse, time.ParseInLocation, and time.Unix, as well as the unmarshalers t.GobDecode, t.UnmarshalBinary. t.UnmarshalJSON, and t.UnmarshalText always create times with no monotonic clock reading.

@colin-sitehost
Copy link
Author

somewhat derivative, but what is the suggestion for interface boundaries within a process? is there a way to persist this monotonic information, say cgo or reflective use cases like testing.

@golang golang locked and limited conversation to collaborators May 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants