#include <chrono>
#include <fmt/chrono.h>
int main() {
using namespace std::chrono;
// this one prints 1.00s, as expected
fmt::print("{:.2}\n", duration<double>(1.0));
// this one prints 1s but shouldn't compile
fmt::print("{:.2}\n", duration<int>(1));
// these both print .2
fmt::print("{:.2}\n", time_point<system_clock, duration<double>>(duration<double>(1.0)));
fmt::print("{:.2}\n", time_point<system_clock, duration<int>>(duration<int>(1)));
}
If we look at the standard spec, it's clear that using precision with a duration is only valid for floating point (https://eel.is/c++draft/time.format#1.sentence-4), so the second call there should be rejected.
There's some ambiguity in the standard spec right now about what formatting a time_point<system_clock, duration<int>> with {:.2} actually means (valid or not? probably not?) but either way, printing .2 in either case is definitely incorrect.
If we look at the standard spec, it's clear that using precision with a
durationis only valid for floating point (https://eel.is/c++draft/time.format#1.sentence-4), so the second call there should be rejected.There's some ambiguity in the standard spec right now about what formatting a
time_point<system_clock, duration<int>>with{:.2}actually means (valid or not? probably not?) but either way, printing.2in either case is definitely incorrect.