-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notion API can return date from page fields in the form of "yyyy-mm-dd" if the field configuration does not include time. The resulting string from the API isn't accepted by the time.RFC3339 format and thus causes an unmarshalling error. The present change fixes it by attempting to parse it as such in case the standard format fails. If it fails again, the error is returned.
- Loading branch information
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package notionapi_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/jomei/notionapi" | ||
) | ||
|
||
func TestDate(t *testing.T) { | ||
t.Run(".UnmarshalText", func(t *testing.T) { | ||
var d notionapi.Date | ||
|
||
t.Run("OK datetime with timezone", func(t *testing.T) { | ||
data := []byte("1987-02-13T00:00:00.000+01:00") | ||
err := d.UnmarshalText(data) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
t.Run("OK date", func(t *testing.T) { | ||
data := []byte("1985-01-02") | ||
err := d.UnmarshalText(data) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
t.Run("NOK", func(t *testing.T) { | ||
data := []byte("1985") | ||
err := d.UnmarshalText(data) | ||
if err == nil { | ||
t.Fatalf("expected an error, got none") | ||
} | ||
}) | ||
}) | ||
} |