diff --git a/src/lib.rs b/src/lib.rs index 0bfdfbc..5a54a75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -652,8 +652,7 @@ impl YMD { day = Some(self._ymd[1]); } } else if len_ymd == 3 { - // UNWRAP: 3 elements guarantees all indices are Some - if self.mstridx.unwrap() == 0 { + if self.mstridx == Some(0) { if self._ymd[1] > 31 { month = Some(self._ymd[0]); year = Some(self._ymd[1]); @@ -663,7 +662,7 @@ impl YMD { day = Some(self._ymd[1]); year = Some(self._ymd[2]); } - } else if self.mstridx.unwrap() == 1 { + } else if self.mstridx == Some(1) { if self._ymd[0] > 31 || (yearfirst && self._ymd[2] <= 31) { year = Some(self._ymd[0]); month = Some(self._ymd[1]); @@ -673,7 +672,7 @@ impl YMD { month = Some(self._ymd[1]); year = Some(self._ymd[2]); } - } else if self.mstridx.unwrap() == 2 { + } else if self.mstridx == Some(2) { // It was in the original docs, so: WTF!? if self._ymd[1] > 31 { day = Some(self._ymd[0]); @@ -766,7 +765,7 @@ impl Parser { if !ignoretz { let offset = self.build_tzaware(&naive, &res, default_ts); - Ok((naive, Some(offset.unwrap()), tokens)) + Ok((naive, offset.unwrap(), tokens)) } else { Ok((naive, None, tokens)) } @@ -995,10 +994,10 @@ impl Parser { dt: &NaiveDateTime, res: &ParsingResult, default: NaiveDateTime, - ) -> ParseResult { + ) -> ParseResult> { if res.tzname.is_none() && res.tzoffset.is_none() { - Ok(FixedOffset::east(0)) + Ok(None) } else { Err(ParseError::TimezoneUnsupported) } @@ -1124,6 +1123,8 @@ impl Parser { let hour = value.to_i64().unwrap() as i32; let ampm = info.get_ampm(&tokens[idx + 2]).unwrap(); res.hour = Some(self.adjust_ampm(hour, ampm)); + } else { + ymd.append(value.floor().to_i64().unwrap() as i32, None); } } else if info.get_ampm(&tokens[idx + 1]).is_some() && (*ZERO <= value && value < *TWENTY_FOUR) diff --git a/src/tests.rs b/src/tests.rs index 2e810ce..6b30935 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -38,7 +38,7 @@ fn test_split() { macro_rules! test_parse_naive { ($py: ident, $parser: ident, $s: expr) => { let dt: PyObject = $parser.call_method1("parse", $s).unwrap().extract().unwrap(); - let dt_s: String = dt.call_method0($py, "isoformat").unwrap().extract($py).unwrap(); + let dt_s: String = dt.call_method1($py, "isoformat", " ").unwrap().extract($py).unwrap(); let s = format!("{}", dt_s); println!("{}", s); @@ -61,5 +61,9 @@ fn test_parse() { let py = gil.python(); let parser = py.import("dateutil.parser").unwrap(); + test_parse_naive!(py, parser, "2018.5.15"); test_parse_naive!(py, parser, "May 5, 2018"); + test_parse_naive!(py, parser, "Mar. 5, 2018"); + test_parse_naive!(py, parser, "19990101T23"); + test_parse_naive!(py, parser, "19990101T2359"); } \ No newline at end of file