C++ Logo


Advanced search

Re: [std-proposals] New draft proposal: Add "%s" (two-digit truncated-integer seconds) as a std::format conversion specifier for std::chrono time types.

From: Simon Hill <protogrammer_at_[hidden]>
Date: Thu, 4 May 2023 08:01:12 +0200
> Think about it from the perspective of what the user is doing.... In the latter case, why would you do text conversion in a way that doesn't store all of the information in the time?
Sort items (eg files) by time (full precision desired for sort), then print time in a tidy or consistent or user-specified manner. This is the norm for file managers, the ls command (eg ls "-l -t"), etc.
> Equally importantly, if your intention is specifically to put less
precision into the text than the time actually stores... maybe
verbosity is a *good thing*. That sounds like the sort of thing you
can do by mistake.
Any format string that doesn't contain seconds (eg {:%H:%M}) is less precise and has the same degree of verbosity.
Choosing "%s" (instead of "%S") would be explicitly (if not verbosely) stating that you _don't_ want subsecond precision. Although I agree it's not self-explanatory.
You could accidentally use the wrong case, but it's no worse than accidentally using "%m" instead of "%M".
> All that being said, there is one clear advantage to your idea: cases
where the format string is not known at the site of the use of the
format string. The format string could come from a translation file, a
macro, or somewhere else. And it would be good if those places could
have more control over the formatting precision.
I think that's actually the best argument by far, thanks.

Received on 2023-05-04 06:01:15