Skip to content

Commit

Permalink
synced json has marshalLayout format
Browse files Browse the repository at this point in the history
  • Loading branch information
kobtea committed Sep 10, 2018
1 parent 9df705d commit 8ff9529
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions todoist/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func Next7Days() Time {

func Parse(value string) (Time, error) {
t, err := time.Parse(unmarshalLayout, value)
if err != nil {
t, err = time.Parse(marshalLayout, value)
}
if err != nil {
return Time{}, err
}
Expand Down
8 changes: 8 additions & 0 deletions todoist/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ func TestParse(t *testing.T) {
t.Errorf("%d. %q mismatch:\n exp=%#v\n got=%#v\n\n", i, tt.s, tt.v, tim)
}
}
for i, tt := range marshalTimes {
tim, err := Parse(tt.s)
if !reflect.DeepEqual(err, tt.e) {
t.Errorf("%d. %q error mismatch:\n exp=%s\n got=%s\n\n", i, tt.s, tt.e, err)
} else if tt.e == nil && !tim.Equal(Time{tt.v.Truncate(time.Minute)}) {
t.Errorf("%d. %q mismatch:\n exp=%#v\n got=%#v\n\n", i, tt.s, tt.v, tim)
}
}
}

func TestTime_MarshalJSON(t *testing.T) {
Expand Down

0 comments on commit 8ff9529

Please sign in to comment.