mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-06-27 00:21:07 +02:00
Use custom "Date" type for Duedate field
Jira doesn't use its default time format ("2006-01-02T15:04:05.999-0700") for the duedate field, but instead a shorter representation that contains only the year, month and day fields, i. e. "2006-01-02". This commit adds a new type "Date" that is unmarshalled using the short format.
This commit is contained in:
22
issue.go
22
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
|
||||
|
Reference in New Issue
Block a user