Fix interval parsing for different cases
This commit is contained in:
@ -150,7 +150,7 @@ impl<'a> Parser<'a> {
|
||||
"hours" | "hour" | "hr" | "hrs" | "h" => (0, 0, n.mul(3600)?, 0),
|
||||
"days" | "day" | "d" => (0, n, 0, 0),
|
||||
"weeks" | "week" | "w" => (0, n.mul(7)?, 0, 0),
|
||||
"months" | "month" | "M" => (n, 0, 0, 0),
|
||||
"months" | "month" => (n, 0, 0, 0),
|
||||
"years" | "year" | "y" => (n.mul(12)?, 0, 0, 0),
|
||||
_ => {
|
||||
return Err(Error::UnknownUnit {
|
||||
@ -255,7 +255,7 @@ impl<'a> Parser<'a> {
|
||||
/// assert_eq!(parse_duration("32ms"), Ok(Duration::new(0, 32_000_000)));
|
||||
/// ```
|
||||
pub fn parse_duration(s: &str) -> Result<Interval, Error> {
|
||||
Parser { iter: s.chars(), src: s, current: (0, 0, 0, 0) }.parse()
|
||||
Parser { iter: s.to_lowercase().chars(), src: &s.to_lowercase(), current: (0, 0, 0, 0) }.parse()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -324,4 +324,13 @@ mod tests {
|
||||
assert_eq!(interval.day, 0);
|
||||
assert_eq!(interval.month, 120);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_case() {
|
||||
let interval = parse_duration("200 Seconds").unwrap();
|
||||
|
||||
assert_eq!(interval.sec, 200);
|
||||
assert_eq!(interval.day, 0);
|
||||
assert_eq!(interval.month, 0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user