Skip to content

Commit a038329

Browse files
authored
Update zoneinfo64 (#552)
1 parent 1bda856 commit a038329

File tree

7 files changed

+35
-37
lines changed

7 files changed

+35
-37
lines changed

Cargo.lock

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jiff-tzdb = "0.1.4"
4848
combine = "4.6.7"
4949
web-time = "1.1.0"
5050
zerovec = "0.11.4"
51-
zoneinfo64 = "0.1.0"
51+
zoneinfo64 = "0.2.0"
5252

5353
[package]
5454
name = "temporal_rs"

provider/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ include = [
1717
]
1818

1919
[features]
20+
# Allow people to use default-features = false
21+
default = []
2022
datagen = [
2123
"std",
2224
"dep:serde",

provider/src/zoneinfo64.rs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@ use crate::{
1111
epoch_nanoseconds::{seconds_to_nanoseconds, EpochNanoseconds, NS_IN_S},
1212
TimeZoneProviderError,
1313
};
14-
use icu_time::zone::UtcOffset;
14+
use zoneinfo64::UtcOffset;
1515

1616
impl From<UtcOffset> for UtcOffsetSeconds {
1717
fn from(other: UtcOffset) -> Self {
18-
Self(i64::from(other.to_seconds()))
18+
Self(i64::from(other.seconds()))
1919
}
2020
}
2121

22+
pub use zoneinfo64::ZONEINFO64_RES_FOR_TESTING;
23+
2224
/// A TimeZoneProvider that works using ICU4C zoneinfo64.res data
2325
pub type ZoneInfo64TzdbProvider<'a> = NormalizerAndResolver<CompiledNormalizer, ZoneInfo64<'a>>;
2426

27+
impl ZoneInfo64TzdbProvider<'_> {
28+
/// Produces a zoneinfo64 provider using the builtin zoneinfo64 data,
29+
/// for testing use only. We do not provide strong guarantees for which version of zoneinfo64
30+
/// this will be.
31+
pub fn zoneinfo64_provider_for_testing() -> Option<Self> {
32+
let zi_data = zoneinfo64::ZoneInfo64::try_from_u32s(ZONEINFO64_RES_FOR_TESTING).ok()?;
33+
Some(ZoneInfo64TzdbProvider::new(zi_data))
34+
}
35+
}
36+
2537
fn get<'a>(zi: &'a ZoneInfo64<'a>, id: ResolvedId) -> TimeZoneProviderResult<Zone<'a>> {
2638
let id = u16::try_from(id.0)
2739
.map_err(|_| TimeZoneProviderError::Range("Unknown timezone identifier"))?;
@@ -55,53 +67,40 @@ impl TimeZoneResolver for ZoneInfo64<'_> {
5567
local_datetime.second,
5668
);
5769

58-
const FIVE_DAYS_NANOS: i128 = 5 * 24 * 60 * 60 * 1_000_000_000;
5970
let result = match possible_offset {
60-
// TODO(Manishearth) This is wrong. It mostly works: we do not have any transitions with gaps that last
61-
// longer than 5 days, and for the purpose of calculating an offset when you are that far away from a transition
62-
// treating local datetime as epoch time works fine.
63-
// Can be fixed once we have https://github.com/unicode-org/icu4x/pull/6913
64-
PossibleOffset::None => CandidateEpochNanoseconds::Zero(GapEntryOffsets {
65-
offset_before: self.transition_nanoseconds_for_utc_epoch_nanoseconds(
66-
identifier,
67-
epoch_nanos.0 - FIVE_DAYS_NANOS,
68-
)?,
69-
offset_after: self.transition_nanoseconds_for_utc_epoch_nanoseconds(
70-
identifier,
71-
epoch_nanos.0 + FIVE_DAYS_NANOS,
72-
)?,
73-
transition_epoch: self
74-
.get_time_zone_transition(
75-
identifier,
76-
epoch_nanos.0 - FIVE_DAYS_NANOS,
77-
TransitionDirection::Next,
78-
)?
79-
.unwrap_or_default(),
71+
PossibleOffset::None {
72+
before,
73+
after,
74+
transition,
75+
} => CandidateEpochNanoseconds::Zero(GapEntryOffsets {
76+
offset_before: before.offset.into(),
77+
offset_after: after.offset.into(),
78+
transition_epoch: EpochNanoseconds::from(seconds_to_nanoseconds(transition)),
8079
}),
8180
PossibleOffset::Single(o) => {
8281
let epoch_ns = EpochNanoseconds::from(
83-
epoch_nanos.0 - seconds_to_nanoseconds(i64::from(o.offset.to_seconds())),
82+
epoch_nanos.0 - seconds_to_nanoseconds(i64::from(o.offset.seconds())),
8483
);
8584
CandidateEpochNanoseconds::One(EpochNanosecondsAndOffset {
8685
ns: epoch_ns,
8786
offset: o.offset.into(),
8887
})
8988
}
90-
PossibleOffset::Ambiguous(first, second) => {
89+
PossibleOffset::Ambiguous { before, after, .. } => {
9190
let first_epoch_ns = EpochNanoseconds::from(
92-
epoch_nanos.0 - seconds_to_nanoseconds(i64::from(first.offset.to_seconds())),
91+
epoch_nanos.0 - seconds_to_nanoseconds(i64::from(before.offset.seconds())),
9392
);
9493
let second_epoch_ns = EpochNanoseconds::from(
95-
epoch_nanos.0 - seconds_to_nanoseconds(i64::from(second.offset.to_seconds())),
94+
epoch_nanos.0 - seconds_to_nanoseconds(i64::from(after.offset.seconds())),
9695
);
9796
CandidateEpochNanoseconds::Two([
9897
EpochNanosecondsAndOffset {
9998
ns: first_epoch_ns,
100-
offset: first.offset.into(),
99+
offset: before.offset.into(),
101100
},
102101
EpochNanosecondsAndOffset {
103102
ns: second_epoch_ns,
104-
offset: second.offset.into(),
103+
offset: after.offset.into(),
105104
},
106105
])
107106
}

src/builtins/core/zoneddatetime/tests.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ use crate::{
1212
};
1313
use alloc::string::ToString;
1414
use core::str::FromStr;
15+
use timezone_provider::zoneinfo64::ZONEINFO64_RES_FOR_TESTING;
1516
use tinystr::tinystr;
1617

17-
pub const ZONEINFO64_RES_FOR_TESTING: &[u32] =
18-
resb::include_bytes_as_u32!("../../../../tests/data/zoneinfo64.res");
19-
2018
macro_rules! test_all_providers {
2119
($(#[cfg_for_fs($cfg_fs:meta)])? $(#[cfg_for_zi64($cfg_zi:meta)])? $provider:ident: $b:block) => {{
2220
#[cfg(feature = "compiled_data")]

temporal_capi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ icu_calendar = { version = "2.0.2", default-features = false }
2727
icu_locale = { version = "2.0.0" }
2828
writeable = "0.6.1"
2929
yoke = { version = "0.8.0", optional = true }
30-
zoneinfo64 = { workspace = true, optional = true, default-features = false }
30+
zoneinfo64 = { workspace = true, optional = true }
3131

3232
[features]
3333
compiled_data = ["temporal_rs/compiled_data"]

tests/data/zoneinfo64.res

-145 KB
Binary file not shown.

0 commit comments

Comments
 (0)