github.com/LINBIT/golinstor@v0.52.0/client/timestamp.go (about) 1 package client 2 3 import ( 4 "encoding/json" 5 "net/url" 6 "strconv" 7 "time" 8 ) 9 10 type TimeStampMs struct { 11 time.Time 12 } 13 14 func (t *TimeStampMs) UnmarshalJSON(s []byte) (err error) { 15 r := string(s) 16 q, err := strconv.ParseInt(r, 10, 64) 17 if err != nil { 18 return err 19 } 20 t.Time = time.Unix(q/1000, (q%1000)*1_000_000) 21 return nil 22 } 23 24 func (t TimeStampMs) MarshalJSON() ([]byte, error) { 25 return json.Marshal(t.Time.Unix() * 1000) 26 } 27 28 func (t TimeStampMs) EncodeValues(key string, v *url.Values) error { 29 v.Add(key, t.Format("20060102_150405")) 30 return nil 31 }