Skip to content

Commit aa8748f

Browse files
committed
Enable some local_time tests and make them deterministic
1 parent 1789879 commit aa8748f

1 file changed

Lines changed: 8 additions & 20 deletions

File tree

test/chrono-test.cc

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -350,28 +350,17 @@ TEST(chrono_test, system_clock_time_point) {
350350
}
351351
}
352352

353-
#if FMT_USE_LOCAL_TIME
354-
355-
template <typename Duration>
356-
auto strftime_full_local(fmt::local_time<Duration> t) -> std::string {
357-
auto sys_time = std::chrono::system_clock::to_time_t(
358-
std::chrono::current_zone()->to_sys(t));
359-
auto tm = *std::localtime(&sys_time);
360-
return system_strftime("%Y-%m-%d %H:%M:%S", &tm);
361-
}
353+
TEST(chrono_test, local_time) {
354+
using local_time = fmt::local_time<std::chrono::seconds>;
355+
auto t = local_time(std::chrono::seconds(290088000));
356+
EXPECT_EQ(fmt::format("{:%Y-%m-%d %H:%M:%S}", t), "1979-03-12 12:00:00");
357+
EXPECT_EQ(fmt::format("{}", t), "1979-03-12 12:00:00");
358+
EXPECT_EQ(fmt::format("{:}", t), "1979-03-12 12:00:00");
362359

363-
TEST(chrono_test, local_system_clock_time_point) {
360+
#if FMT_USE_LOCAL_TIME
364361
# ifdef _WIN32
365362
return; // Not supported on Windows.
366363
# endif
367-
auto t1 = std::chrono::time_point_cast<std::chrono::seconds>(
368-
std::chrono::current_zone()->to_local(std::chrono::system_clock::now()));
369-
EXPECT_EQ(strftime_full_local(t1), fmt::format("{:%Y-%m-%d %H:%M:%S}", t1));
370-
EXPECT_EQ(strftime_full_local(t1), fmt::format("{}", t1));
371-
EXPECT_EQ(strftime_full_local(t1), fmt::format("{:}", t1));
372-
using time_point = fmt::local_time<std::chrono::seconds>;
373-
auto t2 = time_point(std::chrono::seconds(86400 + 42));
374-
EXPECT_EQ(strftime_full_local(t2), fmt::format("{:%Y-%m-%d %H:%M:%S}", t2));
375364

376365
std::vector<std::string> spec_list = {
377366
"%%", "%n", "%t", "%Y", "%EY", "%y", "%Oy", "%Ey", "%C",
@@ -418,9 +407,8 @@ TEST(chrono_test, local_system_clock_time_point) {
418407
EXPECT_EQ(sys_output, fmt::format("{:%Oz}", t1));
419408
EXPECT_EQ(sys_output, fmt::format("{:%Oz}", tm));
420409
}
421-
}
422-
423410
#endif // FMT_USE_LOCAL_TIME
411+
}
424412

425413
TEST(chrono_test, daylight_savings_time_end) {
426414
// 2024-10-27 03:05 as the number of seconds since epoch in Europe/Kyiv time.

0 commit comments

Comments
 (0)