Skip to content

Commit 47448ac

Browse files
committed
time: add notes about monotonic time paused during system sleep
1 parent e7e2fa0 commit 47448ac

File tree

1 file changed

+3
-45
lines changed

1 file changed

+3
-45
lines changed

src/time/time.go

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
//
5454
// On some systems the monotonic clock will stop if the computer goes to sleep.
5555
// On such a system, t.Sub(u) may not accurately reflect the actual
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].
56+
// time that passed between t and u. The same applies to other functions and
57+
// methods that subtract times, such as [Since], [Until], [Before], [After] ...
58+
// See issue: https://github.com/golang/go/issues/66870
5959
// Use [Time.Round](0) or [Time.Truncate](0) to walkaround.
6060
//
6161
// Because the monotonic clock reading has no meaning outside
@@ -257,11 +257,6 @@ func (t *Time) mono() int64 {
257257
}
258258

259259
// 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
265260
func (t Time) After(u Time) bool {
266261
if t.wall&u.wall&hasMonotonic != 0 {
267262
return t.ext > u.ext
@@ -272,11 +267,6 @@ func (t Time) After(u Time) bool {
272267
}
273268

274269
// 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
280270
func (t Time) Before(u Time) bool {
281271
if t.wall&u.wall&hasMonotonic != 0 {
282272
return t.ext < u.ext
@@ -288,11 +278,6 @@ func (t Time) Before(u Time) bool {
288278

289279
// Compare compares the time instant t with u. If t is before u, it returns -1;
290280
// 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
296281
func (t Time) Compare(u Time) int {
297282
var tc, uc int64
298283
if t.wall&u.wall&hasMonotonic != 0 {
@@ -317,11 +302,6 @@ func (t Time) Compare(u Time) int {
317302
// For example, 6:00 +0200 and 4:00 UTC are Equal.
318303
// See the documentation on the Time type for the pitfalls of using == with
319304
// 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
325305
func (t Time) Equal(u Time) bool {
326306
if t.wall&u.wall&hasMonotonic != 0 {
327307
return t.ext == u.ext
@@ -893,11 +873,6 @@ func (d Duration) Abs() Duration {
893873
}
894874

895875
// 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
901876
func (t Time) Add(d Duration) Time {
902877
dsec := int64(d / 1e9)
903878
nsec := t.nsec() + int32(d%1e9)
@@ -926,11 +901,6 @@ func (t Time) Add(d Duration) Time {
926901
// value that can be stored in a [Duration], the maximum (or minimum) duration
927902
// will be returned.
928903
// 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
934904
func (t Time) Sub(u Time) Duration {
935905
if t.wall&u.wall&hasMonotonic != 0 {
936906
return subMono(t.ext, u.ext)
@@ -960,12 +930,6 @@ func subMono(t, u int64) Duration {
960930

961931
// Since returns the time elapsed since t.
962932
// 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
969933
func Since(t Time) Duration {
970934
if t.wall&hasMonotonic != 0 {
971935
// Common case optimization: if t has monotonic time, then Sub will use only it.
@@ -976,12 +940,6 @@ func Since(t Time) Duration {
976940

977941
// Until returns the duration until t.
978942
// 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
985943
func Until(t Time) Duration {
986944
if t.wall&hasMonotonic != 0 {
987945
// Common case optimization: if t has monotonic time, then Sub will use only it.

0 commit comments

Comments
 (0)