Skip to content

Commit 24422f5

Browse files
authored
Stop depending on is_dst for calculations (#356)
Makes it so that our timezone calculations don't depend on the `is_dst` field to calculate if a datetime is within a forward transition. I think this is a breaking change, but because the timezone providers are unstable, it should be fine.
1 parent 11bddce commit 24422f5

File tree

4 files changed

+69
-113
lines changed

4 files changed

+69
-113
lines changed

src/builtins/core/timezone.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::builtins::core::duration::DateDuration;
1111
use crate::parsers::{
1212
parse_allowed_timezone_formats, parse_identifier, FormattableOffset, FormattableTime, Precision,
1313
};
14-
use crate::provider::{TimeZoneOffset, TimeZoneProvider};
14+
use crate::provider::{TimeZoneProvider, TimeZoneTransitionInfo};
1515
use crate::{
1616
builtins::core::{duration::normalized::NormalizedTimeDuration, Instant},
1717
iso::{IsoDate, IsoDateTime, IsoTime},
@@ -177,7 +177,7 @@ impl TimeZone {
177177
// 3. Return GetNamedTimeZoneOffsetNanoseconds(parseResult.[[Name]], epochNs).
178178
Self::IanaIdentifier(identifier) => provider
179179
.get_named_tz_offset_nanoseconds(identifier, utc_epoch)
180-
.map(|offset| i128::from(offset.offset) * 1_000_000_000),
180+
.map(|transition| i128::from(transition.offset.0) * 1_000_000_000),
181181
}
182182
}
183183

@@ -428,7 +428,7 @@ impl TimeZone {
428428
.with_message("Could not determine the start of day for the provided date."));
429429
};
430430

431-
let TimeZoneOffset {
431+
let TimeZoneTransitionInfo {
432432
transition_epoch: Some(transition_epoch),
433433
..
434434
} = provider.get_named_tz_offset_nanoseconds(identifier, after_epoch.0)?

src/parsers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'a> IxdtfStringBuilder<'a> {
9191
}
9292
}
9393

94-
impl<'a> Writeable for IxdtfStringBuilder<'a> {
94+
impl Writeable for IxdtfStringBuilder<'_> {
9595
fn write_to<W: core::fmt::Write + ?Sized>(&self, sink: &mut W) -> core::fmt::Result {
9696
self.inner.write_to(sink)
9797
}

src/provider.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ use core::str::FromStr;
55
use crate::{iso::IsoDateTime, unix_time::EpochNanoseconds, TemporalResult};
66
use alloc::vec::Vec;
77

8-
/// `TimeZoneOffset` represents the number of seconds to be added to UT in order to determine local time.
8+
/// `UtcOffsetSeconds` represents the amount of seconds we need to add to the UTC to reach the local time.
99
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10-
pub struct TimeZoneOffset {
10+
pub struct UtcOffsetSeconds(pub i64);
11+
12+
/// `TimeZoneTransitionInfo` represents information about a timezone transition.
13+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14+
pub struct TimeZoneTransitionInfo {
1115
/// The transition time epoch at which the offset needs to be applied.
1216
pub transition_epoch: Option<i64>,
1317
/// The time zone offset in seconds.
14-
pub offset: i64,
18+
pub offset: UtcOffsetSeconds,
1519
}
1620

1721
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -67,7 +71,7 @@ pub trait TimeZoneProvider {
6771
&self,
6872
identifier: &str,
6973
epoch_nanoseconds: i128,
70-
) -> TemporalResult<TimeZoneOffset>;
74+
) -> TemporalResult<TimeZoneTransitionInfo>;
7175

7276
// TODO: implement and stabalize
7377
fn get_named_tz_transition(
@@ -93,7 +97,11 @@ impl TimeZoneProvider for NeverProvider {
9397
unimplemented!()
9498
}
9599

96-
fn get_named_tz_offset_nanoseconds(&self, _: &str, _: i128) -> TemporalResult<TimeZoneOffset> {
100+
fn get_named_tz_offset_nanoseconds(
101+
&self,
102+
_: &str,
103+
_: i128,
104+
) -> TemporalResult<TimeZoneTransitionInfo> {
97105
unimplemented!()
98106
}
99107

0 commit comments

Comments
 (0)