finish human time parsing
This commit is contained in:
parent
1b34ab89af
commit
f0e6a2b47d
|
@ -207,7 +207,9 @@ mod tests {
|
|||
}
|
||||
|
||||
fn time_diff(t1: DateTime<Utc>, t2: DateTime<Local>) {
|
||||
assert!((t1 - Utc.from_utc_datetime(&t2.naive_utc())).num_seconds() < 1, "too different");
|
||||
let diff = (t1 - dbg!(Utc.from_utc_datetime(&dbg!(t2.naive_utc())))).num_seconds();
|
||||
|
||||
assert!(diff < 1, "too different: {} s", diff);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -242,5 +244,8 @@ mod tests {
|
|||
time_diff(parse_time("a m ago").unwrap(), Local::now() - Duration::minutes(1));
|
||||
time_diff(parse_time("an hr ago").unwrap(), Local::now() - Duration::hours(1));
|
||||
time_diff(parse_time("a min ago").unwrap(), Local::now() - Duration::minutes(1));
|
||||
time_diff(parse_time("two hours and fifteen minuts ago").unwrap(), Local::now() - Duration::minutes(2 * 60 + 15));
|
||||
time_diff(parse_time("two hours and thirty minuts ago").unwrap(), Local::now() - Duration::minutes(2 * 60 + 30));
|
||||
// time_diff(parse_time("two and a half hours ago").unwrap(), Local::now() - Duration::minutes(150));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ use std::collections::HashMap;
|
|||
use regex::Regex;
|
||||
|
||||
lazy_static! {
|
||||
// https://regex101.com/r/V9zYQu/1/
|
||||
pub static ref HUMAN_REGEX: Regex = Regex::new(r"(?xi)
|
||||
(?P<hour>
|
||||
(?P<hnum>
|
||||
|
@ -29,7 +30,7 @@ lazy_static! {
|
|||
)|
|
||||
(?P<mtextualnum>\d+)
|
||||
)
|
||||
(\s+)?m(in)?(ute)?s?
|
||||
(\s+)?m(in)?(ute?)?s?
|
||||
)?
|
||||
\s+ago
|
||||
").unwrap();
|
||||
|
|
Loading…
Reference in New Issue