From 497d740c1b412a2d1884850964cb518392972d07 Mon Sep 17 00:00:00 2001 From: Aaron Raddon Date: Sun, 11 May 2014 18:22:16 -0700 Subject: [PATCH] new date format --- parseany.go | 9 +++++++++ parseany_test.go | 13 +++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/parseany.go b/parseany.go index 6476fe6..fc7f859 100644 --- a/parseany.go +++ b/parseany.go @@ -56,6 +56,7 @@ iterRunes: // 2016-03-14 00:00:00.000 // 2014-05-11 08:20:13,787 // 2006-01-02 + // 2013-04-01 22:43:22 // 2014-04-26 05:24:37 PM switch { case r == ' ': @@ -67,6 +68,7 @@ iterRunes: // 2014-04-26 17:24:37.3186369 // 2012-08-03 18:31:59.257000000 // 2016-03-14 00:00:00.000 + // 2013-04-01 22:43:22 // 2014-05-11 08:20:13,787 // 2014-04-26 05:24:37 PM switch r { @@ -211,6 +213,7 @@ iterRunes: // 2014-04-26 17:24:37.3186369 // 2012-08-03 18:31:59.257000000 // 2016-03-14 00:00:00.000 + // 2013-04-01 22:43:22 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 @@ -229,6 +232,12 @@ iterRunes: } else { u.Error(err) } + } else if len(datestr) == len("2013-04-01 22:43:22") { + if t, err := time.Parse("2006-01-02 15:04:05", datestr); err == nil { + return t, nil + } else { + u.Error(err) + } } case 256: // starts digit then slash 02/ // 3/1/2014 diff --git a/parseany_test.go b/parseany_test.go index e3be46f..5558b13 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -114,6 +114,11 @@ func TestParse(t *testing.T) { //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("2013-04-01 22:43:22") + assert.Tf(t, err == nil, "%v", err) + //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) + assert.T(t, "2013-04-01 22:43:22 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + ts, err = ParseAny("2014-04-26 17:24:37.123") assert.Tf(t, err == nil, "%v", err) //u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) @@ -136,8 +141,8 @@ func TestParse(t *testing.T) { } func TestWIP(t *testing.T) { - // 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)) - // assert.T(t, "2012-08-03 18:31:59.257 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) + ts, err := ParseAny("2013-04-01 22:43:22") + assert.Tf(t, err == nil, "%v", err) + u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC)) + assert.T(t, "2013-04-01 22:43:22 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC))) }