From 09446d4d615ffc34656b0617f95af0bc873eb5f6 Mon Sep 17 00:00:00 2001 From: John Pedrie Date: Wed, 6 Mar 2024 12:19:36 -0500 Subject: [PATCH] fix date formats (#6) --- types.go | 1 + types_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 types_test.go diff --git a/types.go b/types.go index e7f32ba..06c2e2a 100644 --- a/types.go +++ b/types.go @@ -631,6 +631,7 @@ func (n *Number) UnmarshalJSON(b []byte) error { var ( timeFormats = []string{ time.RFC3339, + "2006-01-02T15:04:05", "January 2, 2006", } diff --git a/types_test.go b/types_test.go new file mode 100644 index 0000000..1323e34 --- /dev/null +++ b/types_test.go @@ -0,0 +1,23 @@ +package brave_test + +import ( + "encoding/json" + "testing" + + "dev.freespoke.com/brave-search" + "github.com/stretchr/testify/require" +) + +func TestTimestampUnmarshal(t *testing.T) { + cases := []string{ + `"January 12, 2024"`, + `"2024-03-06T16:41:05"`, + `"25 minutes ago"`, + } + + for _, c := range cases { + var ts brave.Timestamp + require.Nil(t, json.Unmarshal([]byte(c), &ts)) + require.False(t, ts.Time().IsZero(), c) + } +}