new date format for weird long date

This commit is contained in:
Aaron Raddon 2015-07-03 10:27:48 -07:00
parent 78bdcff302
commit 4f9dbf802b
2 changed files with 30 additions and 6 deletions

View File

@ -232,6 +232,7 @@ iterRunes:
// Monday, 02-Jan-06 15:04:05 MST // Monday, 02-Jan-06 15:04:05 MST
// Mon, 02 Jan 2006 15:04:05 MST // Mon, 02 Jan 2006 15:04:05 MST
// Mon, 02 Jan 2006 15:04:05 -0700 // Mon, 02 Jan 2006 15:04:05 -0700
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
if unicode.IsLetter(r) { if unicode.IsLetter(r) {
continue continue
} }
@ -244,6 +245,11 @@ iterRunes:
// state = ST_ALPHADIGIT // state = ST_ALPHADIGIT
} }
case ST_ALPHAWS: // Starts alpha then whitespace case ST_ALPHAWS: // Starts alpha then whitespace
// May 8, 2009 5:57:51 PM
// Mon Jan _2 15:04:05 2006
// Mon Jan _2 15:04:05 MST 2006
// Mon Jan 02 15:04:05 -0700 2006
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
switch { switch {
// case r == ' ': // case r == ' ':
// state = ST_ALPHAWSWS // state = ST_ALPHAWSWS
@ -276,30 +282,42 @@ iterRunes:
//u.Error(err) //u.Error(err)
} }
case ST_ALPHAWSALPHA: // Starts Alpha, whitespace, alpha case ST_ALPHAWSALPHA: // Starts Alpha, whitespace, alpha
// ANSIC = "Mon Jan _2 15:04:05 2006" // Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
// UnixDate = "Mon Jan _2 15:04:05 MST 2006" // Mon Jan _2 15:04:05 2006
// RubyDate = "Mon Jan 02 15:04:05 -0700 2006" // Mon Jan _2 15:04:05 MST 2006
if len(datestr) == len("Mon Jan _2 15:04:05 2006") { // Mon Jan 02 15:04:05 -0700 2006
switch {
case len(datestr) == len("Mon Jan _2 15:04:05 2006"):
if t, err := time.Parse(time.ANSIC, datestr); err == nil { if t, err := time.Parse(time.ANSIC, datestr); err == nil {
return t, nil return t, nil
} else { } else {
//break iterRunes //break iterRunes
return time.Time{}, err return time.Time{}, err
} }
} else if len(datestr) == len("Mon Jan _2 15:04:05 MST 2006") { case len(datestr) == len("Mon Jan _2 15:04:05 MST 2006"):
if t, err := time.Parse(time.UnixDate, datestr); err == nil { if t, err := time.Parse(time.UnixDate, datestr); err == nil {
return t, nil return t, nil
} else { } else {
//break iterRunes //break iterRunes
return time.Time{}, err return time.Time{}, err
} }
} else if len(datestr) == len("Mon Jan 02 15:04:05 -0700 2006") { case len(datestr) == len("Mon Jan 02 15:04:05 -0700 2006"):
if t, err := time.Parse(time.RubyDate, datestr); err == nil { if t, err := time.Parse(time.RubyDate, datestr); err == nil {
return t, nil return t, nil
} else { } else {
//break iterRunes //break iterRunes
return time.Time{}, err return time.Time{}, err
} }
case len(datestr) > len("Mon Jan 02 2006 15:04:05 MST-0700"):
// What effing time stamp is this?
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
dateTmp := datestr[:33]
if t, err := time.Parse("Mon Jan 02 2006 15:04:05 MST-0700", dateTmp); err == nil {
return t, nil
} else {
//break iterRunes
return time.Time{}, err
}
} }
default: default:
//u.Infof("no case for: %d", state) //u.Infof("no case for: %d", state)

View File

@ -84,6 +84,12 @@ func TestParse(t *testing.T) {
//u.Debug(fmt.Sprintf("%v", ts.In(time.UTC)), " ---- ", ts) //u.Debug(fmt.Sprintf("%v", ts.In(time.UTC)), " ---- ", ts)
assert.T(t, "2006-01-02 15:04:05 +0000 MST" == fmt.Sprintf("%v", ts)) assert.T(t, "2006-01-02 15:04:05 +0000 MST" == fmt.Sprintf("%v", ts))
// Easily the worst Date format i have ever seen
// "Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)"
ts, err = ParseAny("Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)")
//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)))
// Golang Native Format // Golang Native Format
ts, err = ParseAny("2015-02-18 00:12:00 +0000 UTC") ts, err = ParseAny("2015-02-18 00:12:00 +0000 UTC")
assert.Tf(t, err == nil, "%v", err) assert.Tf(t, err == nil, "%v", err)