From d6e91490c722bf81382913eb46483650aeb9c205 Mon Sep 17 00:00:00 2001 From: allisonmorgan Date: Tue, 25 Nov 2014 13:16:59 -0800 Subject: [PATCH] Added support for timestamps like: "2006-01-02 15:04:05 UTC" --- parseany.go | 12 +++++++++++- parseany_test.go | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/parseany.go b/parseany.go index 701b335..244dacf 100644 --- a/parseany.go +++ b/parseany.go @@ -127,7 +127,12 @@ iterRunes: // 2006-01-02T15:04:05.999999999Z07:00 // 2006-01-02T15:04:05.999999999Z // 2006-01-02T15:04:05.99999999Z - // 2013-06-16T06:57:48.9999999Z + // 2006-01-02T15:04:05.9999999Z + // 2006-01-02T15:04:05.999999Z + // 2006-01-02T15:04:05.99999Z + // 2006-01-02T15:04:05.9999Z + // 2006-01-02T15:04:05.999Z + // 2006-01-02T15:04:05.99Z if len(datestr) == len("2006-01-02T15:04:05Z07:00") { if t, err := time.Parse("2006-01-02T15:04:05Z07:00", datestr); err == nil { return t, nil @@ -317,6 +322,7 @@ iterRunes: // 2012-08-03 18:31:59.257000000 // 2016-03-14 00:00:00.000 // 2013-04-01 22:43:22 + // 2014-12-16 06:20:00 UTC if len(datestr) == len("2012-08-03 18:31:59.257000000") { if t, err := time.Parse("2006-01-02 15:04:05.000000000", datestr); err == nil { return t, nil @@ -329,9 +335,13 @@ iterRunes: } else { return time.Time{}, err } + // the strings "2014-04-26 05:24:37.000" and "2014-12-16 06:20:00 UTC" + // have the same length so I'll throw them under the same else if.. } 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 + } else if t, err := time.Parse("2006-01-02 15:04:05 UTC", datestr); err == nil { + return t, nil } else { return time.Time{}, err } diff --git a/parseany_test.go b/parseany_test.go index 957fa55..20d0603 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -223,6 +223,10 @@ func TestParse(t *testing.T) { //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) assert.T(t, "2012-03-19 10:11:59 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + ts, err = ParseAny("2014-12-16 06:20:00 UTC") + assert.Tf(t, err == nil, "%v", err) + //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) + assert.T(t, "2014-12-16 06:20:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) } // func TestWIP(t *testing.T) {