5 个不稳定版本
| 0.4.0 | 2023年12月6日 |
|---|---|
| 0.3.2 | 2023年12月4日 |
| 0.3.1 | 2023年4月27日 |
| 0.3.0 | 2023年4月26日 |
| 0.2.0 | 2023年4月4日 |
#1571 在 解析器实现
在 suchbar 中使用
40KB
958 行
timewarp
将英语和德语自然语言解析为日期和时间的 NLP 库。利用 pest 解析可读的日期和时间。尽可能宽松。
示例
直接输入
要输入 2022-12-01,你可以输入: 12/1/22, 01.12.22, 22-12-01。
周
2022-W52, 2022W52, week 22-52 或 KW 22/52 被解释为一个区间 2022-12-26 <= x < 2023-01-02。
相对日期
yesterday,tomorrow 等。基于给定基准计算。+4 weeks,-5 months,next friday,last thu...
lib.rs:
timewarp
将英语和德语自然语言解析为日期和时间的 NLP 库。利用 pest 解析可读的日期和时间。
应解析
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))
);
依赖关系
~2–2.8MB
~57K SLoC