Add custom `Time` type to unmarshal Jira's times
parent
29d4547646
commit
481e12aec6
14
comment.go
14
comment.go
|
@ -1,13 +1,9 @@
|
|||
package jiraclient
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Comment struct {
|
||||
Self string `json:"self"`
|
||||
Id string `json:"id"`
|
||||
Author User `json:"author"`
|
||||
Body string `json:"body"`
|
||||
Created time.Time `json:created"`
|
||||
Self string `json:"self"`
|
||||
Id string `json:"id"`
|
||||
Author User `json:"author"`
|
||||
Body string `json:"body"`
|
||||
Created Time `json:"created"`
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package jiraclient
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const jiraTimeLayout = "2006-01-02T15:04:05-0700"
|
||||
|
||||
type Time struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
func (t *Time) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf("\"%s\"", t.Time.Format(jiraTimeLayout))), nil
|
||||
}
|
||||
|
||||
func (t *Time) UnmarshalJSON(data []byte) error {
|
||||
s := strings.Trim(string(data), "\"")
|
||||
if s == "null" || s == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
parsedTime, err := time.Parse(jiraTimeLayout, s)
|
||||
t.Time = parsedTime
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue