mirror of
https://github.com/bspeice/dtparse
synced 2024-12-22 04:18:09 -05:00
All tests are working!
This commit is contained in:
parent
5152ced2f1
commit
d55e67830f
21
src/lib.rs
21
src/lib.rs
@ -640,7 +640,7 @@ impl Parser {
|
|||||||
} else if let Some(value) = self.info.get_ampm(&l[i]) {
|
} else if let Some(value) = self.info.get_ampm(&l[i]) {
|
||||||
let is_ampm = self.ampm_valid(res.hour, res.ampm, fuzzy);
|
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.hour = res.hour.map(|h| self.adjust_ampm(h, value));
|
||||||
res.ampm = Some(value);
|
res.ampm = Some(value);
|
||||||
} else if fuzzy {
|
} else if fuzzy {
|
||||||
@ -750,25 +750,27 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn ampm_valid(&self, hour: Option<i32>, ampm: Option<bool>, fuzzy: bool) -> ParseResult<bool> {
|
fn ampm_valid(&self, hour: Option<i32>, ampm: Option<bool>, fuzzy: bool) -> ParseResult<bool> {
|
||||||
if fuzzy && ampm == Some(true) {
|
let mut val_is_ampm = true;
|
||||||
return Ok(false);
|
|
||||||
|
if fuzzy && ampm.is_some() {
|
||||||
|
val_is_ampm = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if hour.is_none() {
|
if hour.is_none() {
|
||||||
if fuzzy {
|
if fuzzy {
|
||||||
Ok(false)
|
val_is_ampm = false;
|
||||||
} else {
|
} else {
|
||||||
Err(ParseError::AmPmWithoutHour)
|
return Err(ParseError::AmPmWithoutHour);
|
||||||
}
|
}
|
||||||
} else if !(0 <= hour.unwrap() && hour.unwrap() <= 12) {
|
} else if !(0 <= hour.unwrap() && hour.unwrap() <= 12) {
|
||||||
if fuzzy {
|
if fuzzy {
|
||||||
Ok(false)
|
val_is_ampm = false;
|
||||||
} else {
|
} else {
|
||||||
Err(ParseError::InvalidHour)
|
return Err(ParseError::InvalidHour);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Ok(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(val_is_ampm)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_naive(&self, res: &ParsingResult, default: &NaiveDateTime) -> ParseResult<NaiveDateTime> {
|
fn build_naive(&self, res: &ParsingResult, default: &NaiveDateTime) -> ParseResult<NaiveDateTime> {
|
||||||
@ -1103,7 +1105,6 @@ impl Parser {
|
|||||||
|
|
||||||
fn recombine_skipped(&self, skipped_idxs: Vec<usize>, tokens: Vec<String>) -> Vec<String> {
|
fn recombine_skipped(&self, skipped_idxs: Vec<usize>, tokens: Vec<String>) -> Vec<String> {
|
||||||
let mut skipped_tokens: Vec<String> = vec![];
|
let mut skipped_tokens: Vec<String> = vec![];
|
||||||
println!("idxs: {:?}, tokens: {:?}", skipped_idxs, tokens);
|
|
||||||
|
|
||||||
let mut sorted_idxs = skipped_idxs.clone();
|
let mut sorted_idxs = skipped_idxs.clone();
|
||||||
sorted_idxs.sort();
|
sorted_idxs.sort();
|
||||||
|
Loading…
Reference in New Issue
Block a user