Skip to content

Commit

Permalink
Use fancy new keviyah module for Hebrew calendrical calculations (#4504)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth authored Jan 5, 2024
1 parent 877d9d9 commit 1ae5bb3
Show file tree
Hide file tree
Showing 6 changed files with 670 additions and 269 deletions.
7 changes: 7 additions & 0 deletions components/calendar/benches/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ fn convert_benches(c: &mut Criterion) {
icu::calendar::gregorian::Gregorian,
);

#[cfg(feature = "bench")]
bench_calendar(
&mut group,
"calendar/hebrew",
icu::calendar::hebrew::Hebrew::new_always_calculating(),
);

#[cfg(feature = "bench")]
bench_calendar(
&mut group,
Expand Down
17 changes: 14 additions & 3 deletions components/calendar/src/calendar_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,22 +382,33 @@ impl<C: CalendarArithmetic> ArithmeticDate<C> {
where
C: CalendarArithmetic<YearInfo = ()>,
{
let max_month = C::months_for_every_year(year, ());
Self::new_from_ordinals_with_info(year, month, day, ())
}

/// Construct a new arithmetic date from a year, month ordinal, and day, bounds checking
/// the month and day
pub fn new_from_ordinals_with_info(
year: i32,
month: u8,
day: u8,
info: C::YearInfo,
) -> Result<Self, CalendarError> {
let max_month = C::months_for_every_year(year, info);
if month > max_month {
return Err(CalendarError::Overflow {
field: "month",
max: max_month as usize,
});
}
let max_day = C::month_days(year, month, ());
let max_day = C::month_days(year, month, info);
if day > max_day {
return Err(CalendarError::Overflow {
field: "day",
max: max_day as usize,
});
}

Ok(Self::new_unchecked(year, month, day))
Ok(Self::new_unchecked_with_info(year, month, day, info))
}
}

Expand Down
7 changes: 5 additions & 2 deletions components/calendar/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,11 @@ impl<A: AsCalendar> fmt::Debug for Date<A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(
f,
"Date({:?}, for calendar {})",
self.inner,
"Date({}-{}-{}, {} era, for calendar {})",
self.year().number,
self.month().ordinal,
self.day_of_month().0,
self.year().era.0,
self.calendar.as_calendar().debug_name()
)
}
Expand Down
Loading

0 comments on commit 1ae5bb3

Please sign in to comment.