forked from kamat/tauclock
fix: preserve legacy DST gap scheduling (#8)
This commit is contained in:
@@ -68,8 +68,9 @@ cargo tauri build
|
||||
### 日付時刻ライブラリと依存監査
|
||||
|
||||
日時処理は、RUSTSEC-2026-0543で保守停止が告知されたChronoではなくJiff 1.xを使用します。
|
||||
日常のローカル時刻、UTC表示、アラームの暦日計算はJiffが担当します。夏時間の重複時刻は
|
||||
早い方、存在しない時刻は後の有効な時刻へ解決します。保存済みアラームJSONの形式は変更しません。
|
||||
日常のローカル時刻、UTC表示、アラームの暦日計算はJiffが担当します。互換性維持のため、
|
||||
夏時間の重複時刻は早い方を選び、存在しない時刻は従来どおりcivil timeをUTCとして解釈する
|
||||
fallbackを使います。保存済みアラームJSONの形式は変更しません。
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
@@ -79,7 +80,8 @@ cargo audit --deny warnings
|
||||
|
||||
Tauriが利用するcrateの非有効なoptional dependencyとして、`Cargo.lock`にChronoが残る場合があります。
|
||||
`cargo tree`でactive dependencyではないことを確認してください。`cargo audit`はlockfile単位で検査するため、
|
||||
この非有効なentryもRUSTSEC-2026-0543として報告します。
|
||||
この非有効なentryもRUSTSEC-2026-0543として報告します。Tauri/Linux GUI由来のその他の
|
||||
warning-class advisoryは [Issue #9](https://git.rumginger.org/kamat/tauclock/issues/9) で追跡します。
|
||||
|
||||
## ライセンス
|
||||
|
||||
|
||||
+45
-17
@@ -1,4 +1,7 @@
|
||||
use jiff::{tz::TimeZone, Timestamp, ZonedDateTime};
|
||||
use jiff::{
|
||||
tz::{AmbiguousOffset, TimeZone},
|
||||
Timestamp, ZonedDateTime,
|
||||
};
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
@@ -878,28 +881,45 @@ fn now_in_time_zone(time_zone: &TimeZone) -> ZonedDateTime {
|
||||
Timestamp::now().to_zoned_datetime(time_zone.clone())
|
||||
}
|
||||
|
||||
/// Calculates the next trigger timestamp in milliseconds for an alarm. Jiff's
|
||||
/// compatible resolution chooses the earlier instant in a fold and the later
|
||||
/// valid wall time in a gap.
|
||||
/// Calculates the next trigger timestamp in milliseconds for an alarm while
|
||||
/// preserving the legacy local-time ambiguity policy. A fold selects the
|
||||
/// earlier occurrence. A gap interprets the nonexistent civil time as UTC
|
||||
/// before converting it back to the local zone.
|
||||
fn resolve_next_trigger(hour: u8, minute: u8, now_local: &ZonedDateTime) -> i64 {
|
||||
let time_zone = now_local.time_zone().clone();
|
||||
let mut candidate = now_local
|
||||
.date()
|
||||
.at(hour as i8, minute as i8, 0, 0)
|
||||
.to_zoned_datetime(time_zone.clone())
|
||||
.expect("alarm date is representable");
|
||||
let mut candidate = combine_local(now_local.date(), hour, minute, &time_zone);
|
||||
if candidate.timestamp().as_millisecond() <= now_local.timestamp().as_millisecond() {
|
||||
candidate = now_local
|
||||
candidate = combine_local(
|
||||
now_local
|
||||
.date()
|
||||
.tomorrow()
|
||||
.expect("tomorrow is representable")
|
||||
.at(hour as i8, minute as i8, 0, 0)
|
||||
.to_zoned_datetime(time_zone)
|
||||
.expect("next alarm date is representable");
|
||||
.expect("tomorrow is representable"),
|
||||
hour,
|
||||
minute,
|
||||
&time_zone,
|
||||
);
|
||||
}
|
||||
candidate.timestamp().as_millisecond()
|
||||
}
|
||||
|
||||
fn combine_local(
|
||||
date: jiff::civil::Date,
|
||||
hour: u8,
|
||||
minute: u8,
|
||||
time_zone: &TimeZone,
|
||||
) -> ZonedDateTime {
|
||||
let civil = date.at(hour as i8, minute as i8, 0, 0);
|
||||
let ambiguous = time_zone.to_ambiguous_zoned_datetime(civil);
|
||||
if matches!(ambiguous.offset(), AmbiguousOffset::Gap { .. }) {
|
||||
return civil
|
||||
.to_zoned_datetime(TimeZone::UTC)
|
||||
.expect("alarm date is representable in UTC")
|
||||
.timestamp()
|
||||
.to_zoned_datetime(time_zone.clone());
|
||||
}
|
||||
ambiguous.compatible().expect("alarm date is representable")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -962,12 +982,20 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_york_gap_uses_jiff_compatible_later_time() {
|
||||
fn new_york_gap_preserves_the_legacy_utc_fallback() {
|
||||
let new_york = named_zone("America/New_York");
|
||||
let now = zoned("2024-03-10T00:00:00Z", new_york);
|
||||
let gap_date: jiff::civil::Date = "2024-03-10".parse().expect("valid date");
|
||||
assert_eq!(
|
||||
combine_local(gap_date, 2, 30, &new_york)
|
||||
.timestamp()
|
||||
.as_millisecond(),
|
||||
milliseconds("2024-03-10T02:30:00Z")
|
||||
);
|
||||
|
||||
let now = zoned("2024-03-10T05:00:00Z", new_york);
|
||||
assert_eq!(
|
||||
resolve_next_trigger(2, 30, &now),
|
||||
milliseconds("2024-03-10T07:30:00Z")
|
||||
milliseconds("2024-03-11T06:30:00Z")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user