瀏覽代碼

Merge pull request #22 from alexandergottlieb/master

parse RssItem.pubDate to DateTime
master
Wito Chandra 6 年之前
committed by GitHub
父節點
當前提交
3ed572a390
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: 4AEE18F83AFDEB23
共有 3 個檔案被更改,包括 14 行新增5 行删除
  1. +11
    -3
      lib/domain/rss_item.dart
  2. +1
    -0
      pubspec.yaml
  3. +2
    -2
      test/rss_test.dart

+ 11
- 3
lib/domain/rss_item.dart 查看文件

@@ -1,3 +1,4 @@
import 'package:intl/intl.dart';
import 'package:webfeed/domain/dublin_core/dublin_core.dart';
import 'package:webfeed/domain/media/media.dart';
import 'package:webfeed/domain/rss_category.dart';
@@ -16,7 +17,7 @@ class RssItem {

final List<RssCategory> categories;
final String guid;
final String pubDate;
final DateTime pubDate;
final String author;
final String comments;
final RssSource source;
@@ -32,7 +33,7 @@ class RssItem {
this.link,
this.categories,
this.guid,
this.pubDate,
String pubDate,
this.author,
this.comments,
this.source,
@@ -41,7 +42,8 @@ class RssItem {
this.enclosure,
this.dc,
this.itunes,
});
})
: this.pubDate = _parsePubDate(pubDate);

factory RssItem.parse(XmlElement element) {
return RssItem(
@@ -63,4 +65,10 @@ class RssItem {
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);
}
}

+ 1
- 0
pubspec.yaml 查看文件

@@ -7,6 +7,7 @@ environment:
sdk: ">=2.0.0 <3.0.0"
dependencies:
xml: "^3.0.0"
intl: "^0.16.0"
dev_dependencies:
test: ^1.3.0
http: "^0.11.3+16"

+ 2
- 2
test/rss_test.dart 查看文件

@@ -72,7 +72,7 @@ void main() {
"Lorem ipsum dolor sit amet, consectetur adipiscing elit");
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.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.value, "Lorem");
expect(feed.items.first.author, "alice@foo.bar.news");
@@ -102,7 +102,7 @@ void main() {
var item = feed.items.first;
expect(item.title, null);
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.credits.length, 2);


Loading…
取消
儲存