From 2943ab2f5bf12ebae0827d5ecec3ccbac004ce5d Mon Sep 17 00:00:00 2001 From: Aaron Raddon Date: Mon, 30 Jan 2017 17:18:48 -0800 Subject: [PATCH] New date format --- README.md | 1 + example/main.go | 2 ++ parseany.go | 11 ++++++++++- parseany_test.go | 5 +++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b613f5..5fba297 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ var examples = []string{ "2009-08-12T22:15:09Z", "2009-08-12T22:15:09", "2014-04-26 17:24:37.3186369", + "2014-04-26 17:24:37.318636", "2012-08-03 18:31:59.257000000 +0000 UTC", "2015-09-30 18:48:56.35272715 +0000 UTC", "2012-08-03 18:31:59.257000000", diff --git a/example/main.go b/example/main.go index abf6f75..f3ed09f 100644 --- a/example/main.go +++ b/example/main.go @@ -44,6 +44,7 @@ var examples = []string{ "2009-08-12T22:15:09Z", "2009-08-12T22:15:09", "2014-04-26 17:24:37.3186369", + "2014-04-26 17:24:37.318636", "2012-08-03 18:31:59.257000000 +0000 UTC", "2015-09-30 18:48:56.35272715 +0000 UTC", "2012-08-03 18:31:59.257000000", @@ -115,6 +116,7 @@ func main() { | 2009-08-12T22:15:09Z | 2009-08-12 22:15:09 +0000 UTC | | 2009-08-12T22:15:09 | 2009-08-12 22:15:09 +0000 UTC | | 2014-04-26 17:24:37.3186369 | 2014-04-26 17:24:37.3186369 +0000 UTC | +| 2014-04-26 17:24:37.318636 | 2014-04-26 17:24:37.318636 +0000 UTC | | 2012-08-03 18:31:59.257000000 +0000 UTC | 2012-08-03 18:31:59.257 +0000 UTC | | 2015-09-30 18:48:56.35272715 +0000 UTC | 2015-09-30 18:48:56.35272715 +0000 UTC | | 2012-08-03 18:31:59.257000000 | 2012-08-03 18:31:59.257 +0000 UTC | diff --git a/parseany.go b/parseany.go index 5458575..936ac4e 100644 --- a/parseany.go +++ b/parseany.go @@ -102,6 +102,7 @@ iterRunes: // 2006-01-02T15:04:05.999999999Z07:00 // 2012-08-03 18:31:59.257000000 // 2014-04-26 17:24:37.3186369 + // 2017-01-27 00:07:31.945167 // 2016-03-14 00:00:00.000 // 2014-05-11 08:20:13,787 // 2006-01-02 @@ -115,6 +116,7 @@ iterRunes: } case ST_DIGITDASHWS: // starts digit then dash 02- then whitespace // 2014-04-26 17:24:37.3186369 + // 2017-01-27 00:07:31.945167 // 2012-08-03 18:31:59.257000000 // 2016-03-14 00:00:00.000 // 2013-04-01 22:43:22 @@ -468,8 +470,9 @@ iterRunes: } } case ST_DIGITDASHWS: // starts digit then dash 02- then whitespace 1 << 2 << 5 + 3 - // 2014-04-26 17:24:37.3186369 // 2012-08-03 18:31:59.257000000 + // 2014-04-26 17:24:37.3186369 + // 2017-01-27 00:07:31.945167 // 2016-03-14 00:00:00.000 // 2013-04-01 22:43:22 if len(datestr) == len("2012-08-03 18:31:59.257000000") { @@ -484,6 +487,12 @@ iterRunes: } else { return time.Time{}, err } + } else if len(datestr) == len("2014-04-26 05:24:37.945167") { + if t, err := time.Parse("2006-01-02 15:04:05.000000", datestr); err == nil { + return t, nil + } else { + return time.Time{}, err + } } else if len(datestr) == len("2014-04-26 05:24:37.000") { if t, err := time.Parse("2006-01-02 15:04:05.000", datestr); err == nil { return t, nil diff --git a/parseany_test.go b/parseany_test.go index 3307a4d..f1bd944 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -261,6 +261,11 @@ func TestParse(t *testing.T) { //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) assert.T(t, "2015-09-30 18:48:56.35272715 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + ts, err = ParseAny("2017-01-27 00:07:31.945167") + assert.Tf(t, err == nil, "%v", err) + //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) + assert.T(t, "2017-01-27 00:07:31.945167 +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))