You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Rust crate for parsing human-readable relative time strings and converting them to a `Duration`, or parsing human-readable datetime strings and converting them to a `DateTime`.
7
+
A Rust crate for parsing human-readable relative time strings and human-readable datetime strings and converting them to a `DateTime`.
8
8
9
9
## Features
10
10
@@ -23,23 +23,23 @@ Add this to your `Cargo.toml`:
23
23
parse_datetime = "0.4.0"
24
24
```
25
25
26
-
Then, import the crate and use the `from_str` and `from_str_at_date` functions:
26
+
Then, import the crate and use the `parse_datetime_at_date` function:
27
+
27
28
```rs
28
-
useparse_datetime::{from_str, from_str_at_date};
29
-
usechrono::Duration;
29
+
usechrono::{Duration, Local};
30
+
useparse_datetime::parse_datetime_at_date;
30
31
31
-
letduration=from_str("+3 days");
32
-
assert_eq!(duration.unwrap(), Duration::days(3));
32
+
letnow=Local::now();
33
+
letafter=parse_datetime_at_date(now, "+3 days");
33
34
34
-
lettoday=Utc::today().naive_utc();
35
-
letyesterday=today-Duration::days(1);
36
35
assert_eq!(
37
-
from_str_at_date(yesterday, "2 days").unwrap(),
38
-
Duration::days(1)
36
+
(now+Duration::days(3)).naive_utc(),
37
+
after.unwrap().naive_utc()
39
38
);
40
39
```
41
40
42
41
For DateTime parsing, import the `parse_datetime` module:
0 commit comments