<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3565: Handling of encodings in localized formatting of chrono types is underspecified</title>
<meta property="og:title" content="Issue 3565: Handling of encodings in localized formatting of chrono types is underspecified">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3565.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="3565"><a href="lwg-defects.html#3565">3565</a>. Handling of encodings in localized formatting of <code>chrono</code> types is underspecified</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> Victor Zverovich <b>Opened:</b> 2021-05-31 <b>Last modified:</b> 2023-03-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>
When formatting chrono types using a locale the result is underspecified, possibly a mix of the literal and locale encodings. For example:
</p>
<blockquote><pre>
std::locale::global(std::locale("Russian.1251"));
auto s = std::format("&Dcy;&iecy;&ncy;&softcy; &ncy;&iecy;&dcy;&iecy;&lcy;&icy;: {}", std::chrono::Monday);
</pre></blockquote>
<p>
(Note that "<code>{}</code>" should be replaced with "<code>{:L}</code>" if <a href="https://wg21.link/P2372" title=" Fixing locale handling in chrono formatters">P2372</a> is adopted but that's non-essential.)
<p/>
If the literal encoding is UTF-8 and the <code>"Russian.1251"</code> locale exists we have a mismatch between encodings.
As far as I can see the standard doesn't specify what happens in this case.
<p/>
One possible and undesirable result is
</p>
<blockquote><pre>
"&Dcy;&iecy;&ncy;&softcy; &ncy;&iecy;&dcy;&iecy;&lcy;&icy;: \xcf\xed"
</pre></blockquote>
<p>
where <code>"\xcf\xed"</code> is <code>"&Pcy;&ncy;"</code> (Mon in Russian) in CP1251 and is not valid UTF-8.
<p/>
Another possible and desirable result is
</p>
<blockquote><pre>
"&Dcy;&iecy;&ncy;&softcy; &ncy;&iecy;&dcy;&iecy;&lcy;&icy;: &Pcy;&ncy;"
</pre></blockquote>
<p>
where everything is in one encoding (UTF-8).
<p/>
This issue is not resolved by LWG <a href="lwg-defects.html#3547" title="Time formatters should not be locale sensitive by default (Status: Resolved)">3547</a><sup><a href="https://cplusplus.github.io/LWG/issue3547" title="Latest snapshot">(i)</a></sup> / <a href="https://wg21.link/P2372" title=" Fixing locale handling in chrono formatters">P2372</a> but the resolution proposed here is
compatible with P2372 and can be rebased onto its wording if the paper is adopted.
</p>

<p><i>[2021-06-14; Reflector poll]</i></p>

<p>
Set priority to 2 after reflector poll. Send to SG16.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">

<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>
<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 the locale that is passed to the formatting function if the latter takes one,
or the global locale otherwise. <ins>If the string literal encoding is UTF-8 the replacement of a conversion
specifier that depends on the locale is transcoded to UTF-8 for narrow strings, otherwise the replacement is
taken as is.</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>
</blockquote>

<p><i>[2023-03-22 Resolved by the adoption of <a href="https://wg21.link/P2419R2" title=" Clarify handling of encodings in localized formatting of chrono types">P2419R2</a> in the July 2022 virtual plenary. Status changed: SG16 &rarr; Resolved.]</i></p>



<p id="res-3565"><b>Proposed resolution:</b></p>




</body>
</html>
