17

I'm experimenting with Google OAuth2 and I encountered this in the expiry time of my refresh token. It comes from 2018-10-15 15:42:37.5989253 +1100 AEDT m=+3610.688917401

I know it's a time format but I couldn't find any information about m=+ anywhere. Is it used internally by Google? I tried to parse it with time.RFC3339 but as you can guess, it ignores the m=+. It says

parsing time "2018-10-15 15:42:37.5989253 +1100 AEDT m=+3610.688917401" as "2006-01-02T15:04:05Z07:00": cannot parse " 15:42:37.5989253 +1100 AEDT m=+3610.688917401" as "T"

So what's this m=+ in the time string?

Volker
  • 40,468
  • 7
  • 81
  • 87
kkesley
  • 3,258
  • 1
  • 28
  • 55

1 Answers1

18

The m=±<value> is monotonic clock reading in second.

Explanation from time.Time.String documentation:

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.

Afaik, golang doesn't provide layout for parsing monotonic clock, so in my opinion it's safe to remove it.

dateFormat := "2006-01-02 15:04:05.999999999 -0700 MST"
dateString := "2018-10-15 15:42:37.5989253 +1100 AEDT m=+3610.688917401"

t, err := time.Parse(dateFormat, strings.Split(dateString, " m=")[0])
if err != nil {
    fmt.Println(err)
    os.Exit(0)
}

fmt.Println(t) // 2018-10-15 15:42:37.5989253 +1100 AEDT

Starting from go 1.9, calling .String() will generate date string output with monotonic clock in it. So I suggest try to use .Format() for normal usage instead of .String().

The monotonic clock info is only useful for debugging purposes.

novalagung
  • 10,905
  • 4
  • 58
  • 82