]> Cypherpunks repositories - gostls13.git/commitdiff
time: add a sentence about distant times to time.Time.Unix
authorRob Pike <r@golang.org>
Thu, 9 Jan 2020 05:22:31 +0000 (16:22 +1100)
committerRob Pike <r@golang.org>
Mon, 13 Jan 2020 21:56:50 +0000 (21:56 +0000)
Since Durations only span 290 years, they are not good for
manipulating very remote times. I bounced off this problem recently
while doing some astronomical calculations and it took me a while to
realize I could get a 64-bit seconds value from time.Time.Unix and
subtract two of them to evaluate the interval.

I thought it worth adding a sentence to make this clear. It didn't
occur to me for quite a while that "Unix time" spans a huge range in
the Go library.

Change-Id: I76c75dc951dfd6bcf86e8b0be3cfec518a3ecdee
Reviewed-on: https://go-review.googlesource.com/c/go/+/213977
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/time/time.go

index 10a132fa2389188ef792b0beb21b342da47fd95f..5dc9fa68ac17a5bc5d125dc1e52d1aff190ded8c 100644 (file)
@@ -1148,6 +1148,9 @@ func (t Time) Zone() (name string, offset int) {
 // Unix returns t as a Unix time, the number of seconds elapsed
 // since January 1, 1970 UTC. The result does not depend on the
 // location associated with t.
+// Unix-like operating systems often record time as a 32-bit
+// count of seconds, but since the method here returns a 64-bit
+// value it is valid for billions of years into the past or future.
 func (t Time) Unix() int64 {
        return t.unixSec()
 }