duration_between

Function duration_between 

Source
pub fn duration_between(
    date1: SystemTime,
    date2: SystemTime,
    unit: DurationUnit,
) -> u64
Expand description

Returns the absolute difference between two dates in the specified unit.

The calculation is based on approximations for months and years.

§Arguments

  • date1 - The first date.
  • date2 - The second date.
  • unit - The unit of time for the returned difference.

§Returns

  • u64 - The absolute difference between the two dates in the specified unit.

§Examples

use std::time::{SystemTime, Duration};
use lowdash::{duration_between, DurationUnit};

let epoch = SystemTime::UNIX_EPOCH;
let one_year = Duration::from_secs(31_557_600);
let later = epoch + one_year;
// Difference in years
assert_eq!(duration_between(epoch, later, DurationUnit::Years), 1);

let one_day = Duration::from_secs(86_400);
let day_later = epoch + one_day;
// Difference in days
assert_eq!(duration_between(epoch, day_later, DurationUnit::Days), 1);