Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ var sdkDateType = reflect.TypeOf(SDKDate{})
var sdkDateTypePtr = reflect.TypeOf(&SDKDate{})

//Formats for sdk supported time representations
const sdkTimeFormat = time.RFC3339Nano
const sdkTimeFormat = "2006-01-02T15:04:05.000Z07:00"
const rfc1123OptionalLeadingDigitsInDay = "Mon, _2 Jan 2006 15:04:05 MST"
const sdkDateFormat = "2006-01-02"

func tryParsingTimeWithValidFormatsForHeaders(data []byte, headerName string) (t time.Time, err error) {
header := strings.ToLower(headerName)
switch header {
case "lastmodified", "date":
t, err = tryParsing(data, time.RFC3339Nano, time.RFC3339, time.RFC1123, rfc1123OptionalLeadingDigitsInDay, time.RFC850, time.ANSIC)
t, err = tryParsing(data, time.RFC3339Nano, sdkTimeFormat, time.RFC3339, time.RFC1123, rfc1123OptionalLeadingDigitsInDay, time.RFC850, time.ANSIC)
return
default: //By default we parse with RFC3339
t, err = time.Parse(sdkTimeFormat, string(data))
Expand Down
8 changes: 4 additions & 4 deletions common/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func TestHttpMarshalerAll(t *testing.T) {
var content map[string]string
body, _ := ioutil.ReadAll(request.Body)
json.Unmarshal(body, &content)
when := s.When.Format(time.RFC3339Nano)
when := s.When.Format(sdkTimeFormat)
assert.True(t, request.URL.Path == "//101")
assert.True(t, request.URL.Query().Get("name") == s.Name)
assert.True(t, request.URL.Query().Get("income") == strconv.FormatFloat(float64(s.Income), 'f', 2, 32))
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestHttpMarshallerSimpleStructPointers(t *testing.T) {
assert.Equal(t, "", request.Header.Get(requestHeaderOpcRetryToken))
assert.True(t, strings.Contains(request.URL.Path, "111"))
assert.True(t, strings.Contains(string(all), "thekey"))
assert.Contains(t, string(all), now.Format(time.RFC3339Nano))
assert.Contains(t, string(all), now.Format(sdkTimeFormat))
}

func TestHttpMarshallerSimpleStructPointersFilled(t *testing.T) {
Expand Down Expand Up @@ -1190,11 +1190,11 @@ func TestToStringValue_TimeFormat(t *testing.T) {
}{
{
Input: "2018-10-15T19:43:05.080Z",
Expected: "2018-10-15T19:43:05.08Z",
Expected: "2018-10-15T19:43:05.080Z",
},
{
Input: "2018-10-15T19:43:05Z",
Expected: "2018-10-15T19:43:05Z",
Expected: "2018-10-15T19:43:05.000Z",
},
}

Expand Down