<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3844: Non-numeric formats for negative durations</title>
<meta property="og:title" content="Issue 3844: Non-numeric formats for negative durations">
<meta property="og:description" content="C++ library issue. Status: Open">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3844.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#Open">Open</a> status.</em></p>
<h3 id="3844"><a href="lwg-active.html#3844">3844</a>. Non-numeric formats for negative durations</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#Open">Open</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2022-12-20 <b>Last modified:</b> 2023-02-10</p>
<p><b>Priority: </b>3
</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#Open">Open</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The wording of 30.12 <a href="https://wg21.link/time.format">[time.format]</a> p4 seems to have some
unwanted consequences. It says:
</p>
<blockquote>
The result of formatting a <code>std::chrono::duration</code> instance holding a
negative value, or an <code>hh_mm_ss</code> object <code>h</code> for which
<code>h.is_negative()</code> is <code>true</code>, is equivalent to the output
of the corresponding positive value,
with a <code><i>STATICALLY-WIDEN</i>&lt;charT&gt;("-")</code>
character sequence placed before the replacement of
the initial conversion specifier.
</blockquote>

<p>
Taken literally, I think that means:
</p>

<blockquote><pre>
format("{:%q}", -1s) == "-s"
format("{:%t%j}", -25h) == "-\t1"
format("{:%p%I}", -11h) == "-am11"
</pre></blockquote>

<p>
The last one probably doesn't matter (what does -11am mean anyway?)
but some of them do matter, for example something like
"<code>{:(%q)%t%Q}"</code> intends to put the unit suffix first in parens
but will print <code>"(-s)\t1"</code> which probably isn't what the user wanted.
</p>

<p>
I think we want to place the sign before the first <u>numeric</u>
conversion specifier, not "the initial conversion specifier".
That is what Howard's <code>date::format</code> and &lt;fmt&gt; both do.
</p>

<p><i>[Issaquah 2023-02-10; LWG issue processing]</i></p>

<p>
Set priority to 3. Proposed a hybrid resolution.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<blockquote class="note">
Two alternatives are presented,
choose one of <b>Option A</b> or <b>Option B</b>.
</blockquote>

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

<p><b>Option A</b></p>

<p>-4-
The result of formatting a <code><del>std::</del>chrono::duration</code>
instance holding a negative value, or a<del>n</del>
<code><ins>chrono::</ins>hh_mm_ss</code> object <code>h</code> for which
<code>h.is_negative()</code> is <code>true</code>,
is equivalent to the output
of the corresponding positive value,
with a <code><i>STATICALLY-WIDEN</i>&lt;charT&gt;("-")</code>
character sequence placed before the replacement of
the <del>initial</del> <ins>first</ins>
conversion specifier
<ins>that is not one of %n, %p, %q, %t, or %%</ins>.
</p>

<p><b>Option B</b></p>

<p>-4-
<ins>Among the specifiers, %H, %I, %M, %S, and %T, the</ins> <del>The</del>
result of formatting a <code><del>std::</del>chrono::duration</code>
instance holding a negative value, or a<del>n</del>
<code><ins>chrono::</ins>hh_mm_ss</code> object <code>h</code> for which
<code>h.is_negative()</code> is <code>true</code>,
is equivalent to the output
of the corresponding positive value,
with a <code><i>STATICALLY-WIDEN</i>&lt;charT&gt;("-")</code>
character sequence placed before the replacement of
the initial conversion specifier.
</p>

</blockquote>
</li>
</ol>
</blockquote>



<p id="res-3844"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4928" title=" Working Draft, Standard for Programming Language C++">N4928</a>.
</p>

<ol>
<li>
<p> Modify 30.12 <a href="https://wg21.link/time.format">[time.format]</a> as indicated: </p>
<blockquote>
<p>-4-
The result of formatting a <code><del>std::</del>chrono::duration</code>
instance holding a negative value, or a<del>n</del>
<code><ins>chrono::</ins>hh_mm_ss</code> object <code>h</code> for which
<code>h.is_negative()</code> is <code>true</code>,
is equivalent to the output
of the corresponding positive value,
with a <code><i>STATICALLY-WIDEN</i>&lt;charT&gt;("-")</code>
character sequence placed before the replacement of
the <del>initial</del> <ins>first</ins>
conversion specifier
<ins>that is one of %H, %I, %M, %S, or %T</ins>.
</p>
</blockquote>
</li>
</ol>






</body>
</html>
