public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/110719] New: Should chrono formatters always use std::time_put for locale's representation?
@ 2023-07-18 14:43 redi at gcc dot gnu.org
  2023-07-19 10:13 ` [Bug libstdc++/110719] " redi at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-18 14:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110719
           Summary: Should chrono formatters always use std::time_put for
                    locale's representation?
           Product: gcc
           Version: 13.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

auto t = std::chrono::system_clock::now();
  auto loc = std::locale::classic();
  std::cout << std::format(loc, "{:%EX %OS}\n", t);

This prints something like:

14:30:46.809059031 46

The %EX output is produced by calling std::format again with a format string
based on the locale's D_FMT, which for the C locale is something like:
%H:%M:%S. And using std::format("{:%H:%M:%S}", t) prints fractional seconds for
the %S part.

The %OS output is produced by calling std::time_put::put with the %OS format
string and a struct tm with tm_sec set to the integer number of seconds. This
doesn't print the fractional part.

If chrono::parse("%EX", t) uses std::time_get then this presents a problem for
round-tripping, as the formatted output will have fractional seconds, but the
parsed input will not consume that fractional part.

Should we consistently use std::time_put for all locale-specific output?
Alternatively, we could use time_point_cast and duration_cast to round to
seconds. None of the locale-specific formats print fractional seconds.

It would be useful to profile std::format with and without std::time_get, to
see if reusing std::format performs better. If it doesn't, using std::time_put
might be simpler.

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

* [Bug libstdc++/110719] Should chrono formatters always use std::time_put for locale's representation?
  2023-07-18 14:43 [Bug libstdc++/110719] New: Should chrono formatters always use std::time_put for locale's representation? redi at gcc dot gnu.org
@ 2023-07-19 10:13 ` redi at gcc dot gnu.org
  2023-07-19 10:37 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-19 10:13 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-07-19
             Status|UNCONFIRMED                 |ASSIGNED
   Target Milestone|---                         |13.3
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org

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

* [Bug libstdc++/110719] Should chrono formatters always use std::time_put for locale's representation?
  2023-07-18 14:43 [Bug libstdc++/110719] New: Should chrono formatters always use std::time_put for locale's representation? redi at gcc dot gnu.org
  2023-07-19 10:13 ` [Bug libstdc++/110719] " redi at gcc dot gnu.org
@ 2023-07-19 10:37 ` redi at gcc dot gnu.org
  2023-07-19 11:37 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-19 10:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #0)
> It would be useful to profile std::format with and without std::time_get, to

s/time_get/time_put/

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

* [Bug libstdc++/110719] Should chrono formatters always use std::time_put for locale's representation?
  2023-07-18 14:43 [Bug libstdc++/110719] New: Should chrono formatters always use std::time_put for locale's representation? redi at gcc dot gnu.org
  2023-07-19 10:13 ` [Bug libstdc++/110719] " redi at gcc dot gnu.org
  2023-07-19 10:37 ` redi at gcc dot gnu.org
@ 2023-07-19 11:37 ` cvs-commit at gcc dot gnu.org
  2023-07-19 11:39 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-19 11:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:f4bce119f617dc4663fb43f55784908daf16b4b6

commit r14-2640-gf4bce119f617dc4663fb43f55784908daf16b4b6
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jul 18 12:46:07 2023 +0100

    libstdc++: Implement correct locale-specific chrono formatting [PR110719]

    This fixes some TODOs in the C++20 <chrono> format support, where the
    locale-specific output was incorrect or unimplemented. The approach
    taken here is to either use the formatting locale's std::time_put facet
    to do the formatting, or to remove subsecond precision from time points
    so that locale-specific formats don't print fractional seconds. This
    ensures that we are consistent with what the std::time_put facet would
    print (which never includes fractional seconds) even if we actually
    reimplement the formatting by hand instead of using the facet.

    This also fixes a misplaced statement that allowed modifiers for %Z
    which should have been on %z instead. There was also some ill-formed
    code in an untested branch for formatting time zone names to wide
    characters. A new test for zoned_time I/O has been added to exercise
    that code properly.

    libstdc++-v3/ChangeLog:

            PR libstdc++/110719
            * include/bits/chrono_io.h (__formatter_chrono::_M_parse): Fix
            allowed modifiers for %z and %Z. Fix -Wparentheses and
            -Wnarrowing warnings.
            (__formatter_chrono::_M_format): Call new functions for %d, %e,
            %H, %I, %m and %M.
            (__formatter_chrono::_M_c): Use _S_floor_seconds to remove
            subsecond precision.
            (__formatter_chrono::_M_C_y_Y): Use _M_locale_fmt to handle
            modifiers.
            (__formatter_chrono::_M_e): Replace with _M_d_e and use
            _M_locale_fmt.
            (__formatter_chrono::_M_I): Replace with _M_H_I and use
            _M_locale_fmt.
            (__formatter_chrono::_M_m): New function.
            (__formatter_chrono::_M_M): New function.
            (__formatter_chrono::_M_r): Use _M_locale_fmt.
            (__formatter_chrono::_M_S): Likewise.
            (__formatter_chrono::_M_u_w): Likewise.
            (__formatter_chrono::_M_U_V_W): Likewise.
            (__formatter_chrono::_M_X): Use _S_floor_seconds.
            (__formatter_chrono::_M_Z): Fix untested branch for wchar_t.
            (__formatter_chrono::_S_altnum): Remove function.
            (__formatter_chrono::_S_dd_zero_fill): Remove function.
            (__formatter_chrono::_S_floor_seconds): New function.
            (__formatter_chrono::_M_locale_fmt): New function.
            * testsuite/std/time/clock/system/io.cc: Adjust expected output
            for locale-specific formats and check modified formats.
            * testsuite/std/time/clock/utc/io.cc: Likewise.
            * testsuite/std/time/zoned_time/io.cc: New test.

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

* [Bug libstdc++/110719] Should chrono formatters always use std::time_put for locale's representation?
  2023-07-18 14:43 [Bug libstdc++/110719] New: Should chrono formatters always use std::time_put for locale's representation? redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-07-19 11:37 ` cvs-commit at gcc dot gnu.org
@ 2023-07-19 11:39 ` redi at gcc dot gnu.org
  2023-07-19 15:51 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-19 11:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #0)
> Should we consistently use std::time_put for all locale-specific output?
> Alternatively, we could use time_point_cast and duration_cast to round to
> seconds. None of the locale-specific formats print fractional seconds.

This has now been implemented on trunk.

> It would be useful to profile std::format with and without std::time_get, to
> see if reusing std::format performs better. If it doesn't, using
> std::time_put might be simpler.

This profiling would still be useful.

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

* [Bug libstdc++/110719] Should chrono formatters always use std::time_put for locale's representation?
  2023-07-18 14:43 [Bug libstdc++/110719] New: Should chrono formatters always use std::time_put for locale's representation? redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-07-19 11:39 ` redi at gcc dot gnu.org
@ 2023-07-19 15:51 ` cvs-commit at gcc dot gnu.org
  2023-07-28 17:32 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-19 15:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:86b36e9f7e3839e923db2fda4962cd3faf2ea47b

commit r14-2646-g86b36e9f7e3839e923db2fda4962cd3faf2ea47b
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Jul 19 14:38:08 2023 +0100

    libstdc++: Fix locale-specific duration formatting [PR110719]

    The r14-2640-gf4bce119f617dc commit only removed fractional seconds for
    time points, but it needs to be done for durations and hh_mm_ss types
    too.

    libstdc++-v3/ChangeLog:

            PR libstdc++/110719
            * include/bits/chrono_io.h (__formatter_chrono::_S_floor_seconds):
            Handle duration and hh_mm_ss.
            * testsuite/20_util/duration/io.cc: Check locale-specific
            formats.
            * testsuite/std/time/hh_mm_ss/io.cc: Likewise.

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

* [Bug libstdc++/110719] Should chrono formatters always use std::time_put for locale's representation?
  2023-07-18 14:43 [Bug libstdc++/110719] New: Should chrono formatters always use std::time_put for locale's representation? redi at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-07-19 15:51 ` cvs-commit at gcc dot gnu.org
@ 2023-07-28 17:32 ` cvs-commit at gcc dot gnu.org
  2023-07-28 17:32 ` cvs-commit at gcc dot gnu.org
  2023-07-28 18:59 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-28 17:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:cb01a31ab2779b0252c4945924ba2163d9150642

commit r13-7630-gcb01a31ab2779b0252c4945924ba2163d9150642
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jul 18 12:46:07 2023 +0100

    libstdc++: Implement correct locale-specific chrono formatting [PR110719]

    This fixes some TODOs in the C++20 <chrono> format support, where the
    locale-specific output was incorrect or unimplemented. The approach
    taken here is to either use the formatting locale's std::time_put facet
    to do the formatting, or to remove subsecond precision from time points
    so that locale-specific formats don't print fractional seconds. This
    ensures that we are consistent with what the std::time_put facet would
    print (which never includes fractional seconds) even if we actually
    reimplement the formatting by hand instead of using the facet.

    This also fixes a misplaced statement that allowed modifiers for %Z
    which should have been on %z instead. There was also some ill-formed
    code in an untested branch for formatting time zone names to wide
    characters. A new test for zoned_time I/O has been added to exercise
    that code properly.

    libstdc++-v3/ChangeLog:

            PR libstdc++/110719
            * include/bits/chrono_io.h (__formatter_chrono::_M_parse): Fix
            allowed modifiers for %z and %Z. Fix -Wparentheses and
            -Wnarrowing warnings.
            (__formatter_chrono::_M_format): Call new functions for %d, %e,
            %H, %I, %m and %M.
            (__formatter_chrono::_M_c): Use _S_floor_seconds to remove
            subsecond precision.
            (__formatter_chrono::_M_C_y_Y): Use _M_locale_fmt to handle
            modifiers.
            (__formatter_chrono::_M_e): Replace with _M_d_e and use
            _M_locale_fmt.
            (__formatter_chrono::_M_I): Replace with _M_H_I and use
            _M_locale_fmt.
            (__formatter_chrono::_M_m): New function.
            (__formatter_chrono::_M_M): New function.
            (__formatter_chrono::_M_r): Use _M_locale_fmt.
            (__formatter_chrono::_M_S): Likewise.
            (__formatter_chrono::_M_u_w): Likewise.
            (__formatter_chrono::_M_U_V_W): Likewise.
            (__formatter_chrono::_M_X): Use _S_floor_seconds.
            (__formatter_chrono::_M_Z): Fix untested branch for wchar_t.
            (__formatter_chrono::_S_altnum): Remove function.
            (__formatter_chrono::_S_dd_zero_fill): Remove function.
            (__formatter_chrono::_S_floor_seconds): New function.
            (__formatter_chrono::_M_locale_fmt): New function.
            * testsuite/std/time/clock/system/io.cc: Adjust expected output
            for locale-specific formats and check modified formats.
            * testsuite/std/time/clock/utc/io.cc: Likewise.
            * testsuite/std/time/zoned_time/io.cc: New test.

    (cherry picked from commit f4bce119f617dc4663fb43f55784908daf16b4b6)

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

* [Bug libstdc++/110719] Should chrono formatters always use std::time_put for locale's representation?
  2023-07-18 14:43 [Bug libstdc++/110719] New: Should chrono formatters always use std::time_put for locale's representation? redi at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-07-28 17:32 ` cvs-commit at gcc dot gnu.org
@ 2023-07-28 17:32 ` cvs-commit at gcc dot gnu.org
  2023-07-28 18:59 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-28 17:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:24c352c41eb944d29b09f33a42662efad3f6f811

commit r13-7631-g24c352c41eb944d29b09f33a42662efad3f6f811
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Jul 19 14:38:08 2023 +0100

    libstdc++: Fix locale-specific duration formatting [PR110719]

    The r14-2640-gf4bce119f617dc commit only removed fractional seconds for
    time points, but it needs to be done for durations and hh_mm_ss types
    too.

    libstdc++-v3/ChangeLog:

            PR libstdc++/110719
            * include/bits/chrono_io.h (__formatter_chrono::_S_floor_seconds):
            Handle duration and hh_mm_ss.
            * testsuite/20_util/duration/io.cc: Check locale-specific
            formats.
            * testsuite/std/time/hh_mm_ss/io.cc: Likewise.

    (cherry picked from commit 86b36e9f7e3839e923db2fda4962cd3faf2ea47b)

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

* [Bug libstdc++/110719] Should chrono formatters always use std::time_put for locale's representation?
  2023-07-18 14:43 [Bug libstdc++/110719] New: Should chrono formatters always use std::time_put for locale's representation? redi at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-07-28 17:32 ` cvs-commit at gcc dot gnu.org
@ 2023-07-28 18:59 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-28 18:59 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 13.3

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

end of thread, other threads:[~2023-07-28 19:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18 14:43 [Bug libstdc++/110719] New: Should chrono formatters always use std::time_put for locale's representation? redi at gcc dot gnu.org
2023-07-19 10:13 ` [Bug libstdc++/110719] " redi at gcc dot gnu.org
2023-07-19 10:37 ` redi at gcc dot gnu.org
2023-07-19 11:37 ` cvs-commit at gcc dot gnu.org
2023-07-19 11:39 ` redi at gcc dot gnu.org
2023-07-19 15:51 ` cvs-commit at gcc dot gnu.org
2023-07-28 17:32 ` cvs-commit at gcc dot gnu.org
2023-07-28 17:32 ` cvs-commit at gcc dot gnu.org
2023-07-28 18:59 ` 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).