Skip to content

Commit

Permalink
saturate
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jan 4, 2024
1 parent 201b4b9 commit 1bc5496
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions utils/calendrical_calculations/src/hebrew_keviyah.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,17 @@ impl YearInfo {

let (yi, h_year) = match cmp {
// The approx year is a year greater. Go one year down
Ordering::Greater => (Self::compute_for(approx - 1), approx - 1),
Ordering::Greater => {
let prev = approx.saturating_sub(1);
(Self::compute_for(prev), prev)
}
// Bullseye
Ordering::Equal => (yi, approx),
// The approx year is a year lower. Go one year up.
Ordering::Less => (Self::compute_for(approx + 1), approx + 1),
Ordering::Less => {
let next = approx.saturating_add(1);
(Self::compute_for(next), next)
}
};

debug_assert!(yi.compare(date).is_eq() || maybe_approx.is_err(), // The data will be incorrect if we saturate, and that's expected
Expand Down

0 comments on commit 1bc5496

Please sign in to comment.