53
53
//
54
54
// On some systems the monotonic clock will stop if the computer goes to sleep.
55
55
// On such a system, t.Sub(u) may not accurately reflect the actual
56
- // time that passed between t and u.
56
+ // time that passed between t and u. This may impact a bunch of functions/methods:
57
+ // [time.Since], [time.Until], [Time.Add], [Time.Sub], [Time.After], [Time.Before]
58
+ // [Time.Equal], [Time.Compare].
59
+ // Use [Time.Round](0) or [Time.Truncate](0) to walkaround.
57
60
//
58
61
// Because the monotonic clock reading has no meaning outside
59
62
// the current process, the serialized forms generated by t.GobEncode,
@@ -254,6 +257,11 @@ func (t *Time) mono() int64 {
254
257
}
255
258
256
259
// After reports whether the time instant t is after u.
260
+ //
261
+ // On some systems the monotonic clock will stop if the computer goes to sleep.
262
+ // On such a system, this may not accurately reflect the actual time that
263
+ // passed between t and u. Use [Time.Round](0) or [Time.Truncate](0) to walkaround.
264
+ // See issue: https://github.com/golang/go/issues/66870
257
265
func (t Time ) After (u Time ) bool {
258
266
if t .wall & u .wall & hasMonotonic != 0 {
259
267
return t .ext > u .ext
@@ -264,6 +272,11 @@ func (t Time) After(u Time) bool {
264
272
}
265
273
266
274
// Before reports whether the time instant t is before u.
275
+ //
276
+ // On some systems the monotonic clock will stop if the computer goes to sleep.
277
+ // On such a system, this may not accurately reflect the actual time that
278
+ // passed between t and u. Use [Time.Round](0) or [Time.Truncate](0) to walkaround.
279
+ // See issue: https://github.com/golang/go/issues/66870
267
280
func (t Time ) Before (u Time ) bool {
268
281
if t .wall & u .wall & hasMonotonic != 0 {
269
282
return t .ext < u .ext
@@ -275,6 +288,11 @@ func (t Time) Before(u Time) bool {
275
288
276
289
// Compare compares the time instant t with u. If t is before u, it returns -1;
277
290
// if t is after u, it returns +1; if they're the same, it returns 0.
291
+ //
292
+ // On some systems the monotonic clock will stop if the computer goes to sleep.
293
+ // On such a system, this may not accurately reflect the actual time that
294
+ // passed between t and u. Use [Time.Round](0) or [Time.Truncate](0) to walkaround.
295
+ // See issue: https://github.com/golang/go/issues/66870
278
296
func (t Time ) Compare (u Time ) int {
279
297
var tc , uc int64
280
298
if t .wall & u .wall & hasMonotonic != 0 {
@@ -299,6 +317,11 @@ func (t Time) Compare(u Time) int {
299
317
// For example, 6:00 +0200 and 4:00 UTC are Equal.
300
318
// See the documentation on the Time type for the pitfalls of using == with
301
319
// Time values; most code should use Equal instead.
320
+ //
321
+ // On some systems the monotonic clock will stop if the computer goes to sleep.
322
+ // On such a system, this may not accurately reflect the actual time that
323
+ // passed between t and u. Use [Time.Round](0) or [Time.Truncate](0) to walkaround.
324
+ // See issue: https://github.com/golang/go/issues/66870
302
325
func (t Time ) Equal (u Time ) bool {
303
326
if t .wall & u .wall & hasMonotonic != 0 {
304
327
return t .ext == u .ext
@@ -870,6 +893,11 @@ func (d Duration) Abs() Duration {
870
893
}
871
894
872
895
// Add returns the time t+d.
896
+ // On some systems the monotonic clock will stop if the computer goes to sleep.
897
+ //
898
+ // On such a system, this may not accurately reflect the actual time that
899
+ // t+d. Use [Time.Round](0) or [Time.Truncate](0) to walkaround.
900
+ // See issue: https://github.com/golang/go/issues/66870
873
901
func (t Time ) Add (d Duration ) Time {
874
902
dsec := int64 (d / 1e9 )
875
903
nsec := t .nsec () + int32 (d % 1e9 )
@@ -898,6 +926,11 @@ func (t Time) Add(d Duration) Time {
898
926
// value that can be stored in a [Duration], the maximum (or minimum) duration
899
927
// will be returned.
900
928
// To compute t-d for a duration d, use t.Add(-d).
929
+ //
930
+ // On some systems the monotonic clock will stop if the computer goes to sleep.
931
+ // On such a system, this may not accurately reflect the actual time that
932
+ // passed between t and u. Use [Time.Round](0) or [Time.Truncate](0) to walkaround.
933
+ // See issue: https://github.com/golang/go/issues/66870
901
934
func (t Time ) Sub (u Time ) Duration {
902
935
if t .wall & u .wall & hasMonotonic != 0 {
903
936
return subMono (t .ext , u .ext )
@@ -927,6 +960,12 @@ func subMono(t, u int64) Duration {
927
960
928
961
// Since returns the time elapsed since t.
929
962
// It is shorthand for time.Now().Sub(t).
963
+ //
964
+ // On some systems the monotonic clock will stop if the computer goes to sleep.
965
+ // On such a system, this may not accurately reflect the actual time that
966
+ // passed between t and process start time.
967
+ // Use [Time.Round](0) or [Time.Truncate](0) to walkaround.
968
+ // See issue: https://github.com/golang/go/issues/66870
930
969
func Since (t Time ) Duration {
931
970
if t .wall & hasMonotonic != 0 {
932
971
// Common case optimization: if t has monotonic time, then Sub will use only it.
@@ -937,6 +976,12 @@ func Since(t Time) Duration {
937
976
938
977
// Until returns the duration until t.
939
978
// It is shorthand for t.Sub(time.Now()).
979
+ //
980
+ // On some systems the monotonic clock will stop if the computer goes to sleep.
981
+ // On such a system, this may not accurately reflect the actual time that
982
+ // passed between t and now.
983
+ // Use [Time.Round](0) or [Time.Truncate](0) to walkaround.
984
+ // See issue: https://github.com/golang/go/issues/66870
940
985
func Until (t Time ) Duration {
941
986
if t .wall & hasMonotonic != 0 {
942
987
// Common case optimization: if t has monotonic time, then Sub will use only it.
0 commit comments