5 releases (3 breaking)

0.4.0 Sep 18, 2021
0.3.0 Jul 7, 2021
0.2.1 Jul 12, 2020
0.2.0 Jul 5, 2020
0.1.0 Jul 4, 2020

#43 in Date and time

Download history 37/week @ 2021-07-02 108/week @ 2021-07-09 58/week @ 2021-07-16 19/week @ 2021-07-23 30/week @ 2021-07-30 14/week @ 2021-08-06 71/week @ 2021-08-13 13/week @ 2021-08-20 25/week @ 2021-08-27 14/week @ 2021-09-03 23/week @ 2021-09-10 48/week @ 2021-09-17 49/week @ 2021-09-24 99/week @ 2021-10-01 19/week @ 2021-10-08 12/week @ 2021-10-15

144 downloads per month
Used in rtw

MIT/Apache

31KB
660 lines

htp crate tbl documentation GitHub license

HTP

Work in progress Human Time Parser

This lib uses pest for parsing.

Example

use chrono::{Utc, TimeZone};
use htp::parse;
let now = Utc.datetime_from_str("2020-12-24T23:45:00", "%Y-%m-%dT%H:%M:%S").unwrap();
let expected = Utc.datetime_from_str("2020-12-18T19:43:00", "%Y-%m-%dT%H:%M:%S").unwrap();
let datetime = parse("last friday at 19:43", now).unwrap();
assert_eq!(datetime, expected);

Similar Crate

Why?

Tweak how time is parsed and interpreted inside my rust time tracking tool.

It's fun to write parsers once in while, pest is really nice.

What date format can it parse?

see time_clue grammar rule.

some examples:

  • 4 min ago, 4 h ago, 1 week ago, in 2 hours, in 1 month
  • last friday at 19, monday at 6 am
  • 7, 7am, 7pm, 7:30, 19:43:00
  • now, yesterday, today, friday
  • 2020-12-25T19:43:00

It also supports interestingly-spaced inputs such as:

4           min      ago

It is possible to try HTP out using cargo run --example time_parser:

example

cargo run --example time_parser last friday at 6

output

2020-07-03T06:00:00+02:00

Thanks to pest it also provides meaningful errors:

example

cargo run --example time_parser last friday at

output

 --> 1:15
  |
1 | last friday at
  |               ^---
  |
  = expected hms

Changelog

Please see the CHANGELOG for a release history.

Dependencies

~2–2.7MB
~54K SLoC

vFa