Skip to content

time: Time.Sub bug when computing times before the year 1681 #23079

@Indy9000

Description

@Indy9000

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.2 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/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/36/_8j4j_hx70j84ydkhz_tdrfr0000gn/T/go-build255965845=/tmp/go-build -gno-record-gcc-switches -fno-common"
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"

What did you do?

te1 := time.Date(1601, time.January, 1, 0, 0, 0, 0, time.UTC)
te2 := time.Date(1970, time.January, 1, 0, 0, 0, 0, time.UTC)
d := te2.Sub(te1)
dsecs := int64(d.Seconds())  // returns 9223372036
fmt.Println("dsecs=",dsecs)

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
https://play.golang.org/p/FH75X3kXgV

What did you expect to see?

dsecs=11643609600

What did you see instead?

dsecs=9223372036

correct results starts to appear after the year 1681. (and possibly few days/months before)

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