diff --git a/parseany.go b/parseany.go index 8f78512..616bc3e 100644 --- a/parseany.go +++ b/parseany.go @@ -280,18 +280,33 @@ iterRunes: // Mon, 02 Jan 2006 15:04:05 MST // Mon, 02 Jan 2006 15:04:05 -0700 // Monday, 02-Jan-06 15:04:05 MST + // Monday, 02 Jan 2006 15:04:05 -0700 switch { case r == '-': state = ST_ALPHACOMMADASH } - + if t, err := time.Parse("Mon, 02 Jan 2006 15:04:05 MST", datestr); err == nil { + return t, nil + } + if t, err := time.Parse("Monday, 02 Jan 2006 15:04:05 MST", datestr); err == nil { + return t, nil + } case ST_ALPHACOMMADASH: // Starts alpha then comma and one dash // Mon, 02 Jan 2006 15:04:05 -0700 + // Monday, 02 Jan 2006 15:04:05 -0700 // Monday, 02-Jan-06 15:04:05 MST switch { case r == '-': state = ST_ALPHACOMMADASHDASH } + t, err := time.Parse("Mon, 02 Jan 2006 15:04:05 -0700", datestr) + if err == nil { + return t, nil + } + if t, err := time.Parse("Monday, 02 Jan 2006 15:04:05 -0700", datestr); err == nil { + return t, nil + } + case ST_ALPHAWSCOMMA: // Starts Alpha, whitespace, digit, comma // May 8, 2009 5:57:51 PM if t, err := time.Parse("Jan 2, 2006 3:04:05 PM", datestr); err == nil { diff --git a/parseany_test.go b/parseany_test.go index 0701c65..bc0466b 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -106,6 +106,16 @@ func TestParse(t *testing.T) { //u.Debug(fmt.Sprintf("%v", ts.In(time.UTC)), " ---- ", ts.In(time.UTC)) assert.T(t, "2015-07-03 17:04:07 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + ts, err = ParseAny("Mon, 02 Jan 2006 15:04:05 MST") + assert.Tf(t, err == nil, "%v", err) + //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) + assert.T(t, "2006-01-02 15:04:05 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + + ts, err = ParseAny("Mon, 02 Jan 2006 15:04:05 -0700") + assert.Tf(t, err == nil, "%v", err) + //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) + assert.T(t, "2006-01-02 22:04:05 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + // Golang Native Format ts, err = ParseAny("2015-02-18 00:12:00 +0000 UTC") assert.Tf(t, err == nil, "%v", err)