From d55e67830f42c37916659b4a44f78631d217e350 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sun, 8 Jul 2018 21:51:02 -0400 Subject: [PATCH] All tests are working! --- src/lib.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 422b597..53bc165 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -640,7 +640,7 @@ impl Parser { } else if let Some(value) = self.info.get_ampm(&l[i]) { let is_ampm = self.ampm_valid(res.hour, res.ampm, fuzzy); - if is_ampm.is_ok() { + if is_ampm == Ok(true) { res.hour = res.hour.map(|h| self.adjust_ampm(h, value)); res.ampm = Some(value); } else if fuzzy { @@ -750,25 +750,27 @@ impl Parser { } fn ampm_valid(&self, hour: Option, ampm: Option, fuzzy: bool) -> ParseResult { - if fuzzy && ampm == Some(true) { - return Ok(false); + let mut val_is_ampm = true; + + if fuzzy && ampm.is_some() { + val_is_ampm = false; } if hour.is_none() { if fuzzy { - Ok(false) + val_is_ampm = false; } else { - Err(ParseError::AmPmWithoutHour) + return Err(ParseError::AmPmWithoutHour); } } else if !(0 <= hour.unwrap() && hour.unwrap() <= 12) { if fuzzy { - Ok(false) + val_is_ampm = false; } else { - Err(ParseError::InvalidHour) + return Err(ParseError::InvalidHour); } - } else { - Ok(false) } + + Ok(val_is_ampm) } fn build_naive(&self, res: &ParsingResult, default: &NaiveDateTime) -> ParseResult { @@ -1103,7 +1105,6 @@ impl Parser { fn recombine_skipped(&self, skipped_idxs: Vec, tokens: Vec) -> Vec { let mut skipped_tokens: Vec = vec![]; - println!("idxs: {:?}, tokens: {:?}", skipped_idxs, tokens); let mut sorted_idxs = skipped_idxs.clone(); sorted_idxs.sort();