修复(计费): 北京本地时间换算校验当日时刻范围
beijing_local_micros 增加 time_of_day_micros 越界即返回 0 的校验,避免越界时刻被解释成另一天 Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
@@ -20,9 +20,13 @@ pub fn beijing_local_date_parts(micros: i64) -> (i32, u8, u8, i64) {
|
||||
(year, month, day, time_of_day_micros)
|
||||
}
|
||||
|
||||
/// 北京时间本地年月日 + 当日已过微秒 → UTC 微秒时间戳;本地日期不存在时返回 0。
|
||||
/// 北京时间本地年月日 + 当日已过微秒 → UTC 微秒时间戳;本地日期或当日时刻越界时返回 0。
|
||||
pub fn beijing_local_micros(year: i32, month: u8, day: u8, time_of_day_micros: i64) -> i64 {
|
||||
if !(1..=12).contains(&month) || day == 0 || day > days_in_month(year, month) {
|
||||
if !(1..=12).contains(&month)
|
||||
|| day == 0
|
||||
|| day > days_in_month(year, month)
|
||||
|| !(0..PROFILE_RUNTIME_DAY_MICROS).contains(&time_of_day_micros)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
days_from_civil(year, month, day)
|
||||
|
||||
Reference in New Issue
Block a user