Search code examples
dategolocale

I save a date in a JSON, when I reload it, it looks nearly the same... What is that `m=+2.58`?


I'm writing a test in Golang which verifies that a journal on disk is properly managed. When I look at the file I see the correct date, but when I look at the date in the test and the date I reload from JSON, they look different:

Timestamp I got with time.Now():

2019-08-06 00:17:46.033527441 -0700 PDT m=+2.582718548

Timestamp I reloaded from the JSON:

2019-08-06 00:17:46.033527441 -0700 PDT

If I change the date to UTC(), it all works as expected (i.e. start with time.Now().UTC()).

I understand that the location is different, I'm just not too sure what the m=... parameter stands for and why would it not be present in the date I reloaded from JSON since it is the exact same date.

So... What is that field?


Solution

  • fmt.Println(time.Now().String())
    

    String returns the time formatted using the format string "2006-01-02 15:04:05.999999999 -0700 MST" If the time has a monotonic clock reading, the returned string includes a final field "m=±", where value is the monotonic clock reading formatted as a decimal number of seconds. The returned string is meant for debugging; for a stable serialized representation, use t.MarshalText, t.MarshalBinary, or t.Format with an explicit format string.

    Reference


    Monotonic Clocks

    Operating systems provide both a “wall clock,” which is subject to changes for clock synchronization, and a “monotonic clock,” which is not. The general rule is that the wall clock is for telling time and the monotonic clock is for measuring time. Rather than split the API, in this package the Time returned by time.Now contains both a wall clock reading and a monotonic clock reading; later time-telling operations use the wall clock reading, but later time-measuring operations, specifically comparisons and subtractions, use the monotonic clock reading.