Best practices for date arithmetic in Rust 2018?

Hello everyone
what is the current best practices for doing date arithmetic in Rust ?
For example, I want to subtract two dates and get the number of days between them?
Here is what I have done and it appears to work but I would like opinions if this is idiomatic Rust and in line with best practices because I am new to Rust. Below I used chrono crate https://docs.rs/chrono/0.4.11/chrono/

let mut dt = Utc.ymd(2014, 7, 1);
let mut prev_dt = Utc.ymd(2000, 12, 1);
// different in Days is:
dt.signed_duration_since(prev_dt).num_days();

Thank you in advance!

Unless you want to calculate the Julian date yourself, either the time or chrono crate would suffice, as you mentioned. I see nothing wrong with how you've handled things.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.