Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "m=+" in GO time string? [duplicate]

Tags:

time

go

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?

like image 477
kkesley Avatar asked Oct 15 '18 04:10

kkesley


People also ask

What is M in timestamp?

String returns the time formatted using the format string. 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.

What is the type of time now () in Golang?

The Now() function in Go language is used to find the current local time.


1 Answers

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.

like image 83
novalagung Avatar answered Oct 21 '22 16:10

novalagung