From f40887f3bfb971c0bf05a2228aeb59194310ed2d Mon Sep 17 00:00:00 2001 From: Aaron Raddon Date: Fri, 6 Apr 2018 06:57:28 -0700 Subject: [PATCH] new format(no seconds) closes #58 --- parseany.go | 9 +++++++-- parseany_test.go | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/parseany.go b/parseany.go index c9fe2e5..fb74408 100644 --- a/parseany.go +++ b/parseany.go @@ -821,7 +821,7 @@ iterRunes: for ; i < len(datestr); i++ { r := rune(datestr[i]) - //gou.Debugf("%d %s iterTimeRunes %s %s", i, string(r), p.ds(), p.ts()) + //gou.Debugf("%d %s %d iterTimeRunes %s %s", i, string(r), p.stateTime, p.ds(), p.ts()) switch p.stateTime { case timeStart: @@ -871,7 +871,12 @@ iterRunes: case '-', '+': // 03:21:51+00:00 p.stateTime = timeOffset - p.seclen = i - p.seci + if p.seci == 0 { + // 22:18+0530 + p.minlen = i - p.mini + } else { + p.seclen = i - p.seci + } p.offseti = i case '.': p.stateTime = timePeriod diff --git a/parseany_test.go b/parseany_test.go index f1cf6a7..a8416b6 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -126,8 +126,8 @@ func TestInLocation(t *testing.T) { func TestOne(t *testing.T) { time.Local = time.UTC var ts time.Time - ts = MustParse("2014-05-11 08:20:13,787") - assert.Equal(t, "2014-05-11 08:20:13.787 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) + ts = MustParse("2018-04-02T22:18+0000") + assert.Equal(t, "2018-04-02 22:18:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) } type dateTest struct { @@ -310,6 +310,9 @@ var testInputs = []dateTest{ {in: "2014-04-26 17:24:37.12 +0000", out: "2014-04-26 17:24:37.12 +0000 UTC"}, {in: "2014-04-26 17:24:37.1 +0000", out: "2014-04-26 17:24:37.1 +0000 UTC"}, {in: "2014-05-11 08:20:13 +0000", out: "2014-05-11 08:20:13 +0000 UTC"}, + // yyyy-mm-dd hh:mm:ss+0000 + // yyyy-mm-dd hh:mm+0000 + {in: "2014-05-11 08:20:13 +0530", out: "2014-05-11 02:50:13 +0000 UTC"}, // 13:31:51.999 -07:00 MST // yyyy-mm-dd hh:mm:ss +00:00 @@ -400,6 +403,8 @@ var testInputs = []dateTest{ {in: "2016-06-21T19:55:00+0100", out: "2016-06-21 18:55:00 +0000 UTC"}, {in: "2016-06-21T19:55:00-0700", out: "2016-06-22 02:55:00 +0000 UTC"}, {in: "2016-06-21T19:55:00.799+0100", out: "2016-06-21 18:55:00.799 +0000 UTC"}, + {in: "2016-06-21T19:55+0100", out: "2016-06-21 18:55:00 +0000 UTC"}, + {in: "2016-06-21T19:55+0130", out: "2016-06-21 18:25:00 +0000 UTC"}, // yyyy-mm-ddThh:mm:ssZ {in: "2009-08-12T22:15Z", out: "2009-08-12 22:15:00 +0000 UTC"}, {in: "2009-08-12T22:15:09Z", out: "2009-08-12 22:15:09 +0000 UTC"},