diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 2c0de9ebc77a0..f9f18494d31ff 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1459,8 +1459,9 @@ template class tm_writer { } auto tm_hour12() const noexcept -> int { - auto hour = tm_hour() % 12; - return hour == 0 ? 12 : hour; + const auto h = tm_hour(); + const auto z = h < 12 ? h : h - 12; + return z == 0 ? 12 : z; } // POSIX and the C Standard are unclear or inconsistent about what %C and %y