Get the latest tech news

Monotonic and wall clock time in the Go time package


Operating systems expose a wall clock that can leap or slew with NTP and a monotonic clock that never runs backward. In Go, only time.Now (might) carries both readings, while values from time.Parse, time.Date, etc., are wall-clock-only—so naïve equality checks or time.Since on those can mislead when the system clock shifts.

Since the monotonic reading is tied specifically to your current process and system uptime, it has no real meaning outside your running program. When you use operations that do not change the instant itself (such as Add, AddDate, Sub, Round, Truncate, or simple arithmetic with Duration), Go will carry the monotonic part forward if it was there to begin with. There was a real production issue caused by the system time changing in vmalert (a VictoriaMetrics component that checks alert state in a time-based way).

Get the Android app

Or read this on Hacker News

Read more on:

Photo of time package

time package

Photo of wall clock time

wall clock time