Skip to content

time: MarshalBinary fails on valid Time #39616

@kayleg

Description

@kayleg

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

$ go version
go version go1.14.2 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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/path/Library/Caches/go-build"
GOENV="/Users/path/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOOS="darwin"
GOPATH="/Users/path/code/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/opt/go/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bf/vxlr89hd4jqfx43ncc0y10b00000gn/T/go-build493699043=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Call In on a zero value time.Time creates in valid time when the result would be before the zero time.

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

What did you expect to see?

The zero value time would have its time zone set to the specified timezone yet still be the zero value date.

For Example:
Setting 0001-01-01 00:00 UTC to EDT should return 0001-01-01 00:00 EDT or return an error if the value is outside the range (which in this case it is)

Using zeroTime.After(newTime) should return true or some other mechanism to check the time is valid should exist.

What did you see instead?

A time value before the range was returned with an invalid time zone 0000-12-31 19:03:58 -0456 LMT.

Attempting to compare the result against the zero time using After does not function as zeroTime.After(newTime) and newTime.After(zeroTime) both return false so you can have a false positive that the time is valid.

Also the resulting time value prevents MarshalBinary from working

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.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions