From 4ead7e8cc4fd5c09db7aba5c4f5fd5d957c82a24 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Thu, 9 Jan 2020 16:22:31 +1100 Subject: [PATCH] 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 Reviewed-by: Andrew Gerrand --- src/time/time.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/time/time.go b/src/time/time.go index 10a132fa23..5dc9fa68ac 100644 --- a/src/time/time.go +++ b/src/time/time.go @@ -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() } -- 2.50.0