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