Skip to content

Commit

Permalink
Add %k, %l format specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
ZaheenJ committed May 24, 2024
1 parent f536329 commit 2627fa5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,12 @@ FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end,
case 'I':
handler.on_12_hour(numeric_system::standard, pad);
break;
case 'k':
handler.on_24_hour(numeric_system::standard, pad_type::space);
break;
case 'l':
handler.on_12_hour(numeric_system::standard, pad_type::space);
break;
case 'M':
handler.on_minute(numeric_system::standard, pad);
break;
Expand Down Expand Up @@ -936,6 +942,12 @@ FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end,
case 'M':
handler.on_minute(numeric_system::alternative, pad);
break;
case 'k':
handler.on_24_hour(numeric_system::alternative, pad_type::space);
break;
case 'l':
handler.on_12_hour(numeric_system::alternative, pad_type::space);
break;
case 'S':
handler.on_second(numeric_system::alternative, pad);
break;
Expand Down
4 changes: 4 additions & 0 deletions test/chrono-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@ TEST(chrono_test, glibc_extensions) {
EXPECT_EQ(fmt::format("{:%0OI,%0OH,%0OM,%0OS}", d), "01,01,02,03");
EXPECT_EQ(fmt::format("{:%_OI,%_OH,%_OM,%_OS}", d), " 1, 1, 2, 3");
EXPECT_EQ(fmt::format("{:%-OI,%-OH,%-OM,%-OS}", d), "1,1,2,3");

EXPECT_EQ(fmt::format("{:%k,%l}", d), " 1, 1");
}

{
Expand All @@ -993,6 +995,8 @@ TEST(chrono_test, glibc_extensions) {
EXPECT_EQ(fmt::format("{:%0OI,%0OH,%0OM,%0OS}", tm), "01,01,02,03");
EXPECT_EQ(fmt::format("{:%_OI,%_OH,%_OM,%_OS}", tm), " 1, 1, 2, 3");
EXPECT_EQ(fmt::format("{:%-OI,%-OH,%-OM,%-OS}", tm), "1,1,2,3");

EXPECT_EQ(fmt::format("{:%k,%l}", tm), " 1, 1");
}

{
Expand Down

0 comments on commit 2627fa5

Please sign in to comment.