16 releases (4 stable)
1.0.12 | Jul 4, 2021 |
---|---|
0.1.47 | Jul 4, 2021 |
#261 in Date and time
43 downloads per month
Used in lib-todoist
24KB
383 lines
chrono_elapsed
https://crates.io/crates/chrono_elapsed.
An extension of chrono to assist in reporting on due dates. I wrote this because I'm building a CLI in Rust and I chose to bring Todoist to the terminal since I primarily use it for my todo's, and wanted to integrate it more closely with my dev workflow.
Personally, I'm only using this for dates that are in the near future, or have very recently passed, so it doesn't currently accurately handle oddities in the calendar, such as February. A lot of assumptions are being made, so fair warning if you're interested in a crate for getting accurate data regarding time elapsed between two dates, this is not for you (yet... I hope.)
Example
let dt_str = "1993-10-30T04:20:00Z";
let past_dt = dt_str
.parse::<DateTime<Local>>()
.expect("failed to parse str as `DateTime<Local>`");
let elapsed = Elapsed::new(past_dt);
println!("{}", elapsed);
Would print: 30y 1m
. Wildly inaccurate, but you get the idea. Becomes more
accurate when the date is closer to now. A closer datetime that had just passed
would print something like 4min 46sec
, e.g.
let now = Local::now();
let recent_dt = now - Duration::minutes(20);
let elapsed = Elapsed::new(recent_dt);
println!("{}", elapsed)
Dependencies
~1.3–1.8MB
~26K SLoC