From 068594790e4876430e17a88ee62358116630f71d Mon Sep 17 00:00:00 2001 From: Zifeng Yu Date: Sat, 24 Jul 2021 20:24:59 +0800 Subject: [PATCH] issue-130 fix timezone detection issue after timePeriod --- parseany.go | 7 +++++++ parseany_test.go | 1 + 2 files changed, 8 insertions(+) diff --git a/parseany.go b/parseany.go index b9668b2..0c140e7 100644 --- a/parseany.go +++ b/parseany.go @@ -1503,6 +1503,8 @@ iterRunes: // 22:18:00.001 +0000 UTC m=+0.000000001 // timePeriodWsAlpha // 06:20:00.000 UTC + // timeZ + // 15:09:23.099Z switch r { case ' ': p.mslen = i - p.msi @@ -1512,6 +1514,11 @@ iterRunes: p.mslen = i - p.msi p.offseti = i p.stateTime = timePeriodOffset + case 'Z': + p.mslen = i - p.msi + // (Z)ulu time + p.loc = time.UTC + p.stateTime = timeZ default: if unicode.IsLetter(r) { // 06:20:00.000 UTC diff --git a/parseany_test.go b/parseany_test.go index 7fea1e6..0614144 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -389,6 +389,7 @@ var testInputs = []dateTest{ {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"}, {in: "2009-08-12T22:15:09.99Z", out: "2009-08-12 22:15:09.99 +0000 UTC"}, + {in: "2009-08-12T22:15:09.99Z", out: "2009-08-12 22:15:09.99 +0000 UTC", loc: "Asia/Shanghai"}, {in: "2009-08-12T22:15:09.9999Z", out: "2009-08-12 22:15:09.9999 +0000 UTC"}, {in: "2009-08-12T22:15:09.99999999Z", out: "2009-08-12 22:15:09.99999999 +0000 UTC"}, {in: "2009-08-12T22:15:9.99999999Z", out: "2009-08-12 22:15:09.99999999 +0000 UTC"},