Simplify C99 strftime detection conditions
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
parent
cb72c23e9e
commit
4841784e82
@ -15,9 +15,15 @@
|
|||||||
#include "util.h" // get_locale
|
#include "util.h" // get_locale
|
||||||
|
|
||||||
using fmt::runtime;
|
using fmt::runtime;
|
||||||
|
|
||||||
using testing::Contains;
|
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 make_tm() -> std::tm {
|
||||||
auto time = std::tm();
|
auto time = std::tm();
|
||||||
time.tm_mday = 1;
|
time.tm_mday = 1;
|
||||||
@ -123,7 +129,7 @@ TEST(chrono_test, format_tm) {
|
|||||||
make_tm(2000, 1, 3, 12, 14, 16) // W1
|
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() "
|
GTEST_SKIP() << "Skip the rest of this test because it relies on strftime() "
|
||||||
"conforming to C99, but on this platform, MINGW + MSVCRT, "
|
"conforming to C99, but on this platform, MINGW + MSVCRT, "
|
||||||
"the function conforms only to C89.";
|
"the function conforms only to C89.";
|
||||||
@ -269,7 +275,7 @@ TEST(chrono_test, system_clock_time_point) {
|
|||||||
// Disabled on Windows because these formats are not consistent among
|
// Disabled on Windows because these formats are not consistent among
|
||||||
// platforms.
|
// platforms.
|
||||||
spec_list.insert(spec_list.end(), {"%c", "%Ec", "%r"});
|
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
|
// Only C89 conversion specifiers when using MSVCRT instead of UCRT
|
||||||
spec_list = {"%%", "%Y", "%y", "%b", "%B", "%m", "%U", "%W", "%j", "%d",
|
spec_list = {"%%", "%Y", "%y", "%b", "%B", "%m", "%U", "%W", "%j", "%d",
|
||||||
"%a", "%A", "%w", "%H", "%I", "%M", "%S", "%x", "%X", "%p"};
|
"%a", "%A", "%w", "%H", "%I", "%M", "%S", "%x", "%X", "%p"};
|
||||||
@ -288,10 +294,10 @@ TEST(chrono_test, system_clock_time_point) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Timezone formatters tests makes sense for localtime.
|
// Timezone formatters tests makes sense for localtime.
|
||||||
#if defined(__MINGW32__) && !defined(_UCRT)
|
#if FMT_HAS_C99_STRFTIME
|
||||||
spec_list = {"%Z"};
|
|
||||||
#else
|
|
||||||
spec_list = {"%z", "%Z"};
|
spec_list = {"%z", "%Z"};
|
||||||
|
#else
|
||||||
|
spec_list = {"%Z"};
|
||||||
#endif
|
#endif
|
||||||
for (const auto& spec : spec_list) {
|
for (const auto& spec : spec_list) {
|
||||||
auto t = std::chrono::system_clock::to_time_t(t1);
|
auto t = std::chrono::system_clock::to_time_t(t1);
|
||||||
@ -374,7 +380,7 @@ TEST(chrono_test, local_system_clock_time_point) {
|
|||||||
// Disabled on Windows because these formats are not consistent among
|
// Disabled on Windows because these formats are not consistent among
|
||||||
// platforms.
|
// platforms.
|
||||||
spec_list.insert(spec_list.end(), {"%c", "%Ec", "%r"});
|
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
|
// Only C89 conversion specifiers when using MSVCRT instead of UCRT
|
||||||
spec_list = {"%%", "%Y", "%y", "%b", "%B", "%m", "%U", "%W", "%j", "%d", "%a",
|
spec_list = {"%%", "%Y", "%y", "%b", "%B", "%m", "%U", "%W", "%j", "%d", "%a",
|
||||||
"%A", "%w", "%H", "%I", "%M", "%S", "%x", "%X", "%p", "%Z"};
|
"%A", "%w", "%H", "%I", "%M", "%S", "%x", "%X", "%p", "%Z"};
|
||||||
|
@ -22,6 +22,13 @@
|
|||||||
using fmt::detail::max_value;
|
using fmt::detail::max_value;
|
||||||
using testing::Contains;
|
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 {
|
namespace test_ns {
|
||||||
template <typename Char> class test_string {
|
template <typename Char> class test_string {
|
||||||
private:
|
private:
|
||||||
@ -299,7 +306,7 @@ TEST(chrono_test_wchar, time_point) {
|
|||||||
// Disabled on Windows, because these formats is not consistent among
|
// Disabled on Windows, because these formats is not consistent among
|
||||||
// platforms.
|
// platforms.
|
||||||
spec_list.insert(spec_list.end(), {L"%c", L"%Ec", L"%r"});
|
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
|
// 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",
|
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",
|
L"%W", L"%j", L"%d", L"%a", L"%A", L"%w", L"%H",
|
||||||
@ -319,10 +326,10 @@ TEST(chrono_test_wchar, time_point) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Timezone formatters tests makes sense for localtime.
|
// Timezone formatters tests makes sense for localtime.
|
||||||
#if defined(__MINGW32__) && !defined(_UCRT)
|
#if FMT_HAS_C99_STRFTIME
|
||||||
spec_list = {L"%Z"};
|
|
||||||
#else
|
|
||||||
spec_list = {L"%z", L"%Z"};
|
spec_list = {L"%z", L"%Z"};
|
||||||
|
#else
|
||||||
|
spec_list = {L"%Z"};
|
||||||
#endif
|
#endif
|
||||||
for (const auto& spec : spec_list) {
|
for (const auto& spec : spec_list) {
|
||||||
auto t = std::chrono::system_clock::to_time_t(t1);
|
auto t = std::chrono::system_clock::to_time_t(t1);
|
||||||
|
Loading…
Reference in New Issue
Block a user