public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/110504] New: std::format("{:%S}", duration<long, std::ratio<1,2>>(4)) returns "02.0" instead of "02"
@ 2023-06-30 16:35 redi at gcc dot gnu.org
  2023-06-30 16:55 ` [Bug libstdc++/110504] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2023-06-30 16:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110504

            Bug ID: 110504
           Summary: std::format("{:%S}", duration<long,
                    std::ratio<1,2>>(4)) returns "02.0" instead of "02"
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

And std::format("{:%M:%S}", duration<long, std::ratio<2, 3>>(99)) returns
"01:06.000000" instead of "01:06"

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/110504] std::format("{:%S}", duration<long, std::ratio<1,2>>(4)) returns "02.0" instead of "02"
  2023-06-30 16:35 [Bug libstdc++/110504] New: std::format("{:%S}", duration<long, std::ratio<1,2>>(4)) returns "02.0" instead of "02" redi at gcc dot gnu.org
@ 2023-06-30 16:55 ` redi at gcc dot gnu.org
  2023-06-30 23:16 ` redi at gcc dot gnu.org
  2023-07-10 14:43 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2023-06-30 16:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110504

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-06-30
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/110504] std::format("{:%S}", duration<long, std::ratio<1,2>>(4)) returns "02.0" instead of "02"
  2023-06-30 16:35 [Bug libstdc++/110504] New: std::format("{:%S}", duration<long, std::ratio<1,2>>(4)) returns "02.0" instead of "02" redi at gcc dot gnu.org
  2023-06-30 16:55 ` [Bug libstdc++/110504] " redi at gcc dot gnu.org
@ 2023-06-30 23:16 ` redi at gcc dot gnu.org
  2023-07-10 14:43 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2023-06-30 23:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110504

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I have a patch to fix this:

--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -1079,7 +1079,9 @@ namespace __format
            {
              locale __loc = _M_locale(__ctx);
              auto __ss = __hms.subseconds();
-             if constexpr (is_floating_point_v<rep>)
+             if (__ss == __ss.zero())
+               ; // Do not write all-zero fractional part.
+             else if constexpr (is_floating_point_v<rep>)
                {
                  __out = std::format_to(__loc, std::move(__out),
                                         _GLIBCXX_WIDEN("{:.{}Lg}"),


However the example in [time.clock.utc.nonmembers] suggests that in fact
printing the zeros is correct. The sys_time<milliseconds> value is printed as
"2015-06-30 23:59:60.000 UTC" which would be altered by the patch above.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/110504] std::format("{:%S}", duration<long, std::ratio<1,2>>(4)) returns "02.0" instead of "02"
  2023-06-30 16:35 [Bug libstdc++/110504] New: std::format("{:%S}", duration<long, std::ratio<1,2>>(4)) returns "02.0" instead of "02" redi at gcc dot gnu.org
  2023-06-30 16:55 ` [Bug libstdc++/110504] " redi at gcc dot gnu.org
  2023-06-30 23:16 ` redi at gcc dot gnu.org
@ 2023-07-10 14:43 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-10 14:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110504

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The current code in libstdc++ is correct here.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-10 14:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-30 16:35 [Bug libstdc++/110504] New: std::format("{:%S}", duration<long, std::ratio<1,2>>(4)) returns "02.0" instead of "02" redi at gcc dot gnu.org
2023-06-30 16:55 ` [Bug libstdc++/110504] " redi at gcc dot gnu.org
2023-06-30 23:16 ` redi at gcc dot gnu.org
2023-07-10 14:43 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).