pub fn date_time_diff<DT: DateTimeParts>(from: DT, to: DT) -> DateTimeDiffResultExpand description
Calculate the difference between two date-time values in years, months, days, hours, minutes, seconds and nanoseconds.
The result is positive when to is later than from, and negative when to is earlier than from.
If the two values are in different time zones, to is converted to the time zone of from first.
Then the result is calculated with the wall-clock date and time in that time zone.
ยงExample
use chrono::prelude::*;
use date_differencer::{DateTimeDiffResult, date_time_diff};
let date = Local.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap();
let date_after_1_year_1_day_5_minutes =
Local.with_ymd_and_hms(2001, 1, 2, 0, 5, 0).unwrap();
assert_eq!(
DateTimeDiffResult {
years: 1,
days: 1,
minutes: 5,
..DateTimeDiffResult::default()
},
date_time_diff(date, date_after_1_year_1_day_5_minutes)
);