From 8b8213f0c8b6a9e90d11c677da463f7b63b6b367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Fri, 2 Oct 2026 19:12:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D(=E8=AE=A1=E8=B4=B9):=20?= =?UTF-8?q?=E5=85=AC=E5=8E=86=E5=8F=8D=E7=AE=97=E9=81=BF=E5=85=8D=20i64=20?= =?UTF-8?q?=E6=BA=A2=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit civil_from_days 用 saturating_add 计算日序号偏移,消除 date_key 接近 i64::MAX 时的加法溢出 Co-authored-by: Junie --- server-rs/crates/module-runtime/src/civil_calendar.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server-rs/crates/module-runtime/src/civil_calendar.rs b/server-rs/crates/module-runtime/src/civil_calendar.rs index bc6cec172..036bf1a2d 100644 --- a/server-rs/crates/module-runtime/src/civil_calendar.rs +++ b/server-rs/crates/module-runtime/src/civil_calendar.rs @@ -36,7 +36,7 @@ pub fn days_from_civil(year: i32, month: u8, day: u8) -> i64 { /// 1970-01-01 起的日序号 → 公历年月日。 pub fn civil_from_days(date_key: i64) -> (i32, u8, u8) { // 中文注释:days_from_civil 的反向算法,避免依赖运行环境时区。 - let z = date_key + 719_468; + let z = date_key.saturating_add(719_468); let era = z.div_euclid(146_097); let day_of_era = z - era * 146_097; let year_of_era = (day_of_era - day_of_era / 1_460 + day_of_era / 36_524