diff --git a/issue.go b/issue.go index 46ad849..5a5da64 100644 --- a/issue.go +++ b/issue.go @@ -351,7 +351,7 @@ func (t *Time) UnmarshalJSON(b []byte) error { // MarshalJSON will transform the time.Time into a JIRA time // during the creation of a JIRA request func (t Time) MarshalJSON() ([]byte, error) { - return []byte(time.Time(t).Format("\"2006-01-02T15:04:05.999-0700\"")), nil + return []byte(time.Time(t).Format("\"2006-01-02T15:04:05.000-0700\"")), nil } // UnmarshalJSON will transform the JIRA date into a time.Time diff --git a/issue_test.go b/issue_test.go index a7c1565..21236a0 100644 --- a/issue_test.go +++ b/issue_test.go @@ -9,11 +9,9 @@ import ( "reflect" "strings" "testing" - - "github.com/google/go-cmp/cmp" - "time" + "github.com/google/go-cmp/cmp" "github.com/trivago/tgo/tcontainer" ) @@ -1799,3 +1797,34 @@ func TestIssueService_AddRemoteLink(t *testing.T) { t.Errorf("Error given: %s", err) } } + +func TestTime_MarshalJSON(t *testing.T) { + timeFormatParseFrom := "2006-01-02T15:04:05.999Z" + testCases := []struct { + name string + inputTime string + expected string + }{ + { + name: "test without ms", + inputTime: "2020-04-01T01:01:01.000Z", + expected: "\"2020-04-01T01:01:01.000+0000\"", + }, + { + name: "test with ms", + inputTime: "2020-04-01T01:01:01.001Z", + expected: "\"2020-04-01T01:01:01.001+0000\"", + }, + } + + for _, tt := range testCases { + t.Run(tt.name, func(t *testing.T) { + rawTime, _ := time.Parse(timeFormatParseFrom, tt.inputTime) + time := Time(rawTime) + got, _ := time.MarshalJSON() + if string(got) != tt.expected { + t.Errorf("Time.MarshalJSON() = %v, want %v", string(got), tt.expected) + } + }) + } +}