OSDN Git Service

rename dir (#283)
[bytom/vapor.git] / toolbar / federation / types / types.go
1 package types
2
3 import (
4         "fmt"
5         "strconv"
6         "time"
7 )
8
9 type Timestamp time.Time
10
11 func (t *Timestamp) Unix() int64 {
12         return time.Time(*t).Unix()
13 }
14
15 func (t *Timestamp) MarshalJSON() ([]byte, error) {
16         ts := time.Time(*t).Unix()
17         stamp := fmt.Sprint(ts)
18         return []byte(stamp), nil
19 }
20
21 func (t *Timestamp) UnmarshalJSON(b []byte) error {
22         ts, err := strconv.Atoi(string(b))
23         if err != nil {
24                 return err
25         }
26
27         *t = Timestamp(time.Unix(int64(ts), 0))
28         return nil
29 }