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

Fix year 2319 in the Chinese calendar #4929

Merged
merged 1 commit into from
May 22, 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
14 changes: 13 additions & 1 deletion components/calendar/src/chinese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ mod test {

use super::*;
use crate::types::MonthCode;
use calendrical_calculations::rata_die::RataDie;
use calendrical_calculations::{iso::fixed_from_iso, rata_die::RataDie};
/// Run a test twice, with two calendars
fn do_twice(
chinese_calculating: &Chinese,
Expand Down Expand Up @@ -503,6 +503,18 @@ mod test {
expected_month: 6,
expected_day: 12,
},
TestCase {
fixed: fixed_from_iso(2319, 2, 20).to_i64_date(),
expected_year: 2319 + 2636,
expected_month: 13,
expected_day: 30,
},
TestCase {
fixed: fixed_from_iso(2319, 2, 21).to_i64_date(),
expected_year: 2319 + 2636 + 1,
expected_month: 1,
expected_day: 1,
},
TestCase {
fixed: 738718,
expected_year: 4660,
Expand Down
5 changes: 3 additions & 2 deletions components/calendar/src/provider/chinese_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ impl<'data> ChineseBasedCacheV1<'data> {
/// Bit: 0 1 2 3 4 5 6 7
/// Byte 0: [ month lengths .............
/// Byte 1: .. month lengths ] | [ leap month index ..
/// Byte 2: ] | [ NY offset ] | unused
/// Byte 2: ] | [ NY offset ] | unused
/// ```
///
/// Where the New Year Offset is the offset from ISO Jan 21 of that year for Chinese New Year,
/// the month lengths are stored as 1 = 30, 0 = 29 for each month including the leap month.
/// The largest possible offset is 33, which requires 6 bits of storage.
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
Expand Down Expand Up @@ -162,7 +163,7 @@ impl PackedChineseBasedYearInfo {
!month_lengths[12] || leap_month_idx.is_some(),
"Last month length should not be set for non-leap years"
);
debug_assert!(ny_offset < 32, "Year offset too big to store");
debug_assert!(ny_offset < 33, "Year offset too big to store");
debug_assert!(
leap_month_idx.map(|l| l.get() <= 13).unwrap_or(true),
"Leap month indices must be 1 <= i <= 13"
Expand Down
Loading