diff --git a/parseany.go b/parseany.go index 9984d43..bbc31dd 100644 --- a/parseany.go +++ b/parseany.go @@ -35,6 +35,7 @@ const ( ST_DIGITDASHTZ ST_DIGITDASHTZDIGIT ST_DIGITDASHTDELTA + ST_DIGITDASHTDELTACOLON ST_DIGITSLASH ST_DIGITSLASHWS ST_DIGITSLASHWSCOLON @@ -116,6 +117,7 @@ iterRunes: // 2006-01-02T15:04:05Z07:00 // 2017-06-25T17:46:57.45706582-07:00 // 2006-01-02T15:04:05.999999999Z07:00 + // 2006-01-02T15:04:05+0000 // 2012-08-03 18:31:59.257000000 // 2014-04-26 17:24:37.3186369 // 2017-01-27 00:07:31.945167 @@ -203,9 +205,11 @@ iterRunes: // 2006-01-02T15:04:05.999999999Z07:00 // 2006-01-02T15:04:05Z07:00 // With another dash aka time-zone at end - // ST_DIGITDASHTDASH - // 2017-06-25T17:46:57.45706582-07:00 - // 2017-06-25T17:46:57+04:00 + // ST_DIGITDASHTDELTA + // ST_DIGITDASHTDELTACOLON + // 2017-06-25T17:46:57.45706582-07:00 + // 2017-06-25T17:46:57+04:00 + // 2006-01-02T15:04:05+0000 switch r { case '-', '+': state = ST_DIGITDASHTDELTA @@ -216,6 +220,10 @@ iterRunes: if unicode.IsDigit(r) { state = ST_DIGITDASHTZDIGIT } + case ST_DIGITDASHTDELTA: + if r == ':' { + state = ST_DIGITDASHTDELTACOLON + } case ST_DIGITSLASH: // starts digit then slash 02/ // 2014/07/10 06:55:38.156283 // 03/19/2012 10:11:59 @@ -451,6 +459,10 @@ iterRunes: return time.Parse("2006-01", datestr) } case ST_DIGITDASHTDELTA: + // 2006-01-02T15:04:05+0000 + return time.Parse("2006-01-02T15:04:05-0700", datestr) + + case ST_DIGITDASHTDELTACOLON: // With another +/- time-zone at end // 2006-01-02T15:04:05.999999999+07:00 // 2006-01-02T15:04:05.999999999-07:00 diff --git a/parseany_test.go b/parseany_test.go index 6e61f3e..19f4887 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -398,20 +398,29 @@ func TestParse(t *testing.T) { ts = MustParse("2014-05-11 08:20:13,787") assert.Equal(t, "2014-05-11 08:20:13.787 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) - _, err = ParseAny("2014-13-13 08:20:13,787") // month 13 doesn't exist + _, err = ParseAny("2014-13-13 08:20:13,787") // month 13 doesn't exist so error assert.NotEqual(t, nil, err) ts = MustParse("2014-05-11 08:20:13 +00:00") assert.Equal(t, "2014-05-11 08:20:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) + ts = MustParse("2014-05-11 08:20:13 +0000") + assert.Equal(t, "2014-05-11 08:20:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) + ts = MustParse("2016-06-21T19:55:00+01:00") assert.Equal(t, "2016-06-21 18:55:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) ts = MustParse("2016-06-21T19:55:00.799+01:00") assert.Equal(t, "2016-06-21 18:55:00.799 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) - ts = MustParse("2014-05-11 08:20:13 +0000") - assert.Equal(t, "2014-05-11 08:20:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) + ts = MustParse("2016-06-21T19:55:00+0100") + assert.Equal(t, "2016-06-21 18:55:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) + + ts = MustParse("2016-06-21T19:55:00-0700") + assert.Equal(t, "2016-06-22 02:55:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) + + ts = MustParse("2016-06-21T19:55:00.799+0100") + assert.Equal(t, "2016-06-21 18:55:00.799 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) // yyyymmdd and similar ts = MustParse("2014")