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