Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
time: Sub is inaccurate after computer has slept #23178
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
This is expected, see the documentation for the time package.
You can always remove the monotonic part from a time.Time:
See also the issue for this: #12914
I have one concern with this: the use of monotonic clocks is advocated to ensure that elapsed time is measured correctly, independent of changes made to system clocks. However, this falls down if the computer sleeps. It seems there is no safe way to measure the real elapsed time, since:
Particularly with a lot of software running on laptops, the chance of 2) is probably higher than the chance of 1). And currently there is no third option that isn't skewed by sleep or system clock changes.
If a third option can't be implemented that solves the deficiencies of 1) and 2), I think it would be good for the docs to specifically call out that during computer sleep, the monotonic clock stops.
changed the title
(time.Time).Sub(time.Time) inaccurate after computer has slept
Dec 20, 2017
I think it is worth pointing out that 1 and 2 are problems of different magnitude. With 1, you could very easily have negative elapsed times. That would not only be confusing, but also easily break programs unless you took it into account.
But with 2, a user can only stop the clock, not move it back. In other words, it is impossible to have negative elapsed times - just smaller ones.
Not knowing much about monotonic times, I wonder - does any kernel or operating system keep track of sleep time as well as awake time? If it is possible with today's hardware at all.