Skip to content

Commit

Permalink
Improves release date time handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
adlio committed Jan 30, 2019
1 parent 1725b38 commit 571ba70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion release-date.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func (date *ReleaseDate) Scan(value interface{}) error {
// parsing to time.Time.
func (date *ReleaseDate) ScanString(s string) {
var ptn string
if len(s) > 10 {
if len(s) == 20 {
ptn = "2006-01-02T15:04:05Z"
} else if len(s) > 10 {
ptn = "2006-01-02 15:04:05"
} else {
ptn = "2006-01-02"
Expand Down
8 changes: 8 additions & 0 deletions release-date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ func TestDateScanTime(t *testing.T) {
assert.Equal(t, 1, d.Day())
}

func TestDateScanTimelessUTCString(t *testing.T) {
var d ReleaseDate
d.Scan("2015-02-02T00:00:00Z")
assert.Equal(t, 2015, d.Year())
assert.Equal(t, time.February, d.Month())
assert.Equal(t, 2, d.Day())
}

func TestUnmarshalXML(t *testing.T) {
s := struct {
ReleaseDate ReleaseDate
Expand Down

0 comments on commit 571ba70

Please sign in to comment.