style: 自动格式化

This commit is contained in:
2026-10-16 06:42:50 +00:00
parent d878af4b9c
commit 3220c5fffc
3 changed files with 52 additions and 55 deletions
+34 -34
View File
@@ -156,14 +156,11 @@ impl Keviyah {
let is_leap = self.is_leap(); let is_leap = self.is_leap();
// 闰年中 Adar 之后的序月对应上一个月号。 // 闰年中 Adar 之后的序月对应上一个月号。
let month_number = ordinal_month - (is_leap && ordinal_month >= 6) as u8; let month_number = ordinal_month - (is_leap && ordinal_month >= 6) as u8;
29 29 + (month_number % 2
+ (
month_number % 2
// Heshvan 在全年型为长月 // Heshvan 在全年型为长月
+ (ordinal_month == 2 && year_type == YearType::Complete) as u8 + (ordinal_month == 2 && year_type == YearType::Complete) as u8
// Kislev 在缺年型为短月 // Kislev 在缺年型为短月
- (ordinal_month == 3 && year_type == YearType::Deficient) as u8 - (ordinal_month == 3 && year_type == YearType::Deficient) as u8)
)
} }
/// 第 ordinal_month 个序月之前的累计天数。 /// 第 ordinal_month 个序月之前的累计天数。
@@ -172,15 +169,13 @@ impl Keviyah {
let is_leap = self.is_leap(); let is_leap = self.is_leap();
let month_number = ordinal_month - (is_leap && ordinal_month > 6) as u8; let month_number = ordinal_month - (is_leap && ordinal_month > 6) as u8;
29 * (ordinal_month as u16 - 1) 29 * (ordinal_month as u16 - 1)
+ ( + (month_number / 2
month_number / 2
// Adar I 为长月 // Adar I 为长月
+ (is_leap && ordinal_month > 6) as u8 + (is_leap && ordinal_month > 6) as u8
// Heshvan 在全年型为长月 // Heshvan 在全年型为长月
+ (ordinal_month > 2 && year_type == YearType::Complete) as u8 + (ordinal_month > 2 && year_type == YearType::Complete) as u8
// Kislev 在缺年型为短月 // Kislev 在缺年型为短月
- (ordinal_month > 3 && year_type == YearType::Deficient) as u8 - (ordinal_month > 3 && year_type == YearType::Deficient) as u8) as u16
) as u16
} }
/// 年内第 day_of_year 天(1 起)折算为(序月, 月内日)。 /// 年内第 day_of_year 天(1 起)折算为(序月, 月内日)。
@@ -288,19 +283,15 @@ impl YearInfo {
if in_week >= hal(7, 18, 0) { if in_week >= hal(7, 18, 0) {
weeks_since_beharad += 1; weeks_since_beharad += 1;
} }
Self { Self { keviyah, weeks_since_beharad }
keviyah,
weeks_since_beharad,
}
} }
/// 新年首日(Tishrei 1)的 ISO 纪元日。 /// 新年首日(Tishrei 1)的 ISO 纪元日。
fn new_year(self) -> i128 { fn new_year(self) -> i128 {
// Beharad 周从周一开始。 // Beharad 周从周一开始。
const BEHARAD_START_OF_YEAR: i128 = StartOfYear::Monday as i128; const BEHARAD_START_OF_YEAR: i128 = StartOfYear::Monday as i128;
let days_since_beharad = self.weeks_since_beharad * 7 let days_since_beharad =
+ self.keviyah.start_of_year() as i128 self.weeks_since_beharad * 7 + self.keviyah.start_of_year() as i128 - BEHARAD_START_OF_YEAR;
- BEHARAD_START_OF_YEAR;
HEBREW_EPOCH_DAYS + days_since_beharad HEBREW_EPOCH_DAYS + days_since_beharad
} }
@@ -347,9 +338,7 @@ pub(crate) const HEBREW_ERA: &str = "am";
/// hebrew 日期(年, 序月, 日)→ ISO 纪元日。 /// hebrew 日期(年, 序月, 日)→ ISO 纪元日。
pub(crate) fn hebrew_to_iso_days(h_year: i128, ordinal_month: u32, day: u32) -> i128 { pub(crate) fn hebrew_to_iso_days(h_year: i128, ordinal_month: u32, day: u32) -> i128 {
let year_info = YearInfo::compute_for(h_year); let year_info = YearInfo::compute_for(h_year);
year_info.new_year() year_info.new_year() + year_info.keviyah.days_preceding(ordinal_month as u8) as i128 + (day - 1) as i128
+ year_info.keviyah.days_preceding(ordinal_month as u8) as i128
+ (day - 1) as i128
} }
/// ISO 纪元日 → hebrew 日期(年, 序月, 日)。 /// ISO 纪元日 → hebrew 日期(年, 序月, 日)。
@@ -368,11 +357,7 @@ pub(crate) fn hebrew_to_iso(h_year: i128, ordinal_month: u32, day: u32) -> (i32,
/// ISO 日期分量 → hebrew 日期(年, 序月, 日)。 /// ISO 日期分量 → hebrew 日期(年, 序月, 日)。
pub(crate) fn iso_to_hebrew(iso_year: i32, iso_month: u32, iso_day: u32) -> (i128, u32, u32) { pub(crate) fn iso_to_hebrew(iso_year: i32, iso_month: u32, iso_day: u32) -> (i128, u32, u32) {
iso_days_to_hebrew(days_from_civil( iso_days_to_hebrew(days_from_civil(i128::from(iso_year), i128::from(iso_month), i128::from(iso_day)))
i128::from(iso_year),
i128::from(iso_month),
i128::from(iso_day),
))
} }
/// 数值月(平年 1-12、闰年 1-13)→ 序月:hebrew 数值月即序月(闰年 Adar I 为 6、 /// 数值月(平年 1-12、闰年 1-13)→ 序月:hebrew 数值月即序月(闰年 Adar I 为 6、
@@ -455,10 +440,7 @@ mod tests {
fn test_year_lengths_valid() { fn test_year_lengths_valid() {
for year in 3700..=5800 { for year in 3700..=5800 {
let len = hebrew_year_length(year); let len = hebrew_year_length(year);
assert!( assert!(matches!(len, 353 | 354 | 355 | 383 | 384 | 385), "year {year} -> {len}");
matches!(len, 353 | 354 | 355 | 383 | 384 | 385),
"year {year} -> {len}"
);
} }
} }
@@ -528,12 +510,30 @@ mod tests {
fn test_icu4x_vectors() { fn test_icu4x_vectors() {
let cases: [Vector4x; 6] = [ let cases: [Vector4x; 6] = [
// iso 为公历年月日,heb 为希伯来年与序数月与日 // iso 为公历年月日,heb 为希伯来年与序数月与日
Vector4x { iso: (2021, 1, 10), heb: (5781, 4, 26) }, Vector4x {
Vector4x { iso: (2021, 9, 10), heb: (5782, 1, 4) }, iso: (2021, 1, 10),
Vector4x { iso: (2022, 2, 10), heb: (5782, 6, 9) }, // Adar I(闰年) heb: (5781, 4, 26),
Vector4x { iso: (2022, 3, 10), heb: (5782, 7, 7) }, // Adar II(闰年) },
Vector4x { iso: (2022, 10, 10), heb: (5783, 1, 15) }, Vector4x {
Vector4x { iso: (2022, 12, 25), heb: (5783, 4, 1) }, iso: (2021, 9, 10),
heb: (5782, 1, 4),
},
Vector4x {
iso: (2022, 2, 10),
heb: (5782, 6, 9),
}, // Adar I(闰年)
Vector4x {
iso: (2022, 3, 10),
heb: (5782, 7, 7),
}, // Adar II(闰年)
Vector4x {
iso: (2022, 10, 10),
heb: (5783, 1, 15),
},
Vector4x {
iso: (2022, 12, 25),
heb: (5783, 4, 1),
},
]; ];
for v in cases { for v in cases {
let (iy, im, id) = v.iso; let (iy, im, id) = v.iso;
@@ -6,9 +6,9 @@ use oxide_types::object::JsObject;
use oxide_types::value::JsValue; use oxide_types::value::JsValue;
use super::calendar::{ use super::calendar::{
hebrew_days_in_month, hebrew_is_leap, hebrew_month_code, hebrew_months_in_year, hebrew_days_in_month, hebrew_is_leap, hebrew_month_code, hebrew_months_in_year, hebrew_number_from_ordinal,
hebrew_number_from_ordinal, hebrew_ordinal_from_month_code, hebrew_ordinal_from_number, hebrew_to_iso, hebrew_ordinal_from_month_code, hebrew_ordinal_from_number, hebrew_to_iso, hebrew_year_length, iso_to_hebrew,
hebrew_year_length, iso_to_hebrew, HEBREW_ERA, HEBREW_ERA,
}; };
use super::common::native_try; use super::common::native_try;
use super::common::{ use super::common::{
@@ -257,9 +257,7 @@ fn plain_date_ymd<H: VmHost>(vm: &mut H, args: &[u8]) -> Result<(f64, f64, f64),
/// 读 PlainDate 的 ISO 分量(槽 0-2)与日历 ID(槽 3),含 receiver 校验。 /// 读 PlainDate 的 ISO 分量(槽 0-2)与日历 ID(槽 3),含 receiver 校验。
/// getter 按日历 ID 分发:hebrew 换算为历法字段,其余历法直返 ISO 分量。 /// getter 按日历 ID 分发:hebrew 换算为历法字段,其余历法直返 ISO 分量。
fn plain_date_iso_ymd_calendar<H: VmHost>( fn plain_date_iso_ymd_calendar<H: VmHost>(vm: &mut H, args: &[u8]) -> Result<(i32, u32, u32, String), JsValue> {
vm: &mut H, args: &[u8],
) -> Result<(i32, u32, u32, String), JsValue> {
let ptr = receiver_obj(vm, args)?; let ptr = receiver_obj(vm, args)?;
let obj = unsafe { &*ptr }; let obj = unsafe { &*ptr };
ensure_plain_date(vm, obj)?; ensure_plain_date(vm, obj)?;
@@ -429,9 +427,7 @@ fn hebrew_object_date_ymd<H: VmHost>(
let era_present = !era_raw.is_undefined(); let era_present = !era_raw.is_undefined();
let era_year_present = !era_year_raw.is_undefined(); let era_year_present = !era_year_raw.is_undefined();
if era_present != era_year_present { if era_present != era_year_present {
return Err(crate::error::create_type_error( return Err(crate::error::create_type_error(vm, "era and eraYear must both be present or both absent"));
vm, "era and eraYear must both be present or both absent",
));
} }
let hebrew_year = if era_year_present { let hebrew_year = if era_year_present {
let era = temporal_option_string(vm, era_raw)?; let era = temporal_option_string(vm, era_raw)?;
@@ -359,7 +359,8 @@ pub fn plain_year_month_from<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult
if calendar == "hebrew" { if calendar == "hebrew" {
if era_present != era_year_present { if era_present != era_year_present {
return NativeResult::Err(crate::error::create_type_error( return NativeResult::Err(crate::error::create_type_error(
vm, "era and eraYear must both be present or both absent", vm,
"era and eraYear must both be present or both absent",
)); ));
} }
if era_present { if era_present {