Support Atom dates in RSS feeds.

Some generators seem to get this wrong; act gracefully.
This commit is contained in:
Leslie P. Polzer 2019-03-09 17:32:42 -08:00
parent e6dab863fc
commit 307868a646
3 changed files with 3859 additions and 2 deletions

3
rss.go
View file

@ -59,6 +59,9 @@ func (d Date) Parse() (time.Time, error) {
t, err := d.ParseWithFormat(wordpressDateFormat) t, err := d.ParseWithFormat(wordpressDateFormat)
if err != nil { if err != nil {
t, err = d.ParseWithFormat(time.RFC822) // RSS 2.0 spec t, err = d.ParseWithFormat(time.RFC822) // RSS 2.0 spec
if err != nil {
t, err = d.ParseWithFormat(time.RFC3339) // Atom
}
} }
return t, err return t, err
} }

View file

@ -30,7 +30,7 @@ func (f *testFetcher) Get(url string) (resp *http.Response, err error) {
} }
// A trivial test making sure that that all feeds parse - it *does not* check // A trivial test making sure that that all feeds parse - it *does not* check
// for correctness or completeness thereof. // for correctness or completeness thereof, except for dates.
func TestAllFeedsParse(t *testing.T) { func TestAllFeedsParse(t *testing.T) {
fileInfos, err := ioutil.ReadDir(testDataDir) fileInfos, err := ioutil.ReadDir(testDataDir)
if err != nil { if err != nil {
@ -41,8 +41,14 @@ func TestAllFeedsParse(t *testing.T) {
if !strings.HasSuffix(fileName, testFileSuffix) { if !strings.HasSuffix(fileName, testFileSuffix) {
continue continue
} }
if _, err := ReadWithClient(fileName, new(testFetcher)); err != nil { channel, err := ReadWithClient(fileName, new(testFetcher))
if err != nil {
t.Fatalf("ReadWithClient(%q) err = %v, expected nil", fileName, err) t.Fatalf("ReadWithClient(%q) err = %v, expected nil", fileName, err)
} }
for _, item := range channel.Item {
if _, err := item.PubDate.Parse(); err != nil {
t.Fatalf("Date Parser(%q) err = %v, expected nil", fileName, err)
}
}
} }
} }

3848
testdata/remoteok.io.rss vendored Normal file

File diff suppressed because one or more lines are too long