From 7b91f1acd1d04f9cb9c0d17d41c7e971c8d811e7 Mon Sep 17 00:00:00 2001 From: Aaron Raddon Date: Tue, 6 May 2014 12:32:49 -0700 Subject: [PATCH] add new date format --- parseany.go | 18 +++++++++++++++++- parseany_test.go | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/parseany.go b/parseany.go index bd8171d..4cb5844 100644 --- a/parseany.go +++ b/parseany.go @@ -177,10 +177,26 @@ func ParseAny(datestr string) (time.Time, error) { case f.Has(HAS_DASH) && !f.Has(HAS_SLASH): switch { case f.Has(HAS_WHITESPACE) && f.Has(HAS_COLON): + //2014-04-26 05:24:37.3186369 //2006-01-02 15:04:05.000 - case f.Has(HAS_WHITESPACE) && f.Has(HAS_COLON): //2006-01-02 //2006-01-02 + if len(datestr) == len("2014-04-26 05:24:37.3186369") { + if t, err := time.Parse("2006-01-02 03:04:05.0000000", datestr); err == nil { + return t, nil + } else { + u.Error(err) + } + } else if len(datestr) == len("2014-04-26 05:24:37.3186369") { + if t, err := time.Parse("2006-01-02 03:04:05.000", datestr); err == nil { + return t, nil + } else { + u.Error(err) + } + } + + default: + } case f.Has(HAS_SLASH): switch { diff --git a/parseany_test.go b/parseany_test.go index b333960..a62193a 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -91,4 +91,10 @@ func TestParse(t *testing.T) { //u.Debug(ts2.In(time.UTC), " ", ts2.Unix()) assert.T(t, "2009-08-13 05:15:09 +0000 UTC" == fmt.Sprintf("%v", ts2.In(time.UTC))) + //2014-04-26 05:24:37.3186369 + ts, err = ParseAny("2014-04-26 05:24:37.3186369") + assert.T(t, err == nil) + u.Debug(ts.Unix(), ts) + assert.T(t, "2014-04-26 05:24:37.3186369 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + }