use chrono::{DateTime, Utc};
pub(crate) fn days_until(when: DateTime<Utc>, now: DateTime<Utc>) -> i64 {
let days = (when - now).num_days();
if days == 0 && when < now {
-1
} else {
days
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn past_instants_are_negative_without_overstating_age() {
let now: DateTime<Utc> = "2026-01-10T12:00:00Z".parse().unwrap();
let h = chrono::Duration::hours;
assert_eq!(days_until(now - chrono::Duration::seconds(1), now), -1);
assert_eq!(days_until(now - h(5), now), -1);
assert_eq!(days_until(now - h(24), now), -1);
assert_eq!(days_until(now - h(25), now), -1);
assert_eq!(days_until(now - h(49), now), -2);
assert_eq!(days_until(now, now), 0);
assert_eq!(days_until(now + h(5), now), 0);
assert_eq!(days_until(now + h(24), now), 1);
assert_eq!(days_until(now + h(71), now), 2);
}
}