...
1
2
3
4
5
6 package github
7
8 import (
9 "strconv"
10 "time"
11 )
12
13
14
15
16
17 type Timestamp struct {
18 time.Time
19 }
20
21 func (t Timestamp) String() string {
22 return t.Time.String()
23 }
24
25
26 func (t *Timestamp) GetTime() *time.Time {
27 if t == nil {
28 return nil
29 }
30 return &t.Time
31 }
32
33
34
35 func (t *Timestamp) UnmarshalJSON(data []byte) (err error) {
36 str := string(data)
37 i, err := strconv.ParseInt(str, 10, 64)
38 if err == nil {
39 t.Time = time.Unix(i, 0)
40 if t.Time.Year() > 3000 {
41 t.Time = time.Unix(0, i*1e6)
42 }
43 } else {
44 t.Time, err = time.Parse(`"`+time.RFC3339+`"`, str)
45 }
46 return
47 }
48
49
50 func (t Timestamp) Equal(u Timestamp) bool {
51 return t.Time.Equal(u.Time)
52 }
53
View as plain text