diff --git a/testdata/translator/rss/feed_item_updated_-_rss_channel_item_updated_atom.json b/testdata/translator/rss/feed_item_updated_-_rss_channel_item_updated_atom.json new file mode 100644 index 00000000..256bea65 --- /dev/null +++ b/testdata/translator/rss/feed_item_updated_-_rss_channel_item_updated_atom.json @@ -0,0 +1,24 @@ +{ + "items": [ + { + "updated": "Thu, 01 Jan 2004 19:48:21 GMT", + "updatedParsed": "2004-01-01T19:48:21Z", + "extensions": { + "atom": { + "updated": [ + { + "name": "updated", + "value": "", + "parsed": { + "updated": "Thu, 01 Jan 2004 19:48:21 GMT", + "updatedParsed": "2004-01-01T19:48:21Z" + } + } + ] + } + } + } + ], + "feedType": "rss", + "feedVersion": "2.0" +} diff --git a/testdata/translator/rss/feed_item_updated_-_rss_channel_item_updated_atom.xml b/testdata/translator/rss/feed_item_updated_-_rss_channel_item_updated_atom.xml new file mode 100644 index 00000000..8706e4d6 --- /dev/null +++ b/testdata/translator/rss/feed_item_updated_-_rss_channel_item_updated_atom.xml @@ -0,0 +1,10 @@ + + + + + Thu, 01 Jan 2004 19:48:21 GMT + + + diff --git a/translator.go b/translator.go index 11fcd66f..9e5d16f3 100644 --- a/translator.go +++ b/translator.go @@ -71,6 +71,8 @@ func (t *DefaultRSSTranslator) translateFeedItem(rssItem *rss.Item) (item *Item) item.Links = t.translateItemLinks(rssItem) item.Published = t.translateItemPublished(rssItem) item.PublishedParsed = t.translateItemPublishedParsed(rssItem) + item.Updated = t.translateItemUpdated(rssItem) + item.UpdatedParsed = t.translateItemUpdatedParsed(rssItem) item.Author = t.translateItemAuthor(rssItem) item.Authors = t.translateItemAuthors(rssItem) item.GUID = t.translateItemGUID(rssItem) @@ -316,18 +318,20 @@ func (t *DefaultRSSTranslator) translateItemLinks(rssItem *rss.Item) (links []st } func (t *DefaultRSSTranslator) translateItemUpdated(rssItem *rss.Item) (updated string) { - if rssItem.DublinCoreExt != nil && rssItem.DublinCoreExt.Date != nil { + if updatedVal, ok := t.hasAtomExtensionsForKey(rssItem, "updated"); ok { + updated = t.atomTranslator.translateItemUpdated(updatedVal) + } else if rssItem.DublinCoreExt != nil && rssItem.DublinCoreExt.Date != nil { updated = t.firstEntry(rssItem.DublinCoreExt.Date) } return updated } func (t *DefaultRSSTranslator) translateItemUpdatedParsed(rssItem *rss.Item) (updated *time.Time) { - if rssItem.DublinCoreExt != nil && rssItem.DublinCoreExt.Date != nil { - updatedText := t.firstEntry(rssItem.DublinCoreExt.Date) + if updatedText := t.translateItemUpdated(rssItem); updatedText != "" { updatedDate, err := shared.ParseDate(updatedText) if err == nil { - updated = &updatedDate + utcDate := updatedDate.UTC() + updated = &utcDate } } return