Add test for different timezones

pull/1857/head
Alexey Sokolov 3 months ago
parent 9de3f908b9
commit 4fc9429d0f

@ -85,6 +85,29 @@ TEST(IRC32, SetMessageTags) {
EXPECT_EQ(sLine, R"(@a=\:\s\\\r\n :rest)");
}
TEST(UtilsTest, Timezone) {
char* oldTZ = getenv("TZ");
if (oldTZ) oldTZ = strdup(oldTZ);
setenv("TZ", "Europe/Berlin", 1);
tzset();
EXPECT_EQ(CUtils::FormatTime(1673122230, "%Y-%m-%d %H:%M:%S", "UTC"), "2023-01-07 20:10:30");
EXPECT_EQ(CUtils::FormatTime(1673122230, "%Y-%m-%d %H:%M:%S", "GMT"), "2023-01-07 20:10:30");
EXPECT_EQ(CUtils::FormatTime(1673122230, "%Y-%m-%d %H:%M:%S", "GMT+7"), "2023-01-08 03:10:30");
EXPECT_EQ(CUtils::FormatTime(1673122230, "%Y-%m-%d %H:%M:%S", "GMT-7"), "2023-01-07 13:10:30");
EXPECT_EQ(CUtils::FormatTime(1673122230, "%Y-%m-%d %H:%M:%S", "Asia/Vladivostok"), "2023-01-08 06:10:30");
// Local TZ, set to Berlin in this test
EXPECT_EQ(CUtils::FormatTime(1673122230, "%Y-%m-%d %H:%M:%S", ""), "2023-01-07 21:10:30");
if (oldTZ) {
setenv("TZ", oldTZ, 1);
free(oldTZ);
} else {
unsetenv("TZ");
}
tzset();
}
TEST(UtilsTest, ServerTime) {
char* oldTZ = getenv("TZ");
if (oldTZ) oldTZ = strdup(oldTZ);
@ -116,7 +139,6 @@ TEST(UtilsTest, ServerTime) {
unsetenv("TZ");
}
tzset();
}
TEST(UtilsTest, ParseServerTime) {

Loading…
Cancel
Save