From 0dca814ad38051523950b78870a54b39eb459d2c Mon Sep 17 00:00:00 2001 From: Aaron Raddon Date: Thu, 25 Jun 2015 14:09:39 -0700 Subject: [PATCH] new date format --- parseany.go | 8 ++++++++ parseany_test.go | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/parseany.go b/parseany.go index 671f5f2..da7fdec 100644 --- a/parseany.go +++ b/parseany.go @@ -137,6 +137,7 @@ iterRunes: } case ST_DIGITDASHT: // starts digit then dash 02- then T // 2006-01-02T15:04:05Z07:00 + // 2006-01-02T15:04:05 // 2006-01-02T15:04:05.999999999Z07:00 // 2006-01-02T15:04:05.999999999Z // 2006-01-02T15:04:05.99999999Z @@ -158,6 +159,13 @@ iterRunes: } else { return time.Time{}, err } + } else if len(datestr) == len("2006-01-02T15:04:05") { + if t, err := time.Parse("2006-01-02T15:04:05", datestr); err == nil { + u.Errorf("wat? %v", t) + return t, nil + } else { + return time.Time{}, err + } } else { // updated to include timestamps of different precisions if t, err := time.Parse("2006-01-02T15:04:05.999999999Z", datestr); err == nil { diff --git a/parseany_test.go b/parseany_test.go index 1ca50e7..6518103 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -188,6 +188,11 @@ func TestParse(t *testing.T) { //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) assert.T(t, "2009-08-13 05:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + ts, err = ParseAny("2009-08-12T22:15:09") + assert.Tf(t, err == nil, "%v", err) + //u.Debug(ts.In(time.UTC)) + assert.T(t, "2009-08-12 22:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + ts, err = ParseAny("2014-04-26 17:24:37.3186369") assert.Tf(t, err == nil, "%v", err) //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))