diff --git a/issue.go b/issue.go index f3eb9dc..41ba3f0 100644 --- a/issue.go +++ b/issue.go @@ -103,7 +103,7 @@ type IssueFields struct { Priority *Priority `json:"priority,omitempty" structs:"priority,omitempty"` Resolutiondate Time `json:"resolutiondate,omitempty" structs:"resolutiondate,omitempty"` Created Time `json:"created,omitempty" structs:"created,omitempty"` - Duedate Time `json:"duedate,omitempty" structs:"duedate,omitempty"` + Duedate Date `json:"duedate,omitempty" structs:"duedate,omitempty"` Watches *Watches `json:"watches,omitempty" structs:"watches,omitempty"` Assignee *User `json:"assignee,omitempty" structs:"assignee,omitempty"` Updated Time `json:"updated,omitempty" structs:"updated,omitempty"` @@ -294,6 +294,9 @@ type Parent struct { // Time represents the Time definition of JIRA as a time.Time of go type Time time.Time +// Date represents the Date definition of JIRA as a time.Time of go +type Date time.Time + // Wrapper struct for search result type transitionResult struct { Transitions []Transition `json:"transitions" structs:"transitions"` @@ -339,7 +342,7 @@ type Option struct { func (t *Time) UnmarshalJSON(b []byte) error { // Ignore null, like in the main JSON package. if string(b) == "null" { - return nil + return nil } ti, err := time.Parse("\"2006-01-02T15:04:05.999-0700\"", string(b)) if err != nil { @@ -349,6 +352,21 @@ func (t *Time) UnmarshalJSON(b []byte) error { return nil } +// UnmarshalJSON will transform the JIRA date into a time.Time +// during the transformation of the JIRA JSON response +func (t *Date) UnmarshalJSON(b []byte) error { + // Ignore null, like in the main JSON package. + if string(b) == "null" { + return nil + } + ti, err := time.Parse("\"2006-01-02\"", string(b)) + if err != nil { + return err + } + *t = Date(ti) + return nil +} + // Worklog represents the work log of a JIRA issue. // One Worklog contains zero or n WorklogRecords // JIRA Wiki: https://confluence.atlassian.com/jira/logging-work-on-an-issue-185729605.html