From 27e40c88128784c1619a34b0385cb9e7f78d90b4 Mon Sep 17 00:00:00 2001 From: Xander Gottlieb Date: Mon, 17 Aug 2020 13:05:56 +0200 Subject: [PATCH] support shortened RFC 822 dates --- lib/util/datetime.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/util/datetime.dart b/lib/util/datetime.dart index 8c79901..050d869 100644 --- a/lib/util/datetime.dart +++ b/lib/util/datetime.dart @@ -1,15 +1,18 @@ import 'package:intl/intl.dart'; -var rfc822DateFormat = DateFormat('EEE, dd MMM yyyy HH:mm:ss Z', 'en_US'); +const rfc822DatePattern = 'EEE, dd MMM yyyy HH:mm:ss Z'; DateTime parseDateTime(dateString) { if (dateString == null) return null; return _parseRfc822DateTime(dateString) ?? _parseIso8601DateTime(dateString); } -DateTime _parseRfc822DateTime(dateString) { +DateTime _parseRfc822DateTime(String dateString) { try { - return rfc822DateFormat.parse(dateString); + final length = dateString?.length?.clamp(0, rfc822DatePattern.length); + final trimmedPattern = rfc822DatePattern.substring(0, length); //Some feeds use a shortened RFC 822 date, e.g. 'Tue, 04 Aug 2020' + final format = DateFormat(trimmedPattern, 'en_US'); + return format.parse(dateString); } on FormatException { return null; }