File: timestamp.go

package info (click to toggle)
golang-github-linbit-golinstor 0.57.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 472 kB
  • sloc: makefile: 11
file content (31 lines) | stat: -rw-r--r-- 549 bytes parent folder | download | duplicates (2)
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
}