Skip to main content

calculate_day_offset

Function calculate_day_offset 

Source
pub fn calculate_day_offset(date: NaiveDate, reference_date: NaiveDate) -> i64
Expand description

Number of days between date and reference_date.

Positive means date is after the reference. Negative means before.

use shift_algorithm::calculate_day_offset;
use chrono::NaiveDate;

let ref_date = NaiveDate::from_ymd_opt(2025, 12, 15).unwrap();
let target = NaiveDate::from_ymd_opt(2025, 12, 20).unwrap();
assert_eq!(calculate_day_offset(target, ref_date), 5);
assert_eq!(calculate_day_offset(ref_date, target), -5);