Skip to content

Commit

Permalink
Simplify C99 strftime detection conditions
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Shchapov <[email protected]>
  • Loading branch information
phprus authored and vitaut committed Dec 25, 2022
1 parent cb72c23 commit 4841784
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
20 changes: 13 additions & 7 deletions test/chrono-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
#include "util.h" // get_locale

using fmt::runtime;

using testing::Contains;

#if defined(__MINGW32__) && !defined(_UCRT)
// Only C89 conversion specifiers when using MSVCRT instead of UCRT
# define FMT_HAS_C99_STRFTIME 0
#else
# define FMT_HAS_C99_STRFTIME 1
#endif

auto make_tm() -> std::tm {
auto time = std::tm();
time.tm_mday = 1;
Expand Down Expand Up @@ -123,7 +129,7 @@ TEST(chrono_test, format_tm) {
make_tm(2000, 1, 3, 12, 14, 16) // W1
};

#if defined(__MINGW32__) && !defined(_UCRT)
#if !FMT_HAS_C99_STRFTIME
GTEST_SKIP() << "Skip the rest of this test because it relies on strftime() "
"conforming to C99, but on this platform, MINGW + MSVCRT, "
"the function conforms only to C89.";
Expand Down Expand Up @@ -269,7 +275,7 @@ TEST(chrono_test, system_clock_time_point) {
// Disabled on Windows because these formats are not consistent among
// platforms.
spec_list.insert(spec_list.end(), {"%c", "%Ec", "%r"});
#elif defined(__MINGW32__) && !defined(_UCRT)
#elif !FMT_HAS_C99_STRFTIME
// Only C89 conversion specifiers when using MSVCRT instead of UCRT
spec_list = {"%%", "%Y", "%y", "%b", "%B", "%m", "%U", "%W", "%j", "%d",
"%a", "%A", "%w", "%H", "%I", "%M", "%S", "%x", "%X", "%p"};
Expand All @@ -288,10 +294,10 @@ TEST(chrono_test, system_clock_time_point) {
}

// Timezone formatters tests makes sense for localtime.
#if defined(__MINGW32__) && !defined(_UCRT)
spec_list = {"%Z"};
#else
#if FMT_HAS_C99_STRFTIME
spec_list = {"%z", "%Z"};
#else
spec_list = {"%Z"};
#endif
for (const auto& spec : spec_list) {
auto t = std::chrono::system_clock::to_time_t(t1);
Expand Down Expand Up @@ -374,7 +380,7 @@ TEST(chrono_test, local_system_clock_time_point) {
// Disabled on Windows because these formats are not consistent among
// platforms.
spec_list.insert(spec_list.end(), {"%c", "%Ec", "%r"});
# elif defined(__MINGW32__) && !defined(_UCRT)
# elif !FMT_HAS_C99_STRFTIME
// Only C89 conversion specifiers when using MSVCRT instead of UCRT
spec_list = {"%%", "%Y", "%y", "%b", "%B", "%m", "%U", "%W", "%j", "%d", "%a",
"%A", "%w", "%H", "%I", "%M", "%S", "%x", "%X", "%p", "%Z"};
Expand Down
15 changes: 11 additions & 4 deletions test/xchar-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
using fmt::detail::max_value;
using testing::Contains;

#if defined(__MINGW32__) && !defined(_UCRT)
// Only C89 conversion specifiers when using MSVCRT instead of UCRT
# define FMT_HAS_C99_STRFTIME 0
#else
# define FMT_HAS_C99_STRFTIME 1
#endif

namespace test_ns {
template <typename Char> class test_string {
private:
Expand Down Expand Up @@ -299,7 +306,7 @@ TEST(chrono_test_wchar, time_point) {
// Disabled on Windows, because these formats is not consistent among
// platforms.
spec_list.insert(spec_list.end(), {L"%c", L"%Ec", L"%r"});
#elif defined(__MINGW32__) && !defined(_UCRT)
#elif !FMT_HAS_C99_STRFTIME
// Only C89 conversion specifiers when using MSVCRT instead of UCRT
spec_list = {L"%%", L"%Y", L"%y", L"%b", L"%B", L"%m", L"%U",
L"%W", L"%j", L"%d", L"%a", L"%A", L"%w", L"%H",
Expand All @@ -319,10 +326,10 @@ TEST(chrono_test_wchar, time_point) {
}

// Timezone formatters tests makes sense for localtime.
#if defined(__MINGW32__) && !defined(_UCRT)
spec_list = {L"%Z"};
#else
#if FMT_HAS_C99_STRFTIME
spec_list = {L"%z", L"%Z"};
#else
spec_list = {L"%Z"};
#endif
for (const auto& spec : spec_list) {
auto t = std::chrono::system_clock::to_time_t(t1);
Expand Down

0 comments on commit 4841784

Please sign in to comment.