29 lines
486 B
Go
29 lines
486 B
Go
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
|
|
}
|