mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-28 06:36:02 +00:00
Fix chrono-test on platforms with 32-bit time_t
This commit is contained in:
parent
305747d440
commit
be57ec7ec0
@ -17,6 +17,9 @@
|
|||||||
using fmt::runtime;
|
using fmt::runtime;
|
||||||
using testing::Contains;
|
using testing::Contains;
|
||||||
|
|
||||||
|
template <typename Duration>
|
||||||
|
using sys_time = std::chrono::time_point<std::chrono::system_clock, Duration>;
|
||||||
|
|
||||||
#if defined(__MINGW32__) && !defined(_UCRT)
|
#if defined(__MINGW32__) && !defined(_UCRT)
|
||||||
// Only C89 conversion specifiers when using MSVCRT instead of UCRT
|
// Only C89 conversion specifiers when using MSVCRT instead of UCRT
|
||||||
# define FMT_HAS_C99_STRFTIME 0
|
# define FMT_HAS_C99_STRFTIME 0
|
||||||
@ -858,42 +861,33 @@ TEST(chrono_test, utc_clock) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST(chrono_test, timestamps_ratios) {
|
TEST(chrono_test, timestamp_ratios) {
|
||||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>
|
auto t1 = sys_time<std::chrono::milliseconds>(std::chrono::milliseconds(67890));
|
||||||
t1(std::chrono::milliseconds(67890));
|
|
||||||
|
|
||||||
EXPECT_EQ(fmt::format("{:%M:%S}", t1), "01:07.890");
|
EXPECT_EQ(fmt::format("{:%M:%S}", t1), "01:07.890");
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes> t2(
|
auto t2 = sys_time<std::chrono::minutes>(std::chrono::minutes(7));
|
||||||
std::chrono::minutes(7));
|
|
||||||
|
|
||||||
EXPECT_EQ(fmt::format("{:%M:%S}", t2), "07:00");
|
EXPECT_EQ(fmt::format("{:%M:%S}", t2), "07:00");
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::system_clock,
|
auto t3 = sys_time<std::chrono::duration<int, std::ratio<9>>>(
|
||||||
std::chrono::duration<int, std::ratio<9>>>
|
std::chrono::duration<int, std::ratio<9>>(7));
|
||||||
t3(std::chrono::duration<int, std::ratio<9>>(7));
|
|
||||||
|
|
||||||
EXPECT_EQ(fmt::format("{:%M:%S}", t3), "01:03");
|
EXPECT_EQ(fmt::format("{:%M:%S}", t3), "01:03");
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::system_clock,
|
auto t4 = sys_time<std::chrono::duration<int, std::ratio<63>>>(
|
||||||
std::chrono::duration<int, std::ratio<63>>>
|
std::chrono::duration<int, std::ratio<63>>(1));
|
||||||
t4(std::chrono::duration<int, std::ratio<63>>(1));
|
|
||||||
|
|
||||||
EXPECT_EQ(fmt::format("{:%M:%S}", t4), "01:03");
|
EXPECT_EQ(fmt::format("{:%M:%S}", t4), "01:03");
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>
|
if (sizeof(time_t) > 4) {
|
||||||
t5(std::chrono::seconds(32503680000));
|
auto tp = sys_time<std::chrono::milliseconds>(
|
||||||
|
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::int64_t, std::ratio<31556952>>;
|
||||||
#if FMT_SAFE_DURATION_CAST
|
auto tp = sys_time<years>(years(std::numeric_limits<std::int64_t>::max()));
|
||||||
using years = std::chrono::duration<std::int64_t, std::ratio<31556952>>;
|
EXPECT_THROW_MSG((void)fmt::format("{:%Y-%m-%d}", tp), fmt::format_error,
|
||||||
std::chrono::time_point<std::chrono::system_clock, years> t6(
|
"cannot format duration");
|
||||||
(years(std::numeric_limits<std::int64_t>::max())));
|
}
|
||||||
|
|
||||||
EXPECT_THROW_MSG((void)fmt::format("{:%Y-%m-%d}", t6), fmt::format_error,
|
|
||||||
"cannot format duration");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(chrono_test, timestamps_sub_seconds) {
|
TEST(chrono_test, timestamps_sub_seconds) {
|
||||||
|
Loading…
Reference in New Issue
Block a user