C++ Logo

sg16

Advanced search

Re: [SG16] LWG issue: Time formatters should not be locale sensitive by default

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Thu, 29 Apr 2021 08:52:51 +0200
On 29/04/2021 08.37, Corentin via SG16 wrote:
> If you have to mix localized and non localized content, as you can do with numbers, the solution in C++20 would be
>
> std::format("{:%r} {}", date, std::format(locale::classic(), "{:%r}", date));
>
> The solution in 23 would be, using Jens Idea
>
> std::format("{0:%r} {0:N%r}", date ); // second is not localized
>
> Mixing with numbers:
>
> std::format("{} {:N%r}", 0.0 date ); // not localized
> std::format("{:L} {:%r}", 0.0 date ); // localized
>
>
> Really easy to understand and not surprising at all. (/s)

Just to clarify: I'm (no longer) suggesting a "N" modifier for
non-locale-sensitive; I'm suggesting to come up with an
entirely new syntax for chrono formatting that disallows
"literals inside format specifiers" and that by default
is non-locale-sensitive, to be consistent with the way
float-formatting works. The existing strftime formatting
is just left alone.

Jens

Received on 2021-04-29 01:52:58