Skip to content

Commit bab8df8

Browse files
committed
compare to chrono
1 parent 2b40e9b commit bab8df8

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/resb/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ potential_utf.workspace = true
3333
serde = { workspace = true, features = ["derive"] }
3434
icu.workspace = true
3535
chrono = "0.4"
36+
chrono-tz = "0.10"
3637

3738
[features]
3839
default = []

utils/resb/examples/time_zone_rule.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,12 +565,29 @@ fn main() {
565565
.nth(2)
566566
.unwrap_or_default()
567567
.parse()
568-
.unwrap_or(1000000000);
568+
.unwrap_or_default();
569569

570570
let (zone, region) = tzdb.get(&id).unwrap();
571-
572571
let transition = zone.previous_transition(seconds_since_epoch);
573572

573+
let chrono = chrono::offset::TimeZone::offset_from_utc_datetime(
574+
&<chrono_tz::Tz as core::str::FromStr>::from_str(&id).unwrap(),
575+
&chrono::DateTime::from_timestamp(seconds_since_epoch, 0)
576+
.unwrap()
577+
.naive_utc(),
578+
);
579+
580+
assert_eq!(
581+
transition.offset.to_seconds(),
582+
(chrono_tz::OffsetComponents::base_utc_offset(&chrono)
583+
+ chrono_tz::OffsetComponents::dst_offset(&chrono))
584+
.num_seconds() as i32
585+
);
586+
assert_eq!(
587+
transition.rule_applies,
588+
!chrono_tz::OffsetComponents::dst_offset(&chrono).is_zero()
589+
);
590+
574591
println!(
575592
"Zone {id:?} ({region}) at {time:?}: {offset:?} ({is_dst}) since {transition:?}",
576593
time = chrono::DateTime::from_timestamp(seconds_since_epoch, 0).unwrap(),

0 commit comments

Comments
 (0)