Reputation: 334
I am currently working on a simple RSS reader. For retrieving items from RSS feeds, I use SimplePie. Upon retrieval, items are stored in a database with title, link and date. Users are presented with a list of items from the feeds they are subscribed to, newest first.
Some RSS feeds do not have a valid date for each item, or simply provide no date at all. For example, Three Word Phrase's feed has dates like Thurs, 11 Oct 2012
, which are invalid (causing SimplePie to return null). Nerd Rage's feed doesn't even provide a date-related element.
Since feed items are displayed newest-first they need a valid date associated with them. When such a date is not provided, however, I wouldn't know how to handle that. There is no catch-all way to fix invalid dates, and I can't fabricate a date out of thin air either.
Upvotes: 0
Views: 1091
Reputation: 334
A possible solution is to give dateless items the timestamp of their retrieval. Depending on how often you refresh the feeds, this can give a fairly accurate timestamp.
Though this works fine for feeds who have already had their items retrieved once, new feeds behave less elegantly. The first time a dateless feed is loaded, it will get all its items and assign them all the same timestamp, causing them to crowd the top of the "newest first" item list, since they likely have the most recent timestamp.
To remedy this, use an old (0 works fine) timestamp for a feed's items when you first retrieve items for that feed. When encountering new items for that feed on subsequent refreshes, give them the timestamp of retrieval. This way, loading in a new dateless feed will not push all its items to the top, but as they appear, newer items for that feed will get fairly accurate dates.
To summarize, for dateless items/feeds:
When getting items from a feed for the first time: timestamp = 0
When getting items from a feed subsequent times: timestamp = current
Upvotes: 0