diff --git a/parseany.go b/parseany.go index b55eff3..0d0be2f 100644 --- a/parseany.go +++ b/parseany.go @@ -35,7 +35,7 @@ const ( ST_DIGITDASHT ST_DIGITDASHTZ ST_DIGITDASHTZDIGIT - ST_DIGITDASHTDASH + ST_DIGITDASHTDELTA ST_DIGITCOMMA ST_DIGITCOLON ST_DIGITSLASH @@ -217,9 +217,10 @@ iterRunes: // 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 switch { - case r == '-': - state = ST_DIGITDASHTDASH + case r == '-', r == '+': + state = ST_DIGITDASHTDELTA case r == 'Z': state = ST_DIGITDASHTZ } @@ -499,16 +500,16 @@ iterRunes: return time.Time{}, err } } - case ST_DIGITDASHTDASH: - // With another dash aka time-zone at end + case ST_DIGITDASHTDELTA: + // With another +/- time-zone at end + // 2006-01-02T15:04:05.999999999+07:00 // 2006-01-02T15:04:05.999999999-07:00 - // 2006-01-02T15:04:05.99999999-07:00 - // 2006-01-02T15:04:05.9999999-07:00 + // 2006-01-02T15:04:05.999999+07:00 // 2006-01-02T15:04:05.999999-07:00 - // 2006-01-02T15:04:05.99999-07:00 - // 2006-01-02T15:04:05.9999-07:00 + // 2006-01-02T15:04:05.999+07:00 // 2006-01-02T15:04:05.999-07:00 - // 2006-01-02T15:04:05.99-07:00 + // 2006-01-02T15:04:05+07:00 + // 2006-01-02T15:04:05-07:00 if t, err := time.Parse("2006-01-02T15:04:05-07:00", datestr); err == nil { return t, nil } else { diff --git a/parseany_test.go b/parseany_test.go index a2fd923..4589c55 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -393,6 +393,14 @@ func TestParse(t *testing.T) { assertf(t, err == nil, "%v", err) assert(t, "2014-05-11 08:20:13 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + ts, err = ParseAny("2016-06-21T19:55:00+01:00") + assertf(t, err == nil, "%v", err) + assert(t, "2016-06-21 18:55:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + + ts, err = ParseAny("2016-06-21T19:55:00.799+01:00") + assertf(t, err == nil, "%v", err) + assert(t, "2016-06-21 18:55:00.799 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + ts, err = ParseAny("2014-05-11 08:20:13 +0000") assertf(t, err == nil, "%v", err) assert(t, "2014-05-11 08:20:13 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))