Skip to content

Commit 27cf04a

Browse files
committed
#151: Support for atom update date
1 parent 17abd35 commit 27cf04a

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"items": [
3+
{
4+
"updated": "Thu, 01 Jan 2004 19:48:21 GMT",
5+
"updatedParsed": "2004-01-01T19:48:21Z",
6+
"extensions": {
7+
"atom": {
8+
"updated": [
9+
{
10+
"name": "updated",
11+
"value": "",
12+
"parsed": {
13+
"updated": "Thu, 01 Jan 2004 19:48:21 GMT",
14+
"updatedParsed": "2004-01-01T19:48:21Z"
15+
}
16+
}
17+
]
18+
}
19+
}
20+
}
21+
],
22+
"feedType": "rss",
23+
"feedVersion": "2.0"
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!--
2+
Description: item updated (atom)
3+
-->
4+
<rss version="2.0" xmlns:a10="http://www.w3.org/2005/Atom">
5+
<channel>
6+
<item>
7+
<a10:updated>Thu, 01 Jan 2004 19:48:21 GMT</a10:updated>
8+
</item>
9+
</channel>
10+
</rss>

translator.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ func (t *DefaultRSSTranslator) translateFeedItem(rssItem *rss.Item) (item *Item)
6868
item.Link = t.translateItemLink(rssItem)
6969
item.Published = t.translateItemPublished(rssItem)
7070
item.PublishedParsed = t.translateItemPublishedParsed(rssItem)
71+
item.Updated = t.translateItemUpdated(rssItem)
72+
item.UpdatedParsed = t.translateItemUpdatedParsed(rssItem)
7173
item.Author = t.translateItemAuthor(rssItem)
7274
item.GUID = t.translateItemGUID(rssItem)
7375
item.Image = t.translateItemImage(rssItem)
@@ -280,18 +282,20 @@ func (t *DefaultRSSTranslator) translateItemLink(rssItem *rss.Item) (link string
280282
}
281283

282284
func (t *DefaultRSSTranslator) translateItemUpdated(rssItem *rss.Item) (updated string) {
283-
if rssItem.DublinCoreExt != nil && rssItem.DublinCoreExt.Date != nil {
285+
if updatedVal, ok := t.hasAtomExtensionsForKey(rssItem, "updated"); ok {
286+
updated = t.atomTranslator.translateItemUpdated(updatedVal)
287+
} else if rssItem.DublinCoreExt != nil && rssItem.DublinCoreExt.Date != nil {
284288
updated = t.firstEntry(rssItem.DublinCoreExt.Date)
285289
}
286290
return updated
287291
}
288292

289293
func (t *DefaultRSSTranslator) translateItemUpdatedParsed(rssItem *rss.Item) (updated *time.Time) {
290-
if rssItem.DublinCoreExt != nil && rssItem.DublinCoreExt.Date != nil {
291-
updatedText := t.firstEntry(rssItem.DublinCoreExt.Date)
294+
if updatedText := t.translateItemUpdated(rssItem); updatedText != "" {
292295
updatedDate, err := shared.ParseDate(updatedText)
293296
if err == nil {
294-
updated = &updatedDate
297+
utcDate := updatedDate.UTC()
298+
updated = &utcDate
295299
}
296300
}
297301
return

0 commit comments

Comments
 (0)