timer icon indicating copy to clipboard operation
timer copied to clipboard

Use `time.Time` to avoid losing monotonic clock

Open rhansen opened this issue 2 years ago • 0 comments

The time.Time.UnixNano method ignores the monotonic clock value and returns the wall time. This can cause timers to misfire if the wall time is adjusted (e.g., by NTP). For details, see https://pkg.go.dev/time#hdr-Monotonic_Clocks.

Regarding the deleted overflow tests: The range of times representable by a time.Time is complicated, and future versions of Go might change the representation. Go should "do the right thing" with regards to overflow, whatever that means. (In particular, I expect that adding any positive Duration to any Time will not result in an earlier Time.) If Go's behavior is "wrong", then I think it should be addressed in Go, not here. Users will almost certainly never come anywhere close to overflow, so it's unlikely to be a problem in practice even if Go's behavior is "wrong".

rhansen avatar Mar 13 '23 06:03 rhansen