diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 874dc4d9..997bb2d0 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1590,11 +1590,6 @@ template class tm_writer { void on_datetime(numeric_system ns) { if (is_classic_) { -#ifdef _WIN32 - on_us_date(); - *out_++ = ' '; - on_iso_time(); -#else on_abbr_weekday(); *out_++ = ' '; on_abbr_month(); @@ -1604,7 +1599,6 @@ template class tm_writer { on_iso_time(); *out_++ = ' '; on_year(numeric_system::standard); -#endif } else { format_localized('c', ns == numeric_system::standard ? '\0' : 'E'); } @@ -1735,16 +1729,12 @@ template class tm_writer { void on_12_hour_time() { if (is_classic_) { -#ifdef _WIN32 - on_iso_time(); -#else char buf[8]; write_digit2_separated(buf, to_unsigned(tm_hour12()), to_unsigned(tm_min()), to_unsigned(tm_sec()), ':'); out_ = copy_str(std::begin(buf), std::end(buf), out_); *out_++ = ' '; on_am_pm(); -#endif } else { format_localized('r'); } diff --git a/test/chrono-test.cc b/test/chrono-test.cc index 6eaf1cfb..5019a402 100644 --- a/test/chrono-test.cc +++ b/test/chrono-test.cc @@ -248,13 +248,19 @@ TEST(chrono_test, time_point) { EXPECT_EQ(strftime_full(t2), fmt::format("{:%Y-%m-%d %H:%M:%S}", t2)); std::vector spec_list = { - "%%", "%n", "%t", "%Y", "%EY", "%y", "%Oy", "%Ey", "%C", "%EC", - "%G", "%g", "%b", "%h", "%B", "%m", "%Om", "%U", "%OU", "%W", - "%OW", "%V", "%OV", "%j", "%d", "%Od", "%e", "%Oe", "%a", "%A", - "%w", "%Ow", "%u", "%Ou", "%H", "%OH", "%I", "%OI", "%M", "%OM", - "%S", "%OS", "%c", "%Ec", "%x", "%Ex", "%X", "%EX", "%D", "%F", - "%r", "%R", "%T", "%p", "%z", "%Z"}; + "%%", "%n", "%t", "%Y", "%EY", "%y", "%Oy", "%Ey", "%C", + "%EC", "%G", "%g", "%b", "%h", "%B", "%m", "%Om", "%U", + "%OU", "%W", "%OW", "%V", "%OV", "%j", "%d", "%Od", "%e", + "%Oe", "%a", "%A", "%w", "%Ow", "%u", "%Ou", "%H", "%OH", + "%I", "%OI", "%M", "%OM", "%S", "%OS", "%x", "%Ex", "%X", + "%EX", "%D", "%F", "%R", "%T", "%p", "%z", "%Z"}; spec_list.push_back("%Y-%m-%d %H:%M:%S"); +#ifndef _WIN32 + // Disabled on Windows, because these formats is not consistent among + // platforms. + spec_list.insert(spec_list.end(), {"%c", "%Ec", "%r"}); +#endif + for (const auto& spec : spec_list) { auto t = std::chrono::system_clock::to_time_t(t1); auto tm = *std::localtime(&t); diff --git a/test/xchar-test.cc b/test/xchar-test.cc index 4620ee25..8f98c050 100644 --- a/test/xchar-test.cc +++ b/test/xchar-test.cc @@ -284,14 +284,19 @@ TEST(chrono_test, time_point) { auto t1 = std::chrono::system_clock::now(); std::vector spec_list = { - L"%%", L"%n", L"%t", L"%Y", L"%EY", L"%y", L"%Oy", L"%Ey", - L"%C", L"%EC", L"%G", L"%g", L"%b", L"%h", L"%B", L"%m", - L"%Om", L"%U", L"%OU", L"%W", L"%OW", L"%V", L"%OV", L"%j", - L"%d", L"%Od", L"%e", L"%Oe", L"%a", L"%A", L"%w", L"%Ow", - L"%u", L"%Ou", L"%H", L"%OH", L"%I", L"%OI", L"%M", L"%OM", - L"%S", L"%OS", L"%c", L"%Ec", L"%x", L"%Ex", L"%X", L"%EX", - L"%D", L"%F", L"%r", L"%R", L"%T", L"%p", L"%z", L"%Z"}; + L"%%", L"%n", L"%t", L"%Y", L"%EY", L"%y", L"%Oy", L"%Ey", L"%C", + L"%EC", L"%G", L"%g", L"%b", L"%h", L"%B", L"%m", L"%Om", L"%U", + L"%OU", L"%W", L"%OW", L"%V", L"%OV", L"%j", L"%d", L"%Od", L"%e", + L"%Oe", L"%a", L"%A", L"%w", L"%Ow", L"%u", L"%Ou", L"%H", L"%OH", + L"%I", L"%OI", L"%M", L"%OM", L"%S", L"%OS", L"%x", L"%Ex", L"%X", + L"%EX", L"%D", L"%F", L"%R", L"%T", L"%p", L"%z", L"%Z"}; spec_list.push_back(L"%Y-%m-%d %H:%M:%S"); +#ifndef _WIN32 + // Disabled on Windows, because these formats is not consistent among + // platforms. + spec_list.insert(spec_list.end(), {L"%c", L"%Ec", L"%r"}); +#endif + for (const auto& spec : spec_list) { auto t = std::chrono::system_clock::to_time_t(t1); auto tm = *std::localtime(&t);