Expand description
§timewarp
NLP library for parsing English and German natural language into dates and times. Leverages pest for parsing human readable-dates and times.
Should parse
use timewarp::Direction::*;
use timewarp::{date_matcher, Doy, Tempus};
// Fri 2023-03-17
let today = Doy::from_ymd(2023, 3, 17);
// Date as used in German (d.m.y)
assert_eq!(
date_matcher(today, From, "22.1.23").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 1, 22))
);
assert_eq!(
date_matcher(today, From, "22.1.").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 1, 22))
);
// Date as common for english-speaker m/d/y
assert_eq!(
date_matcher(today, From, "3/16/2023").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 3, 16))
);
// Date written in ISO
assert_eq!(
date_matcher(today, From, "2023-03-16").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 3, 16))
);
assert_eq!(
date_matcher(today, To, "last monday").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 3, 13))
);
assert_eq!(
date_matcher(today, From, "tuesday").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 3, 14))
);
assert_eq!(
date_matcher(today, To, "tuesday").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 3, 21))
);
assert_eq!(
date_matcher(today, From, "letzten donnerstag").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 3, 16))
);
assert_eq!(
date_matcher(today, To, "last friday").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 3, 10))
);
assert_eq!(
date_matcher(today, To, "nächsten Fr").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 3, 24))
);
assert_eq!(
date_matcher(today, To, "coming Thu").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 3, 23))
);
assert_eq!(
date_matcher(today, To, "übernächsten Donnerstag").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 3, 30))
);
assert_eq!(
date_matcher(today, To, "nächster Mo").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 3, 20))
);
assert_eq!(
date_matcher(today, To, "vorletzter mo").unwrap(),
Tempus::Moment(Doy::from_ymd(2023, 3, 6))
);
Structs§
- Doy
- Day Of Year. Helper-class to easily calculate dates.
Enums§
- DayOf
Week - Days of the week - as known by every english speaking child.
- Direction
- Designated use of the date.
- Month
- Names of months - shorted to 3-letter-identifier.
- Tempus
- A timespan in whole days.
- Time
Warp Error