From 78bdcff3024e33fd4a3629f9ff1d4b7d78180bd8 Mon Sep 17 00:00:00 2001 From: Aaron Raddon Date: Thu, 25 Jun 2015 17:24:55 -0700 Subject: [PATCH] another date format, yay --- parseany.go | 14 ++++++++++++-- parseany_test.go | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/parseany.go b/parseany.go index 2e7959b..0acc476 100644 --- a/parseany.go +++ b/parseany.go @@ -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 diff --git a/parseany_test.go b/parseany_test.go index 6518103..329442d 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -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))