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: Time.Sub bug when computing times before the year 1681 #23079

Closed
Indy9000 opened this issue Dec 10, 2017 · 1 comment
Closed

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

Indy9000 opened this issue Dec 10, 2017 · 1 comment

Comments

@Indy9000
Copy link

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)

@robpike
Copy link
Contributor

robpike commented Dec 10, 2017

As documented (see go doc time.Duration), a Duration overflows after 290 years, approximately. Thus this is working as documented. It's 2⁶³ nanoseconds:

(2**63) / 1e9*24*60*60*365.25
292.271023045

@mikioh mikioh changed the title Time.Sub bug when computing times before the year 1681 time: Time.Sub bug when computing times before the year 1681 Jan 5, 2018
@golang golang locked and limited conversation to collaborators Jan 5, 2019
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

4 participants