From cc30d8ba7a779f4c441ea5bf7f3254976f610222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Sun, 4 Oct 2026 10:33:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3(=E4=BC=9A=E5=91=98=E8=B4=A6?= =?UTF-8?q?=E6=9C=9F)=EF=BC=9Abeijing=5Flocal=5Fmicros=20=E6=94=B9?= =?UTF-8?q?=E7=94=A8=20checked=20=E8=BF=90=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 年份导致微秒溢出时返回 None,符合函数文档,不再饱和成看似合法的值 - 补测试覆盖 i64 溢出年份返回 None --- .../crates/module-runtime/src/membership/cycle.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server-rs/crates/module-runtime/src/membership/cycle.rs b/server-rs/crates/module-runtime/src/membership/cycle.rs index 306f8afab..2b29f37e6 100644 --- a/server-rs/crates/module-runtime/src/membership/cycle.rs +++ b/server-rs/crates/module-runtime/src/membership/cycle.rs @@ -34,9 +34,9 @@ pub fn beijing_local_micros(year: i32, month: u8, day: u8, time_of_day_micros: i } Some( days_from_civil(year, month, day) - .saturating_mul(PROFILE_RUNTIME_DAY_MICROS) - .saturating_add(time_of_day_micros) - .saturating_sub(PROFILE_TASK_BEIJING_OFFSET_MICROS), + .checked_mul(PROFILE_RUNTIME_DAY_MICROS)? + .checked_add(time_of_day_micros)? + .checked_sub(PROFILE_TASK_BEIJING_OFFSET_MICROS)?, ) } @@ -119,6 +119,13 @@ mod tests { ); } + #[test] + fn beijing_local_micros_rejects_overflowing_year() { + // 中文注释:超出 i64 微秒范围的年份必须返回 None,而不是饱和成看似合法的值。 + assert_eq!(beijing_local_micros(1_000_000, 1, 1, 0), None); + assert_eq!(beijing_local_micros(-1_000_000, 1, 1, 0), None); + } + #[test] fn advance_months_clamps_to_month_end() { // 中文注释:1/31 开通 → 2/28(2026 非闰年)→ 3/31,每期都从原始锚点重算。