another date format, yay

This commit is contained in:
Aaron Raddon 2015-06-25 17:24:55 -07:00
parent 51d5271755
commit 78bdcff302
2 changed files with 18 additions and 2 deletions

View File

@ -106,6 +106,7 @@ iterRunes:
// 2014-04-26 05:24:37 PM
// 2014-12-16 06:20:00 UTC
// 2015-02-18 00:12:00 +0000 UTC
// 2015-06-25 01:25:37.115208593 +0000 UTC
switch r {
case 'A', 'P':
if len(datestr) == len("2014-04-26 03:24:37 PM") {
@ -375,18 +376,27 @@ iterRunes:
}
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") {
// 2015-02-18 00:12:00 +0000 UTC
// 2015-06-25 01:25:37.115208593 +0000 UTC
switch len(datestr) {
case 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
}
} else if len(datestr) == len("2015-02-18 00:12:00 +0000 UTC") {
case len("2015-02-18 00:12:00 +0000 UTC"):
if t, err := time.Parse("2006-01-02 15:04:05 +0000 UTC", datestr); err == nil {
return t, nil
} else {
return time.Time{}, err
}
case len("2015-06-25 01:25:37.115208593 +0000 UTC"):
if t, err := time.Parse("2006-01-02 15:04:05.000000000 +0000 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

View File

@ -198,6 +198,12 @@ 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.3186369 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
// 2015-06-25 01:25:37.115208593 +0000 UTC
ts, err = ParseAny("2012-08-03 18:31:59.257000000 +0000 UTC")
assert.Tf(t, err == nil, "%v", err)
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
assert.T(t, "2012-08-03 18:31:59.257 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
ts, err = ParseAny("2012-08-03 18:31:59.257000000")
assert.Tf(t, err == nil, "%v", err)
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))