Merge pull request #16 from skypher/master

Support Atom dates in RSS.
This commit is contained in:
Erik Unger 2019-03-10 10:27:37 +01:00 committed by GitHub
commit eec8e4f8e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 3860 additions and 3 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