Skip to content

Commit

Permalink
Fix wchar_t tm formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
phprus committed Sep 13, 2021
1 parent 140727c commit a9113e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,13 @@ template <typename Char> struct formatter<std::tm, Char> {
while (end != ctx.end() && *end != '}') ++end;
auto size = detail::to_unsigned(end - it);
specs = {it, size};
if (specs == string_view("%F", 2))
spec_ = spec::year_month_day;
else if (specs == string_view("%T", 2))
spec_ = spec::hh_mm_ss;
// basic_string_view<>::compare isn't constexpr before C++17
if (specs.size() == 2 && specs[0] == Char('%')) {
if (specs[1] == Char('F'))
spec_ = spec::year_month_day;
else if (specs[1] == Char('T'))
spec_ = spec::hh_mm_ss;
}
return end;
}

Expand Down
2 changes: 2 additions & 0 deletions test/xchar-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ TEST(xchar_test, chrono) {
EXPECT_EQ(fmt::format("The date is {:%Y-%m-%d %H:%M:%S}.", tm),
"The date is 2016-04-25 11:22:33.");
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) {
Expand Down

0 comments on commit a9113e5

Please sign in to comment.