Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Dec 6, 2023
1 parent b2cd09c commit f34cc67
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions components/calendar/src/chinese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ mod test {
year: 4660,
month: 6,
day: 6,
// June 23 2023
expected: 738694,
},
TestCase {
Expand Down
5 changes: 3 additions & 2 deletions components/calendar/src/chinese_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ fn compute_cache<CB: ChineseBased>(extended_year: i32) -> ChineseBasedYearInfo {
new_year,
// TODO(#3933): switch ChineseBasedYearInfo to packed info so we don't need to store as bloaty u16s
last_day_of_month: last_day_of_month
.map(|rd| (rd.to_i64_date() - new_year.to_i64_date()) as u16),
// +1 since new_year is in the current month
.map(|rd| (rd.to_i64_date() - new_year.to_i64_date() + 1) as u16),
leap_month,
}
}
Expand Down Expand Up @@ -393,7 +394,7 @@ impl<C: ChineseBasedWithDataLoading + CalendarArithmetic<YearInfo = ChineseBased
/// Calculate the number of days in the year so far for a ChineseBasedDate;
/// similar to `CalendarArithmetic::day_of_year`
pub(crate) fn day_of_year(&self) -> u16 {
self.0.year_info.last_day_of_previous_month(self.0.month)
self.0.year_info.last_day_of_previous_month(self.0.month) + u16::from(self.0.day)
}
}

Expand Down
3 changes: 3 additions & 0 deletions utils/calendrical_calculations/src/chinese_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ pub fn month_structure_for_year<C: ChineseBased>(
current_month_major_solar_term = next_month_major_solar_term;
}

let first_month_diff = ret[0] - new_year + 1; // +1 since new_year is in the current month
debug_assert!(first_month_diff == 29 || first_month_diff == 30);

if ret[11] == ret[12] {
// not all months without solar terms are leap months; they are only leap months if
// the year can admit them
Expand Down

0 comments on commit f34cc67

Please sign in to comment.