Skip to content

Commit

Permalink
LibTimeZone: Handle time zones which begin the year in daylight savings
Browse files Browse the repository at this point in the history
  • Loading branch information
trflynn89 authored and linusg committed Jan 25, 2022
1 parent 7103012 commit 1f051a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,14 @@ static Offset get_active_dst_offset(TimeZoneOffset const& time_zone_offset, AK::
auto standard_time_in_effect = offsets[0]->time_in_effect(time);
auto daylight_time_in_effect = offsets[1]->time_in_effect(time);
if ((time < daylight_time_in_effect) || (time >= standard_time_in_effect))
return { offsets[0]->offset, InDST::No };
if (daylight_time_in_effect < standard_time_in_effect) {
if ((time < daylight_time_in_effect) || (time >= standard_time_in_effect))
return { offsets[0]->offset, InDST::No };
} else {
if ((time >= standard_time_in_effect) && (time < daylight_time_in_effect))
return { offsets[0]->offset, InDST::No };
}
return { offsets[1]->offset, InDST::Yes };
}
Expand Down
5 changes: 5 additions & 0 deletions Tests/LibTimeZone/TestTimeZone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ TEST_CASE(get_time_zone_offset_with_dst)
test_offset("Europe/Moscow"sv, -1596412800, offset(+1, 4, 31, 19), Yes); // Sunday, June 1, 1919 12:00:00 AM
test_offset("Europe/Moscow"sv, -1592611200, offset(+1, 4, 00, 00), Yes); // Tuesday, July 15, 1919 12:00:00 AM
test_offset("Europe/Moscow"sv, -1589068800, offset(+1, 3, 00, 00), No); // Monday, August 25, 1919 12:00:00 AM

// Paraguay begins the year in DST.
test_offset("America/Asuncion"sv, 1642558528, offset(-1, 3, 00, 00), Yes); // Wednesday, January 19, 2022 2:15:28 AM
test_offset("America/Asuncion"sv, 1663553728, offset(-1, 4, 00, 00), No); // Monday, September 19, 2022 2:15:28 AM
test_offset("America/Asuncion"sv, 1671453238, offset(-1, 3, 00, 00), Yes); // Monday, December 19, 2022 12:33:58 PM
}

TEST_CASE(get_named_time_zone_offsets)
Expand Down

0 comments on commit 1f051a8

Please sign in to comment.