From a08bb2d9d740e941fc5034e0004837219d617c7e Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Thu, 11 Jun 2020 12:49:55 -0400 Subject: [PATCH] Add fixes for dateutil/dateutil#822 --- build_pycompat.py | 2 +- src/lib.rs | 6 ++++-- src/tests/pycompat_parser.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/build_pycompat.py b/build_pycompat.py index 7f26438..8886d21 100755 --- a/build_pycompat.py +++ b/build_pycompat.py @@ -81,7 +81,7 @@ tests = { 'Thu Sep 25 10:36:28 BRST 2003', '1996.07.10 AD at 15:08:56 PDT', 'Tuesday, April 12, 1952 AD 3:30:42pm PST', 'November 5, 1994, 8:15:30 am EST', '1994-11-05T08:15:30-05:00', - '1994-11-05T08:15:30Z', '1976-07-04T00:01:02Z', + '1994-11-05T08:15:30Z', '1976-07-04T00:01:02Z', '1986-07-05T08:15:30z', 'Tue Apr 4 00:22:12 PDT 1995' ], 'test_fuzzy_tzinfo': [ diff --git a/src/lib.rs b/src/lib.rs index 1289b78..0092f33 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -347,7 +347,9 @@ impl ParserInfo { res.year = Some(self.convertyear(y, res.century_specified)) }; - if res.tzoffset == Some(0) && res.tzname.is_none() || res.tzname == Some("Z".to_owned()) { + if (res.tzoffset == Some(0) && res.tzname.is_none()) + || (res.tzname == Some("Z".to_owned()) || res.tzname == Some("z".to_owned())) + { res.tzname = Some("UTC".to_owned()); res.tzoffset = Some(0); } else if res.tzoffset != Some(0) @@ -885,7 +887,7 @@ impl Parser { && tzname.is_none() && tzoffset.is_none() && token.len() <= 5 - && all_ascii_upper + && (all_ascii_upper || self.info.utczone.contains_key(token)) } #[allow(clippy::unnecessary_unwrap)] diff --git a/src/tests/pycompat_parser.rs b/src/tests/pycompat_parser.rs index 6ad4066..444eb53 100644 --- a/src/tests/pycompat_parser.rs +++ b/src/tests/pycompat_parser.rs @@ -3348,6 +3348,33 @@ fn test_parse_ignoretz6() { #[test] fn test_parse_ignoretz7() { + let info = ParserInfo::default(); + let pdt = PyDateTime { + year: 1986, + month: 7, + day: 5, + hour: 8, + minute: 15, + second: 30, + micros: 0, + tzo: None, + }; + parse_and_assert( + pdt, + info, + "1986-07-05T08:15:30z", + None, + None, + false, + false, + None, + true, + &HashMap::new(), + ); +} + +#[test] +fn test_parse_ignoretz8() { let info = ParserInfo::default(); let pdt = PyDateTime { year: 1995,