| @@ -1,3 +1,4 @@ | |||||
| import 'package:intl/intl.dart'; | |||||
| import 'package:webfeed/domain/dublin_core/dublin_core.dart'; | import 'package:webfeed/domain/dublin_core/dublin_core.dart'; | ||||
| import 'package:webfeed/domain/media/media.dart'; | import 'package:webfeed/domain/media/media.dart'; | ||||
| import 'package:webfeed/domain/rss_category.dart'; | import 'package:webfeed/domain/rss_category.dart'; | ||||
| @@ -16,7 +17,7 @@ class RssItem { | |||||
| final List<RssCategory> categories; | final List<RssCategory> categories; | ||||
| final String guid; | final String guid; | ||||
| final String pubDate; | |||||
| final DateTime pubDate; | |||||
| final String author; | final String author; | ||||
| final String comments; | final String comments; | ||||
| final RssSource source; | final RssSource source; | ||||
| @@ -32,7 +33,7 @@ class RssItem { | |||||
| this.link, | this.link, | ||||
| this.categories, | this.categories, | ||||
| this.guid, | this.guid, | ||||
| this.pubDate, | |||||
| String pubDate, | |||||
| this.author, | this.author, | ||||
| this.comments, | this.comments, | ||||
| this.source, | this.source, | ||||
| @@ -41,7 +42,8 @@ class RssItem { | |||||
| this.enclosure, | this.enclosure, | ||||
| this.dc, | this.dc, | ||||
| this.itunes, | this.itunes, | ||||
| }); | |||||
| }) | |||||
| : this.pubDate = _parsePubDate(pubDate); | |||||
| factory RssItem.parse(XmlElement element) { | factory RssItem.parse(XmlElement element) { | ||||
| return RssItem( | return RssItem( | ||||
| @@ -63,4 +65,10 @@ class RssItem { | |||||
| itunes: RssItemItunes.parse(element), | itunes: RssItemItunes.parse(element), | ||||
| ); | ); | ||||
| } | } | ||||
| static _parsePubDate(pubDate) { | |||||
| if (pubDate == null) return null; | |||||
| //Locale for pubDate is always en_US, regardless of device locale | |||||
| return DateFormat('EEE, dd MMM yyyy HH:mm:ss Z', 'en_US').parse(pubDate); | |||||
| } | |||||
| } | } | ||||
| @@ -7,6 +7,7 @@ environment: | |||||
| sdk: ">=2.0.0 <3.0.0" | sdk: ">=2.0.0 <3.0.0" | ||||
| dependencies: | dependencies: | ||||
| xml: "^3.0.0" | xml: "^3.0.0" | ||||
| intl: "^0.16.0" | |||||
| dev_dependencies: | dev_dependencies: | ||||
| test: ^1.3.0 | test: ^1.3.0 | ||||
| http: "^0.11.3+16" | http: "^0.11.3+16" | ||||
| @@ -72,7 +72,7 @@ void main() { | |||||
| "Lorem ipsum dolor sit amet, consectetur adipiscing elit"); | "Lorem ipsum dolor sit amet, consectetur adipiscing elit"); | ||||
| expect(feed.items.first.link, "https://foo.bar.news/1"); | expect(feed.items.first.link, "https://foo.bar.news/1"); | ||||
| expect(feed.items.first.guid, "https://foo.bar.news/1?guid"); | expect(feed.items.first.guid, "https://foo.bar.news/1?guid"); | ||||
| expect(feed.items.first.pubDate, "Mon, 26 Mar 2018 14:00:00 PDT"); | |||||
| expect(feed.items.first.pubDate, DateTime(2018, 03, 26, 14)); //Mon, 26 Mar 2018 14:00:00 PDT | |||||
| expect(feed.items.first.categories.first.domain, "news"); | expect(feed.items.first.categories.first.domain, "news"); | ||||
| expect(feed.items.first.categories.first.value, "Lorem"); | expect(feed.items.first.categories.first.value, "Lorem"); | ||||
| expect(feed.items.first.author, "alice@foo.bar.news"); | expect(feed.items.first.author, "alice@foo.bar.news"); | ||||
| @@ -102,7 +102,7 @@ void main() { | |||||
| var item = feed.items.first; | var item = feed.items.first; | ||||
| expect(item.title, null); | expect(item.title, null); | ||||
| expect(item.link, "http://www.foo.com"); | expect(item.link, "http://www.foo.com"); | ||||
| expect(item.pubDate, "Mon, 27 Aug 2001 16:08:56 PST"); | |||||
| expect(item.pubDate, DateTime(2001, 08, 27, 16, 08, 56)); //Mon, 27 Aug 2001 16:08:56 PST | |||||
| expect(item.media.group.contents.length, 5); | expect(item.media.group.contents.length, 5); | ||||
| expect(item.media.group.credits.length, 2); | expect(item.media.group.credits.length, 2); | ||||