Add ability to specify durations with years

This commit is contained in:
Tobie Morgan Hitchcock 2022-07-20 10:35:42 +01:00
parent 0b38fab723
commit 5c0a0ca556

View file

@ -223,6 +223,7 @@ fn duration_raw(i: &str) -> IResult<&str, Duration> {
"h" => time::Duration::new(v * 60 * 60, 0),
"d" => time::Duration::new(v * 60 * 60 * 24, 0),
"w" => time::Duration::new(v * 60 * 60 * 24 * 7, 0),
"y" => time::Duration::new(v * 60 * 60 * 24 * 365, 0),
_ => time::Duration::new(0, 0),
}),
))
@ -234,7 +235,17 @@ fn part(i: &str) -> IResult<&str, u64> {
}
fn unit(i: &str) -> IResult<&str, &str> {
alt((tag("ns"), tag("µs"), tag("ms"), tag("s"), tag("m"), tag("h"), tag("d"), tag("w")))(i)
alt((
tag("ns"),
tag("µs"),
tag("ms"),
tag("s"),
tag("m"),
tag("h"),
tag("d"),
tag("w"),
tag("y"),
))(i)
}
#[cfg(test)]