Skip to content

Commit 4ead7e8

Browse files
committed
time: add a sentence about distant times to time.Time.Unix
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 <[email protected]> Reviewed-by: Andrew Gerrand <[email protected]>
1 parent 9ead772 commit 4ead7e8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/time/time.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,9 @@ func (t Time) Zone() (name string, offset int) {
11481148
// Unix returns t as a Unix time, the number of seconds elapsed
11491149
// since January 1, 1970 UTC. The result does not depend on the
11501150
// location associated with t.
1151+
// Unix-like operating systems often record time as a 32-bit
1152+
// count of seconds, but since the method here returns a 64-bit
1153+
// value it is valid for billions of years into the past or future.
11511154
func (t Time) Unix() int64 {
11521155
return t.unixSec()
11531156
}

0 commit comments

Comments
 (0)