Skip to content

Commit

Permalink
fix(date-parser): failed to parse date "Fri, 31 Mar 2023 20:19:00 Ame…
Browse files Browse the repository at this point in the history
…rica/Los_Angeles" by adding timezone to invalidTimezoneReplacer

test(date-parser): add TestParseRSSDateTimezone unit test
  • Loading branch information
jeankhawand authored and fguillot committed Aug 1, 2023
1 parent 31538c5 commit da0198c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions reader/date/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ var dateFormats = []string{

var invalidTimezoneReplacer = strings.NewReplacer(
"Europe/Brussels", "CET",
"America/Los_Angeles", "PDT",
"GMT+0000 (Coordinated Universal Time)", "GMT",
"GMT-", "GMT -",
)
Expand Down
29 changes: 29 additions & 0 deletions reader/date/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,35 @@ func TestParseAtomDate(t *testing.T) {
}
}

func TestParseRSSDateTimezone(t *testing.T) {
date, err := Parse("Fri, 31 Mar 2023 20:19:00 America/Los_Angeles")
if err != nil {
t.Fatalf(`RSS dates should be parsed correctly`)
}

expectedTS := int64(1680319140)
if date.Unix() != expectedTS {
t.Errorf(`The Unix timestamp should be %v instead of %v`, expectedTS, date.Unix())
}

expectedLocation := "America/Los_Angeles"
if date.Location().String() != expectedLocation {
t.Errorf(`The location should be %q instead of %q`, expectedLocation, date.Location())
}

name, offset := date.Zone()

expectedName := "PDT"
if name != expectedName {
t.Errorf(`The zone name should be %q instead of %q`, expectedName, name)
}

expectedOffset := -25200
if offset != expectedOffset {
t.Errorf(`The offset should be %v instead of %v`, expectedOffset, offset)
}
}

func TestParseRSSDateGMT(t *testing.T) {
date, err := Parse("Tue, 03 Jun 2003 09:39:21 GMT")
if err != nil {
Expand Down

0 comments on commit da0198c

Please sign in to comment.