From e9c3405eea8cb52c67490ee73e5f2bdc9a19a4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reto=20Habl=C3=BCtzel?= Date: Wed, 17 Jun 2020 12:32:11 +0200 Subject: [PATCH] parse datetime with space between date and time --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index f289a68..85af7e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,6 +76,7 @@ pub fn parse_date(string: &str) -> Option> { None.or_else(|| rfc3339(trimmed)) .or_else(|| cut(trimmed, 20).and_then(rfc3339)) .or_else(|| cut(trimmed, 19).map(|s| suffix(s, "Z")).and_then(rfc3339)) + .or_else(|| DateTime::parse_from_str(trimmed, "%Y-%m-%d %H:%M:%S%.3f %z").ok()) .or_else(|| { cut(trimmed, 16) .map(|s| suffix(s, ":00Z")) @@ -175,6 +176,11 @@ mod test { Some(Utc.ymd(2014, 1, 11).and_hms(0, 0, 0).into()) ); + assert_eq!( + parse_date("2014-01-11 01:18:21 +0000"), + Some(Utc.ymd(2014, 01, 11).and_hms(1, 18, 21).into()) + ); + assert_eq!( parse_date("Fri, 12 Feb 2016 14:08:24 +0000"), Some(Utc.ymd(2016, 2, 12).and_hms(14, 8, 24).into())