5 unstable releases
0.4.0 | Dec 6, 2023 |
---|---|
0.3.2 | Dec 4, 2023 |
0.3.1 | Apr 27, 2023 |
0.3.0 | Apr 26, 2023 |
0.2.0 | Apr 4, 2023 |
#2034 in Parser implementations
Used in suchbar
40KB
958 lines
timewarp
NLP library for parsing English and German natural language into dates and times. Leverages pest for parsing human readable-dates and times. Tries to be as lenient as possible.
Examples:
Direct Input
To input a 2022-12-01
you can type: 12/1/22
, 01.12.22
, 22-12-01
.
Week
2022-W52
, 2022W52
, week 22-52
or KW 22/52
are interpreted as an
intervall 2022-12-26 <= x < 2023-01-02
.
Relative Dates
yesterday
, tomorrow
, etc. are calculated based of a given base.
+4 weeks
, -5 months
, next friday
, last thu
...
lib.rs
:
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))
);
Dependencies
~2–2.8MB
~56K SLoC