Skip to content

Commit b6b00b9

Browse files
Optimize Hebrew and Julian calendars (#7213)
Aligns some Hebrew code with the other lunisolar calendars, and applies the Neri-Schneider optimisatios to the Julian calendar as well. I implemented new Hebrew code in `icu_calendar` as there we can keep it internal and iterate on it.
1 parent f3cff8c commit b6b00b9

File tree

23 files changed

+450
-647
lines changed

23 files changed

+450
-647
lines changed

components/calendar/src/cal/abstract_gregorian.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,14 @@ impl<Y: GregorianYears> DateFieldsResolver for AbstractGregorian<Y> {
6262
type YearInfo = i32;
6363

6464
fn days_in_provided_month(year: i32, month: u8) -> u8 {
65-
// https://www.youtube.com/watch?v=J9KijLyP-yg&t=1394s
6665
if month == 2 {
6766
28 + calendrical_calculations::gregorian::is_leap_year(year) as u8
6867
} else {
68+
// https://www.youtube.com/watch?v=J9KijLyP-yg&t=1394s
6969
30 | month ^ (month >> 3)
7070
}
7171
}
7272

73-
fn months_in_provided_year(_: i32) -> u8 {
74-
12
75-
}
76-
7773
#[inline]
7874
fn year_info_from_era(
7975
&self,

components/calendar/src/cal/coptic.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
use crate::calendar_arithmetic::ArithmeticDate;
66
use crate::calendar_arithmetic::DateFieldsResolver;
7-
use crate::error::{
8-
DateError, DateFromFieldsError, EcmaReferenceYearError, MonthCodeError, UnknownEraError,
9-
};
7+
use crate::error::{DateError, DateFromFieldsError, EcmaReferenceYearError, UnknownEraError};
108
use crate::options::DateFromFieldsOptions;
119
use crate::options::{DateAddOptions, DateDifferenceOptions};
1210
use crate::{types, Calendar, Date, RangeError};
@@ -56,22 +54,17 @@ impl DateFieldsResolver for Coptic {
5654
type YearInfo = i32;
5755

5856
fn days_in_provided_month(year: i32, month: u8) -> u8 {
59-
if (1..=12).contains(&month) {
60-
30
61-
} else if month == 13 {
62-
if year.rem_euclid(4) == 3 {
63-
6
64-
} else {
65-
5
66-
}
57+
if month == 13 {
58+
5 + calendrical_calculations::coptic::is_leap_year(year) as u8
6759
} else {
68-
0
60+
30
6961
}
7062
}
7163

7264
fn months_in_provided_year(_: i32) -> u8 {
7365
13
7466
}
67+
7568
#[inline]
7669
fn year_info_from_era(
7770
&self,
@@ -97,19 +90,6 @@ impl DateFieldsResolver for Coptic {
9790
) -> Result<Self::YearInfo, EcmaReferenceYearError> {
9891
Coptic::reference_year_from_month_day(month_code, day)
9992
}
100-
101-
#[inline]
102-
fn ordinal_month_from_code(
103-
&self,
104-
_year: &Self::YearInfo,
105-
month_code: types::ValidMonthCode,
106-
_options: DateFromFieldsOptions,
107-
) -> Result<u8, MonthCodeError> {
108-
match month_code.to_tuple() {
109-
(month_number @ 1..=13, false) => Ok(month_number),
110-
_ => Err(MonthCodeError::NotInCalendar),
111-
}
112-
}
11393
}
11494

11595
impl Coptic {

0 commit comments

Comments
 (0)