mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
new date format for weird long date
This commit is contained in:
parent
78bdcff302
commit
4f9dbf802b
30
parseany.go
30
parseany.go
@ -232,6 +232,7 @@ iterRunes:
|
||||
// Monday, 02-Jan-06 15:04:05 MST
|
||||
// Mon, 02 Jan 2006 15:04:05 MST
|
||||
// Mon, 02 Jan 2006 15:04:05 -0700
|
||||
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
|
||||
if unicode.IsLetter(r) {
|
||||
continue
|
||||
}
|
||||
@ -244,6 +245,11 @@ iterRunes:
|
||||
// state = ST_ALPHADIGIT
|
||||
}
|
||||
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 {
|
||||
// case r == ' ':
|
||||
// state = ST_ALPHAWSWS
|
||||
@ -276,30 +282,42 @@ iterRunes:
|
||||
//u.Error(err)
|
||||
}
|
||||
case ST_ALPHAWSALPHA: // Starts Alpha, whitespace, alpha
|
||||
// ANSIC = "Mon Jan _2 15:04:05 2006"
|
||||
// UnixDate = "Mon Jan _2 15:04:05 MST 2006"
|
||||
// RubyDate = "Mon Jan 02 15:04:05 -0700 2006"
|
||||
if len(datestr) == len("Mon Jan _2 15:04:05 2006") {
|
||||
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
|
||||
// Mon Jan _2 15:04:05 2006
|
||||
// Mon Jan _2 15:04:05 MST 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 {
|
||||
return t, nil
|
||||
} else {
|
||||
//break iterRunes
|
||||
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 {
|
||||
return t, nil
|
||||
} else {
|
||||
//break iterRunes
|
||||
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 {
|
||||
return t, nil
|
||||
} else {
|
||||
//break iterRunes
|
||||
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:
|
||||
//u.Infof("no case for: %d", state)
|
||||
|
@ -84,6 +84,12 @@ func TestParse(t *testing.T) {
|
||||
//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))
|
||||
|
||||
// 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
|
||||
ts, err = ParseAny("2015-02-18 00:12:00 +0000 UTC")
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user