From 39fde9de9e014d69c661a5a909d8a4412c21e234 Mon Sep 17 00:00:00 2001 From: Aaron Raddon Date: Mon, 11 Dec 2017 10:53:38 -0800 Subject: [PATCH] new format: 2017-12-11 10:16 no seconds closes #31 --- parseany.go | 8 +++++++- parseany_test.go | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/parseany.go b/parseany.go index ffe7a2c..131e803 100644 --- a/parseany.go +++ b/parseany.go @@ -668,7 +668,13 @@ iterRunes: } case stateDigitDashWs: // starts digit then dash 02- then whitespace 1 << 2 << 5 + 3 // 2013-04-01 22:43:22 - return parse("2006-01-02 15:04:05", datestr, loc) + // 2013-04-01 22:43 + switch len(datestr) { + case len("2013-04-01 22:43"): + return parse("2006-01-02 15:04", datestr, loc) + default: + return parse("2006-01-02 15:04:05", datestr, loc) + } case stateDigitDashWsWsOffset: // 2006-01-02 15:04:05 -0700 diff --git a/parseany_test.go b/parseany_test.go index 3d69af3..35422e2 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -365,6 +365,9 @@ func TestParse(t *testing.T) { ts = MustParse("2012-08-03 18:31:59.257000000") assert.Equal(t, "2012-08-03 18:31:59.257 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) + ts = MustParse("2013-04-01 22:43") + assert.Equal(t, "2013-04-01 22:43:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) + ts = MustParse("2013-04-01 22:43:22") assert.Equal(t, "2013-04-01 22:43:22 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))