diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 56fbd382..fea296e8 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -17,6 +17,9 @@ using fmt::runtime; using testing::Contains; +template +using sys_time = std::chrono::time_point; + #if defined(__MINGW32__) && !defined(_UCRT) // Only C89 conversion specifiers when using MSVCRT instead of UCRT # define FMT_HAS_C99_STRFTIME 0 @@ -858,42 +861,33 @@ TEST(chrono_test, utc_clock) { } #endif -TEST(chrono_test, timestamps_ratios) { - std::chrono::time_point - t1(std::chrono::milliseconds(67890)); - +TEST(chrono_test, timestamp_ratios) { + auto t1 = sys_time(std::chrono::milliseconds(67890)); EXPECT_EQ(fmt::format("{:%M:%S}", t1), "01:07.890"); - std::chrono::time_point t2( - std::chrono::minutes(7)); - + auto t2 = sys_time(std::chrono::minutes(7)); EXPECT_EQ(fmt::format("{:%M:%S}", t2), "07:00"); - std::chrono::time_point>> - t3(std::chrono::duration>(7)); - + auto t3 = sys_time>>( + std::chrono::duration>(7)); EXPECT_EQ(fmt::format("{:%M:%S}", t3), "01:03"); - std::chrono::time_point>> - t4(std::chrono::duration>(1)); - + auto t4 = sys_time>>( + std::chrono::duration>(1)); EXPECT_EQ(fmt::format("{:%M:%S}", t4), "01:03"); - std::chrono::time_point - t5(std::chrono::seconds(32503680000)); + if (sizeof(time_t) > 4) { + auto tp = sys_time( + std::chrono::seconds(32503680000)); + EXPECT_EQ(fmt::format("{:%Y-%m-%d}", tp), "3000-01-01"); + } - EXPECT_EQ(fmt::format("{:%Y-%m-%d}", t5), "3000-01-01"); - -#if FMT_SAFE_DURATION_CAST - using years = std::chrono::duration>; - std::chrono::time_point t6( - (years(std::numeric_limits::max()))); - - EXPECT_THROW_MSG((void)fmt::format("{:%Y-%m-%d}", t6), fmt::format_error, - "cannot format duration"); -#endif + if (FMT_SAFE_DURATION_CAST) { + using years = std::chrono::duration>; + auto tp = sys_time(years(std::numeric_limits::max())); + EXPECT_THROW_MSG((void)fmt::format("{:%Y-%m-%d}", tp), fmt::format_error, + "cannot format duration"); + } } TEST(chrono_test, timestamps_sub_seconds) {