-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit.go
60 lines (49 loc) · 1.29 KB
/
commit.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package bitbucket
import (
"strconv"
"time"
)
type CommitTime time.Time
type Author struct {
Name string `json:"name"`
EmailAddress string `json:"emailAddress"`
}
type Committer struct {
Name string `json:"name"`
EmailAddress string `json:"emailAddress"`
}
type Parent struct {
Id string `json:"id"`
DisplayId string `json:"displayId"`
}
type Commit struct {
Id string `json:"id"`
DisplayId string `json:"displayId"`
Author Author `json:"author"`
AuthorTimestamp CommitTime `json:"authorTimestamp"`
Committer Committer `json:"committer"`
CommitterTimestamp CommitTime `json:"committerTimestamp"`
Message string `json:"message"`
Parents []Parent `json:"parents"`
}
func (t CommitTime) MarshalJSON() ([]byte, error) {
return []byte(strconv.FormatInt(time.Time(t).Unix(), 10)), nil
}
func (t *CommitTime) UnmarshalJSON(s []byte) (err error) {
r := string(s)
q, err := strconv.ParseInt(r, 10, 64)
if err != nil {
return err
}
*(*time.Time)(t) = time.UnixMilli(q)
return nil
}
func (t CommitTime) Unix() int64 {
return time.Time(t).Unix()
}
func (t CommitTime) Time() time.Time {
return time.Time(t).UTC()
}
func (t CommitTime) String() string {
return time.Time(t).String()
}