Support Atom dates in RSS feeds.
Some generators seem to get this wrong; act gracefully.
This commit is contained in:
parent
e6dab863fc
commit
307868a646
3 changed files with 3859 additions and 2 deletions
3
rss.go
3
rss.go
|
@ -59,6 +59,9 @@ func (d Date) Parse() (time.Time, error) {
|
|||
t, err := d.ParseWithFormat(wordpressDateFormat)
|
||||
if err != nil {
|
||||
t, err = d.ParseWithFormat(time.RFC822) // RSS 2.0 spec
|
||||
if err != nil {
|
||||
t, err = d.ParseWithFormat(time.RFC3339) // Atom
|
||||
}
|
||||
}
|
||||
return t, err
|
||||
}
|
||||
|
|
10
rss_test.go
10
rss_test.go
|
@ -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
|
||||
// for correctness or completeness thereof.
|
||||
// for correctness or completeness thereof, except for dates.
|
||||
func TestAllFeedsParse(t *testing.T) {
|
||||
fileInfos, err := ioutil.ReadDir(testDataDir)
|
||||
if err != nil {
|
||||
|
@ -41,8 +41,14 @@ func TestAllFeedsParse(t *testing.T) {
|
|||
if !strings.HasSuffix(fileName, testFileSuffix) {
|
||||
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)
|
||||
}
|
||||
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
3848
testdata/remoteok.io.rss
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue