diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-01-24 12:36:17 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-25 18:39:36 +0000 |
commit | 7103012c7d447c1ba3d18597b086ae868661f82e (patch) | |
tree | ea203c8accdd873c23ea23972766e18fb5983f7d /Tests | |
parent | fc0c88344b04c7b1a849f1f1e0fe63558112db7b (diff) | |
download | serenity-7103012c7d447c1ba3d18597b086ae868661f82e.zip |
LibTimeZone: Add an API to retrieve both daylight and standard offsets
This API will also include the formatted name of the time zone, with
respect for DST (e.g. EST vs EDT for America/New_York).
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/LibTimeZone/TestTimeZone.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Tests/LibTimeZone/TestTimeZone.cpp b/Tests/LibTimeZone/TestTimeZone.cpp index d86aa6166f..f164db103b 100644 --- a/Tests/LibTimeZone/TestTimeZone.cpp +++ b/Tests/LibTimeZone/TestTimeZone.cpp @@ -149,6 +149,31 @@ TEST_CASE(get_time_zone_offset_with_dst) test_offset("Europe/Moscow"sv, -1589068800, offset(+1, 3, 00, 00), No); // Monday, August 25, 1919 12:00:00 AM } +TEST_CASE(get_named_time_zone_offsets) +{ + auto test_named_offsets = [](auto time_zone, i64 time, i64 expected_standard_offset, i64 expected_daylight_offset, auto expected_standard_name, auto expected_daylight_name) { + auto actual_offsets = TimeZone::get_named_time_zone_offsets(time_zone, AK::Time::from_seconds(time)); + VERIFY(actual_offsets.has_value()); + + EXPECT_EQ(actual_offsets->at(0).seconds, expected_standard_offset); + EXPECT_EQ(actual_offsets->at(1).seconds, expected_daylight_offset); + EXPECT_EQ(actual_offsets->at(0).name, expected_standard_name); + EXPECT_EQ(actual_offsets->at(1).name, expected_daylight_name); + }; + + test_named_offsets("America/New_York"sv, 1642558528, offset(-1, 5, 00, 00), offset(-1, 4, 00, 00), "EST"sv, "EDT"sv); // Wednesday, January 19, 2022 2:15:28 AM + test_named_offsets("UTC"sv, 1642558528, offset(+1, 0, 00, 00), offset(+1, 0, 00, 00), "UTC"sv, "UTC"sv); // Wednesday, January 19, 2022 2:15:28 AM + test_named_offsets("GMT"sv, 1642558528, offset(+1, 0, 00, 00), offset(+1, 0, 00, 00), "GMT"sv, "GMT"sv); // Wednesday, January 19, 2022 2:15:28 AM + + // Phoenix does not observe DST. + test_named_offsets("America/Phoenix"sv, 1642558528, offset(-1, 7, 00, 00), offset(-1, 7, 00, 00), "MST"sv, "MST"sv); // Wednesday, January 19, 2022 2:15:28 AM + + // Moscow's observed DST changed several times in 1919. + test_named_offsets("Europe/Moscow"sv, -1609459200, offset(+1, 2, 31, 19), offset(+1, 3, 31, 19), "MSK"sv, "MSD"sv); // Wednesday, January 1, 1919 12:00:00 AM + test_named_offsets("Europe/Moscow"sv, -1596412800, offset(+1, 2, 31, 19), offset(+1, 4, 31, 19), "MSK"sv, "MDST"sv); // Sunday, June 1, 1919 12:00:00 AM + test_named_offsets("Europe/Moscow"sv, -1589068800, offset(+1, 3, 00, 00), offset(+1, 4, 00, 00), "MSK"sv, "MSD"sv); // Monday, August 25, 1919 12:00:00 AM +} + #else TEST_CASE(time_zone_from_string) |