#chrono #duration #elapsed #datetime #due


A simple extension of chrono. Answers questions like: how much time has elapsed since date y? How long until date x will be upon us?

16 releases (4 stable)

1.0.12 Jul 4, 2021
0.1.47 Jul 4, 2021

#167 in Date and time

50 downloads per month
Used in lib-todoist


383 lines



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.)


let dt_str = "1993-10-30T04:20:00Z";
let past_dt = dt_str
    .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)


~25K SLoC