Fix wchar_t tm formatting

This commit is contained in:
Vladislav Shchapov
2021-09-13 12:12:36 +05:00
committed by Victor Zverovich
parent 92614ecbf9
commit d9fd695ac7
2 changed files with 9 additions and 4 deletions

View File

@@ -564,10 +564,13 @@ template <typename Char> struct formatter<std::tm, Char> {
while (end != ctx.end() && *end != '}') ++end; while (end != ctx.end() && *end != '}') ++end;
auto size = detail::to_unsigned(end - it); auto size = detail::to_unsigned(end - it);
specs = {it, size}; specs = {it, size};
if (specs == string_view("%F", 2)) // basic_string_view<>::compare isn't constexpr before C++17
spec_ = spec::year_month_day; if (specs.size() == 2 && specs[0] == Char('%')) {
else if (specs == string_view("%T", 2)) if (specs[1] == Char('F'))
spec_ = spec::hh_mm_ss; spec_ = spec::year_month_day;
else if (specs[1] == Char('T'))
spec_ = spec::hh_mm_ss;
}
return end; return end;
} }

View File

@@ -261,6 +261,8 @@ TEST(xchar_test, chrono) {
EXPECT_EQ(fmt::format("The date is {:%Y-%m-%d %H:%M:%S}.", tm), EXPECT_EQ(fmt::format("The date is {:%Y-%m-%d %H:%M:%S}.", tm),
"The date is 2016-04-25 11:22:33."); "The date is 2016-04-25 11:22:33.");
EXPECT_EQ(L"42s", fmt::format(L"{}", std::chrono::seconds(42))); EXPECT_EQ(L"42s", fmt::format(L"{}", std::chrono::seconds(42)));
EXPECT_EQ(fmt::format(L"{:%F}", tm), L"2016-04-25");
EXPECT_EQ(fmt::format(L"{:%T}", tm), L"11:22:33");
} }
TEST(xchar_test, color) { TEST(xchar_test, color) {