From 73f547e7b63a8eaded3e5176d4aaf2d57c553c32 Mon Sep 17 00:00:00 2001 From: Aaron Raddon Date: Fri, 14 Jul 2017 07:02:22 -0700 Subject: [PATCH] New zone format --- parseany.go | 18 ++++++++++++++++++ parseany_test.go | 3 +++ 2 files changed, 21 insertions(+) diff --git a/parseany.go b/parseany.go index dead3d4..9984d43 100644 --- a/parseany.go +++ b/parseany.go @@ -56,6 +56,7 @@ const ( ST_WEEKDAYCOMMADELTA ST_WEEKDAYABBREVCOMMA ST_WEEKDAYABBREVCOMMADELTA + ST_WEEKDAYABBREVCOMMADELTAZONE ) var ( @@ -296,6 +297,8 @@ iterRunes: // ST_WEEKDAYABBREVCOMMADELTA // Mon, 02 Jan 2006 15:04:05 -0700 // Thu, 13 Jul 2017 08:58:40 +0100 + // ST_WEEKDAYABBREVCOMMADELTAZONE + // Tue, 11 Jul 2017 16:28:13 +0200 (CEST) switch { case unicode.IsLetter(r): continue @@ -330,6 +333,8 @@ iterRunes: // ST_WEEKDAYABBREVCOMMADELTA // Mon, 02 Jan 2006 15:04:05 -0700 // Thu, 13 Jul 2017 08:58:40 +0100 + // ST_WEEKDAYABBREVCOMMADELTAZONE + // Tue, 11 Jul 2017 16:28:13 +0200 (CEST) switch { case r == '-': if i < 15 { @@ -341,6 +346,16 @@ iterRunes: state = ST_WEEKDAYABBREVCOMMADELTA } + case ST_WEEKDAYABBREVCOMMADELTA: + // ST_WEEKDAYABBREVCOMMADELTA + // Mon, 02 Jan 2006 15:04:05 -0700 + // Thu, 13 Jul 2017 08:58:40 +0100 + // ST_WEEKDAYABBREVCOMMADELTAZONE + // Tue, 11 Jul 2017 16:28:13 +0200 (CEST) + if r == '(' { + state = ST_WEEKDAYABBREVCOMMADELTAZONE + } + case ST_ALPHAWS: // Starts alpha then whitespace // Mon Jan _2 15:04:05 2006 // Mon Jan _2 15:04:05 MST 2006 @@ -680,6 +695,9 @@ iterRunes: // Thu, 13 Jul 2017 08:58:40 +0100 // RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone return time.Parse("Mon, 02 Jan 2006 15:04:05 -0700", datestr) + case ST_WEEKDAYABBREVCOMMADELTAZONE: + // Tue, 11 Jul 2017 16:28:13 +0200 (CEST) + return time.Parse("Mon, 02 Jan 2006 15:04:05 -0700 (CEST)", datestr) } return time.Time{}, fmt.Errorf("Could not find date format for %s", datestr) diff --git a/parseany_test.go b/parseany_test.go index a4a0cf7..6e61f3e 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -153,6 +153,9 @@ func TestParse(t *testing.T) { ts = MustParse("Mon, 02-Jan-06 15:04:05 MST") assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) + ts = MustParse("Tue, 11 Jul 2017 16:28:13 +0200 (CEST)") + assert.Equal(t, "2017-07-11 14:28:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) + ts = MustParse("Thu, 13 Jul 2017 08:58:40 +0100") assert.Equal(t, "2017-07-13 07:58:40 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))