mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-08-10 22:21:36 +02:00
fix: change millisecond time format
If millisecond in go time is empty they will be not exist in result string if using "999" in format. And jira api will response with error in the case. Using "000" fix the problem. Add test for time marshaling.
This commit is contained in:
2
issue.go
2
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
|
||||
|
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user