Fix pubdate parse error.

This commit is contained in:
stonegate 2020-10-03 16:57:11 +08:00
parent ec9836a432
commit 4aa53515e3
1 changed files with 12 additions and 5 deletions

View File

@ -473,17 +473,24 @@ class DBHelper {
try {
date = DateFormat('EEE, dd MMM yyyy HH:mm Z', 'en_US').parse(pubDate);
} catch (e) {
//parse date using regex, still have issue in parse maonth/day
var year = yyyy.stringMatch(pubDate);
var time = hhmm.stringMatch(pubDate);
var month = ddmmm.stringMatch(pubDate);
if (year != null && time != null && month != null) {
try {
date = DateFormat('dd MMM yyyy HH:mm', 'en_US')
.parse(month + year + time);
.parse('$month $year $time');
} catch (e) {
date = DateTime.now();
}
} else if (year != null && time != null && month == null) {
var month = mmDd.stringMatch(pubDate);
try {
date =
DateFormat('yyyy-MM-dd HH:mm', 'en_US').parse('$month $time');
} catch (e) {
date = DateTime.now();
}
} else {
date = DateTime.now();
}