<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3547: Time formatters should not be locale sensitive by default</title>
<meta property="og:title" content="Issue 3547: Time formatters should not be locale sensitive by default">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3547.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#Resolved">Resolved</a> status.</em></p>
<h3 id="3547"><a href="lwg-defects.html#3547">3547</a>. Time formatters should not be locale sensitive by default</h3>
<p><b>Section:</b> 30.12 <a href="https://wg21.link/time.format">[time.format]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Corentin Jabot <b>Opened:</b> 2021-04-27 <b>Last modified:</b> 2021-10-23</p>
<p><b>Priority: </b>2
</p>
<p><b>View other</b> <a href="lwg-index-open.html#time.format">active issues</a> in [time.format].</p>
<p><b>View all other</b> <a href="lwg-index.html#time.format">issues</a> in [time.format].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In 30.12 <a href="https://wg21.link/time.format">[time.format]</a> it is specified:
</p>
<blockquote><p>
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.
</p></blockquote>
<p>
This is not consistent with the format design after the adoption of <a href="https://wg21.link/p1892">P1892</a>. In
28.5.2.2 <a href="https://wg21.link/format.string.std">[format.string.std]</a> we say:
</p>
<blockquote><p>
When the <code>L</code> option is used, the form used for the conversion is called the <i>locale-specific</i> form. The
<code>L</code> option is only valid for arithmetic types, and its effect depends upon the type.
</p></blockquote>
<p>
This has two issues: First, it is inconsistent.
</p>
<blockquote><pre>
format("{}, 0.0"); // locale independent
format("{:L}", 0.0); // use locale
format("{:%r}, some_time); // use globale locale
format("{:%rL}, some_time); // error
</pre></blockquote>
<p>
And second it perpetuates the issues <a href="https://wg21.link/p1892">P1892</a> intended to solve.
It is likely that this inconsistency resulted from both papers being in flight around the same time.
<p/>
The <code>L</code> option should be used and consistent with floating point. We suggest using the C locale
which is the non-locale locale, see also
<a href="https://pubs.opengroup.org/onlinepubs/009604499/basedefs/xbd_chap07.html">here</a>.
</p>

<p><i>[2021-05-17; Reflector poll]</i></p>

<p>
Priority set to 2.
This will be resolved by <a href="https://wg21.link/P2372">P2372</a>.
Tim noted: "P1892 didn't change format's ignore-locale-by-default design,
so that paper being in flight at the same time as P1361 cannot explain why
the latter is locale-sensitive-by-default."
</p>

<p><i>[2021-10-23 Resolved by the adoption of <a href="https://wg21.link/P2372R3" title=" Fixing locale handling in chrono formatters">P2372R3</a> at the October 2021 plenary. Status changed: New &rarr; Resolved.]</i></p>



<p id="res-3547"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/n4885">N4885</a>.
</p>

<ol>
<li><p>Modify 30.12 <a href="https://wg21.link/time.format">[time.format]</a> as indicated:</p>

<blockquote>
<blockquote>
<pre>
<i>chrono-format-spec:</i>
         <i>fill-and-align<sub>opt</sub> width<sub>opt</sub> precision<sub>opt</sub></i> <ins>L<i><sub>opt</sub></i></ins> <i>chrono-specs<sub>opt</sub></i>
[&hellip;]
</pre>
</blockquote>
<p>
-1- [&hellip;]
<p/>
-2- Each conversion specifier <i>conversion-spec</i> is replaced by appropriate characters as described in Table
[tab:time.format.spec]; 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 <code>L</code> option is used, that locale is the locale that is passed to
the formatting function if the latter takes one, or the global locale otherwise. If the <code>L</code> option is not used,
that locale is the <code>"C"</code> locale</ins>. If the formatted object does not contain the information the
conversion specifier refers to, an exception of type <code>format_error</code> is thrown.
</p>
</blockquote>

</li>
</ol>





</body>
</html>
