Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fancy new keviyah module for Hebrew calendrical calculations #4504

Merged
merged 24 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can you debug-assert that info is the correct info for year? That's an invariant of CalendarArithmetic that isn't being enforced in this constructor as far as I see.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. In the long term I want CalendarArithmetic's methods to always take ArithmeticDate (even though it means in some cases we'll need to make fake dates)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this isn't possible to do; CalendarArithmetic doesn't know anything about YearInfo.

}
}

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