Merge pull request #4 from allisonmorgan/master

Support timestamps with leading day of week
This commit is contained in:
Aaron Raddon 2016-05-03 13:10:41 -07:00
commit 7c2f96b241
2 changed files with 26 additions and 1 deletions

View File

@ -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 {

View File

@ -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)