C++ Logo

sg16

Advanced search

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

From: Victor Zverovich <victor.zverovich_at_[hidden]>
Date: Tue, 27 Apr 2021 08:13:16 -0700
Please note that if we go with the L specifier, then it should follow
precision for consistency with standard format specifiers (
https://eel.is/c++draft/format.string.std) and to avoid ambiguity, i.e. it
should be

* fill-and-align(opt) width(opt) precision(opt) **L(opt)*
* chrono-specs(opt)*

Also typo: later -> latter.

- Victor

On Tue, Apr 27, 2021 at 12:29 AM Corentin via SG16 <sg16_at_[hidden]>
wrote:

> In [time.format], it is specified
>
> > Some of the conversion specifiers depend on the locale that is passed to
> the formatting function if the latter takes one, or the global locale
> otherwise
>
> This is not consistent with the format design after the adoption of P1892
> In [format.string.std] we say:
>
> > When the L option is used, the form used for the conversion is called
> the locale-specific form. The L option is only valid for arithmetic types,
> and its effect depends upon the type
>
> This has 2 issues:
> First, it is inconsistent.
>
> format("{}, 0.0"); // locale independent
> format("{:L}", 0.0); // use locale
> format("{:%r}, some_time); // use globale locale
> format("{:%rL}, some_time); // error
>
> And second it perpetuates the issues P1892 intended to solve.
> It is likely that this inconsistency resulted from both papers being in
> flight around the same time
>
> Proposed resolution
>
> The L option should be used and consistent with floating point. We suggest
> using the C locale which is the non-locale locale. (
> https://pubs.opengroup.org/onlinepubs/009604499/basedefs/xbd_chap07.html)
>
> Suggested wording
>
> Modify [time.format]/1
>
> *chrono-format-spec: *
> * fill-and-align(opt) width(opt) precision(opt) chrono-specs(opt)L(opt)*
>
> Modify [time.format]/2
>
> Each conversion specifier conversion-spec is replaced by appropriate
> characters as described in Table 101; the formats specified in ISO
> 8601:2004 shall be used where so described. Some of the conversion
> specifiers depend on <del>the locale that is passed to the formatting
> function if the latter takes one, or the global locale otherwise</del>
> *<ins>a locale. If the L option is used, that locale is the locale that is
> passed to the formatting function if the later takes one, or the global
> locale otherwise. If the L option is not used, that locale is the "C"
> locale</ins>*.If the formatted object does not contain the information
> the conversion specifier refers to, an exception of type format_error is
> thrown.
>
>
>
> --
> SG16 mailing list
> SG16_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/sg16
>

Received on 2021-04-27 10:13:30