Skip to content

Commit

Permalink
Correctly order earliest / latest for Ambiguous times in local TimeZone.
Browse files Browse the repository at this point in the history
Fix for #1625
  • Loading branch information
Arjan committed Nov 8, 2024
1 parent 868822e commit bfa4196
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/offset/local/tz_info/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl AlternateTime {
} else if local_time >= dst_end_transition_end
&& local_time <= dst_end_transition_start
{
Ok(crate::MappedLocalTime::Ambiguous(self.std, self.dst))
Ok(crate::MappedLocalTime::Ambiguous(self.dst, self.std))
} else {
Ok(crate::MappedLocalTime::Single(self.std))
}
Expand All @@ -284,7 +284,7 @@ impl AlternateTime {
} else if local_time >= dst_end_transition_end
&& local_time <= dst_end_transition_start
{
Ok(crate::MappedLocalTime::Ambiguous(self.std, self.dst))
Ok(crate::MappedLocalTime::Ambiguous(self.dst, self.std))
} else if local_time > dst_end_transition_end
&& local_time < dst_start_transition_start
{
Expand All @@ -309,7 +309,7 @@ impl AlternateTime {
} else if local_time >= dst_start_transition_end
&& local_time <= dst_start_transition_start
{
Ok(crate::MappedLocalTime::Ambiguous(self.dst, self.std))
Ok(crate::MappedLocalTime::Ambiguous(self.std, self.dst))

Check warning on line 312 in src/offset/local/tz_info/rule.rs

View check run for this annotation

Codecov / codecov/patch

src/offset/local/tz_info/rule.rs#L312

Added line #L312 was not covered by tests
} else if local_time > dst_start_transition_start
&& local_time < dst_end_transition_start
{
Expand Down Expand Up @@ -337,7 +337,7 @@ impl AlternateTime {
} else if local_time >= dst_start_transition_end
&& local_time <= dst_start_transition_start
{
Ok(crate::MappedLocalTime::Ambiguous(self.dst, self.std))
Ok(crate::MappedLocalTime::Ambiguous(self.std, self.dst))
} else {
Ok(crate::MappedLocalTime::Single(self.dst))
}
Expand Down
8 changes: 5 additions & 3 deletions src/offset/local/tz_info/timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl<'a> TimeZoneRef<'a> {
let local_leap_time = local_time;

// if we have at least one transition,
// we must check _all_ of them, incase of any Overlapping (MappedLocalTime::Ambiguous) or Skipping (MappedLocalTime::None) transitions
// we must check _all_ of them, in case of any Overlapping (MappedLocalTime::Ambiguous) or Skipping (MappedLocalTime::None) transitions
let offset_after_last = if !self.transitions.is_empty() {
let mut prev = self.local_time_types[0];

Expand All @@ -259,7 +259,8 @@ impl<'a> TimeZoneRef<'a> {
} else if local_leap_time >= transition_end
&& local_leap_time <= transition_start
{
if prev.ut_offset < after_ltt.ut_offset {
// Going from local to UTC a bigger offset means an earlier time.
if prev.ut_offset > after_ltt.ut_offset {
return Ok(crate::MappedLocalTime::Ambiguous(prev, after_ltt));
} else {
return Ok(crate::MappedLocalTime::Ambiguous(after_ltt, prev));
Expand All @@ -271,7 +272,8 @@ impl<'a> TimeZoneRef<'a> {
if local_leap_time < transition_start {
return Ok(crate::MappedLocalTime::Single(prev));
} else if local_leap_time == transition_end {
if prev.ut_offset < after_ltt.ut_offset {
// Going from local to UTC a bigger offset means an earlier time.
if prev.ut_offset > after_ltt.ut_offset {

Check warning on line 276 in src/offset/local/tz_info/timezone.rs

View check run for this annotation

Codecov / codecov/patch

src/offset/local/tz_info/timezone.rs#L276

Added line #L276 was not covered by tests
return Ok(crate::MappedLocalTime::Ambiguous(prev, after_ltt));
} else {
return Ok(crate::MappedLocalTime::Ambiguous(after_ltt, prev));
Expand Down

0 comments on commit bfa4196

Please sign in to comment.