Skip to content

Commit

Permalink
Replace TimeDelta::days with try_days
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Mar 6, 2024
1 parent 383fcff commit 073c3c3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/naive/date/mod.rs
Expand Up @@ -1140,7 +1140,10 @@ impl NaiveDate {
let (year2_div_400, year2_mod_400) = div_mod_floor(year2, 400);
let cycle1 = yo_to_cycle(year1_mod_400 as u32, self.ordinal()) as i64;
let cycle2 = yo_to_cycle(year2_mod_400 as u32, rhs.ordinal()) as i64;
TimeDelta::days((year1_div_400 as i64 - year2_div_400 as i64) * 146_097 + (cycle1 - cycle2))
let days = (year1_div_400 as i64 - year2_div_400 as i64) * 146_097 + (cycle1 - cycle2);
// The range of `TimeDelta` is ca. 585 million years, the range of `NaiveDate` ca. 525.000
// years.
expect!(TimeDelta::try_days(days), "always in range")
}

/// Returns the number of whole years from the given `base` until `self`.
Expand Down

0 comments on commit 073c3c3

Please sign in to comment.