diff options
Diffstat (limited to 'Tests/LibTimeZone/TestTimeZone.cpp')
-rw-r--r-- | Tests/LibTimeZone/TestTimeZone.cpp | 79 |
1 files changed, 41 insertions, 38 deletions
diff --git a/Tests/LibTimeZone/TestTimeZone.cpp b/Tests/LibTimeZone/TestTimeZone.cpp index 19cfa5fc42..d86aa6166f 100644 --- a/Tests/LibTimeZone/TestTimeZone.cpp +++ b/Tests/LibTimeZone/TestTimeZone.cpp @@ -10,6 +10,8 @@ #include <AK/Time.h> #include <LibTimeZone/TimeZone.h> +using enum TimeZone::InDST; + #if ENABLE_TIME_ZONE_DATA # include <LibTimeZone/TimeZoneData.h> @@ -90,60 +92,61 @@ static i64 offset(i64 sign, i64 hours, i64 minutes, i64 seconds) return sign * ((hours * 3600) + (minutes * 60) + seconds); } -static void test_offset(StringView time_zone, i64 time, i64 expected_offset) +static void test_offset(StringView time_zone, i64 time, i64 expected_offset, TimeZone::InDST expected_in_dst) { auto actual_offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_seconds(time)); VERIFY(actual_offset.has_value()); - EXPECT_EQ(*actual_offset, expected_offset); + EXPECT_EQ(actual_offset->seconds, expected_offset); + EXPECT_EQ(actual_offset->in_dst, expected_in_dst); } TEST_CASE(get_time_zone_offset) { - test_offset("America/Chicago"sv, -2717668237, offset(-1, 5, 50, 36)); // Sunday, November 18, 1883 12:09:23 PM - test_offset("America/Chicago"sv, -2717668236, offset(-1, 6, 00, 00)); // Sunday, November 18, 1883 12:09:24 PM - test_offset("America/Chicago"sv, -1067810460, offset(-1, 6, 00, 00)); // Sunday, March 1, 1936 1:59:00 AM - test_offset("America/Chicago"sv, -1067810400, offset(-1, 5, 00, 00)); // Sunday, March 1, 1936 2:00:00 AM - test_offset("America/Chicago"sv, -1045432860, offset(-1, 5, 00, 00)); // Sunday, November 15, 1936 1:59:00 AM - test_offset("America/Chicago"sv, -1045432800, offset(-1, 6, 00, 00)); // Sunday, November 15, 1936 2:00:00 AM - - test_offset("Europe/London"sv, -3852662401, offset(-1, 0, 01, 15)); // Tuesday, November 30, 1847 11:59:59 PM - test_offset("Europe/London"sv, -3852662400, offset(+1, 0, 00, 00)); // Wednesday, December 1, 1847 12:00:00 AM - test_offset("Europe/London"sv, -37238401, offset(+1, 0, 00, 00)); // Saturday, October 26, 1968 11:59:59 PM - test_offset("Europe/London"sv, -37238400, offset(+1, 1, 00, 00)); // Sunday, October 27, 1968 12:00:00 AM - test_offset("Europe/London"sv, 57722399, offset(+1, 1, 00, 00)); // Sunday, October 31, 1971 1:59:59 AM - test_offset("Europe/London"sv, 57722400, offset(+1, 0, 00, 00)); // Sunday, October 31, 1971 2:00:00 AM - - test_offset("UTC"sv, -1641846268, offset(+1, 0, 00, 00)); - test_offset("UTC"sv, 0, offset(+1, 0, 00, 00)); - test_offset("UTC"sv, 1641846268, offset(+1, 0, 00, 00)); - - test_offset("Etc/GMT+4"sv, -1641846268, offset(-1, 4, 00, 00)); - test_offset("Etc/GMT+5"sv, 0, offset(-1, 5, 00, 00)); - test_offset("Etc/GMT+6"sv, 1641846268, offset(-1, 6, 00, 00)); - - test_offset("Etc/GMT-12"sv, -1641846268, offset(+1, 12, 00, 00)); - test_offset("Etc/GMT-13"sv, 0, offset(+1, 13, 00, 00)); - test_offset("Etc/GMT-14"sv, 1641846268, offset(+1, 14, 00, 00)); + test_offset("America/Chicago"sv, -2717668237, offset(-1, 5, 50, 36), No); // Sunday, November 18, 1883 12:09:23 PM + test_offset("America/Chicago"sv, -2717668236, offset(-1, 6, 00, 00), No); // Sunday, November 18, 1883 12:09:24 PM + test_offset("America/Chicago"sv, -1067810460, offset(-1, 6, 00, 00), No); // Sunday, March 1, 1936 1:59:00 AM + test_offset("America/Chicago"sv, -1067810400, offset(-1, 5, 00, 00), No); // Sunday, March 1, 1936 2:00:00 AM + test_offset("America/Chicago"sv, -1045432860, offset(-1, 5, 00, 00), No); // Sunday, November 15, 1936 1:59:00 AM + test_offset("America/Chicago"sv, -1045432800, offset(-1, 6, 00, 00), No); // Sunday, November 15, 1936 2:00:00 AM + + test_offset("Europe/London"sv, -3852662401, offset(-1, 0, 01, 15), No); // Tuesday, November 30, 1847 11:59:59 PM + test_offset("Europe/London"sv, -3852662400, offset(+1, 0, 00, 00), No); // Wednesday, December 1, 1847 12:00:00 AM + test_offset("Europe/London"sv, -37238401, offset(+1, 0, 00, 00), No); // Saturday, October 26, 1968 11:59:59 PM + test_offset("Europe/London"sv, -37238400, offset(+1, 1, 00, 00), No); // Sunday, October 27, 1968 12:00:00 AM + test_offset("Europe/London"sv, 57722399, offset(+1, 1, 00, 00), No); // Sunday, October 31, 1971 1:59:59 AM + test_offset("Europe/London"sv, 57722400, offset(+1, 0, 00, 00), No); // Sunday, October 31, 1971 2:00:00 AM + + test_offset("UTC"sv, -1641846268, offset(+1, 0, 00, 00), No); + test_offset("UTC"sv, 0, offset(+1, 0, 00, 00), No); + test_offset("UTC"sv, 1641846268, offset(+1, 0, 00, 00), No); + + test_offset("Etc/GMT+4"sv, -1641846268, offset(-1, 4, 00, 00), No); + test_offset("Etc/GMT+5"sv, 0, offset(-1, 5, 00, 00), No); + test_offset("Etc/GMT+6"sv, 1641846268, offset(-1, 6, 00, 00), No); + + test_offset("Etc/GMT-12"sv, -1641846268, offset(+1, 12, 00, 00), No); + test_offset("Etc/GMT-13"sv, 0, offset(+1, 13, 00, 00), No); + test_offset("Etc/GMT-14"sv, 1641846268, offset(+1, 14, 00, 00), No); EXPECT(!TimeZone::get_time_zone_offset("I don't exist"sv, {}).has_value()); } TEST_CASE(get_time_zone_offset_with_dst) { - test_offset("America/New_York"sv, 1642558528, offset(-1, 5, 00, 00)); // Wednesday, January 19, 2022 2:15:28 AM - test_offset("America/New_York"sv, 1663553728, offset(-1, 4, 00, 00)); // Monday, September 19, 2022 2:15:28 AM - test_offset("America/New_York"sv, 1671453238, offset(-1, 5, 00, 00)); // Monday, December 19, 2022 12:33:58 PM + test_offset("America/New_York"sv, 1642558528, offset(-1, 5, 00, 00), No); // Wednesday, January 19, 2022 2:15:28 AM + test_offset("America/New_York"sv, 1663553728, offset(-1, 4, 00, 00), Yes); // Monday, September 19, 2022 2:15:28 AM + test_offset("America/New_York"sv, 1671453238, offset(-1, 5, 00, 00), No); // Monday, December 19, 2022 12:33:58 PM // Phoenix does not observe DST. - test_offset("America/Phoenix"sv, 1642558528, offset(-1, 7, 00, 00)); // Wednesday, January 19, 2022 2:15:28 AM - test_offset("America/Phoenix"sv, 1663553728, offset(-1, 7, 00, 00)); // Monday, September 19, 2022 2:15:28 AM - test_offset("America/Phoenix"sv, 1671453238, offset(-1, 7, 00, 00)); // Monday, December 19, 2022 12:33:58 PM + test_offset("America/Phoenix"sv, 1642558528, offset(-1, 7, 00, 00), No); // Wednesday, January 19, 2022 2:15:28 AM + test_offset("America/Phoenix"sv, 1663553728, offset(-1, 7, 00, 00), No); // Monday, September 19, 2022 2:15:28 AM + test_offset("America/Phoenix"sv, 1671453238, offset(-1, 7, 00, 00), No); // Monday, December 19, 2022 12:33:58 PM // Moscow's observed DST changed several times in 1919. - test_offset("Europe/Moscow"sv, -1609459200, offset(+1, 2, 31, 19)); // Wednesday, January 1, 1919 12:00:00 AM - test_offset("Europe/Moscow"sv, -1596412800, offset(+1, 4, 31, 19)); // Sunday, June 1, 1919 12:00:00 AM - test_offset("Europe/Moscow"sv, -1592611200, offset(+1, 4, 00, 00)); // Tuesday, July 15, 1919 12:00:00 AM - test_offset("Europe/Moscow"sv, -1589068800, offset(+1, 3, 00, 00)); // Monday, August 25, 1919 12:00:00 AM + test_offset("Europe/Moscow"sv, -1609459200, offset(+1, 2, 31, 19), No); // Wednesday, January 1, 1919 12:00:00 AM + 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 } #else @@ -159,7 +162,7 @@ TEST_CASE(time_zone_from_string) TEST_CASE(get_time_zone_offset) { - EXPECT_EQ(TimeZone::get_time_zone_offset("UTC", AK::Time::from_seconds(123456)), 0); + EXPECT_EQ(TimeZone::get_time_zone_offset("UTC", AK::Time::from_seconds(123456)), { 0, No }); EXPECT(!TimeZone::get_time_zone_offset("Europe/Paris"sv, {}).has_value()); EXPECT(!TimeZone::get_time_zone_offset("Etc/UTC"sv, {}).has_value()); |