From e215f86f9d885b2d08345027abcde046ca2e576f Mon Sep 17 00:00:00 2001 From: Maxim Vladimirskiy Date: Tue, 14 Apr 2020 12:31:56 +0300 Subject: [PATCH] Allow single digit day in RFC822 time --- v3/clock/rfc822.go | 4 ++-- v3/clock/rfc822_test.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/v3/clock/rfc822.go b/v3/clock/rfc822.go index e68b9cb6..446b58b4 100644 --- a/v3/clock/rfc822.go +++ b/v3/clock/rfc822.go @@ -30,13 +30,13 @@ func (t *RFC822Time) UnmarshalJSON(s []byte) error { if err != nil { return err } - if t.Time, err = Parse(RFC1123, q); err == nil { + if t.Time, err = Parse("Mon, 2 Jan 2006 15:04:05 MST", q); err == nil { return nil } if err, ok := err.(*ParseError); !ok || err.LayoutElem != "MST" { return err } - if t.Time, err = Parse(RFC1123Z, q); err != nil { + if t.Time, err = Parse("Mon, 2 Jan 2006 15:04:05 -0700", q); err != nil { return err } return nil diff --git a/v3/clock/rfc822_test.go b/v3/clock/rfc822_test.go index 6d27f0e0..49bca502 100644 --- a/v3/clock/rfc822_test.go +++ b/v3/clock/rfc822_test.go @@ -79,6 +79,18 @@ func TestRFC822Unmarshaling(t *testing.T) { inRFC822: "Thu, 29 Aug 2019 11:20:07 +0330", outRFC3339: "2019-08-29T11:20:07+03:30", outRFC822: "Thu, 29 Aug 2019 11:20:07 +0330", + }, { + inRFC822: "Sun, 01 Sep 2019 11:20:07 +0300", + outRFC3339: "2019-09-01T11:20:07+03:00", + outRFC822: "Sun, 01 Sep 2019 11:20:07 MSK", + }, { + inRFC822: "Sun, 1 Sep 2019 11:20:07 +0300", + outRFC3339: "2019-09-01T11:20:07+03:00", + outRFC822: "Sun, 01 Sep 2019 11:20:07 MSK", + }, { + inRFC822: "Sun, 1 Sep 2019 11:20:07 +0300", + outRFC3339: "2019-09-01T11:20:07+03:00", + outRFC822: "Sun, 01 Sep 2019 11:20:07 MSK", }} { tcDesc := fmt.Sprintf("Test case #%d: %v", i, tc) var ts testStruct