diff --git a/parseany.go b/parseany.go index 4ef312f..5369023 100644 --- a/parseany.go +++ b/parseany.go @@ -16,6 +16,7 @@ const ( ST_DIGIT ST_DIGITDASH ST_DIGITDASHWS + ST_DIGITDASHWSALPHA ST_DIGITDASHT ST_DIGITCOMMA ST_DIGITCOLON @@ -99,6 +100,7 @@ iterRunes: // 2013-04-01 22:43:22 // 2014-05-11 08:20:13,787 // 2014-04-26 05:24:37 PM + // 2014-12-16 06:20:00 UTC switch r { case 'A', 'P': if len(datestr) == len("2014-04-26 03:24:37 PM") { @@ -121,6 +123,12 @@ iterRunes: return time.Time{}, err } } + default: + if unicode.IsLetter(r) { + // 2014-12-16 06:20:00 UTC + state = ST_DIGITDASHWSALPHA + break iterRunes + } } case ST_DIGITDASHT: // starts digit then dash 02- then T // 2006-01-02T15:04:05Z07:00 @@ -353,6 +361,15 @@ iterRunes: return time.Time{}, err } } + case ST_DIGITDASHWSALPHA: // starts digit then dash 02- then whitespace 1 << 2 << 5 + 3 + // 2014-12-16 06:20:00 UTC + if len(datestr) == len("2006-01-02 15:04:05 UTC") { + if t, err := time.Parse("2006-01-02 15:04:05 UTC", datestr); err == nil { + return t, nil + } else { + return time.Time{}, err + } + } case ST_DIGITSLASH: // starts digit then slash 02/ (but nothing else) // 3/1/2014 // 10/13/2014 diff --git a/parseany_test.go b/parseany_test.go index 9564bf8..1fa0c00 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -203,6 +203,11 @@ func TestParse(t *testing.T) { //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) assert.T(t, "2014-04-26 17:24:37.123 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + ts, err = ParseAny("2014-12-16 06:20:00 UTC") + assert.Tf(t, err == nil, "%v", err) + //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) + assert.T(t, "2014-12-16 06:20:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + ts, err = ParseAny("2014-04-26 05:24:37 PM") assert.Tf(t, err == nil, "%v", err) //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))