Title
Non-numeric formats for negative durations
Status
open
Section
[time.format]
Submitter
Jonathan Wakely

Created on 2022-12-20.00:00:00 last changed 13 months ago

Messages

Date: 2023-02-10.18:21:41

Proposed resolution:

This wording is relative to N4928.

  1. Modify [time.format] as indicated:

    -4- The result of formatting a std::chrono::duration instance holding a negative value, or an chrono::hh_mm_ss object h for which h.is_negative() is true, is equivalent to the output of the corresponding positive value, with a STATICALLY-WIDEN<charT>("-") character sequence placed before the replacement of the initial first conversion specifier that is one of %H, %I, %M, %S, or %T.

Date: 2023-02-10.18:21:41

[ Issaquah 2023-02-10; LWG issue processing ]

Set priority to 3. Proposed a hybrid resolution.

Previous resolution [SUPERSEDED]:

Two alternatives are presented, choose one of Option A or Option B.
  1. Modify [time.format] as indicated:

    Option A

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

    Option B

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

Date: 2022-12-20.00:00:00

The wording of [time.format] p4 seems to have some unwanted consequences. It says:

The result of formatting a std::chrono::duration instance holding a negative value, or an hh_mm_ss object h for which h.is_negative() is true, is equivalent to the output of the corresponding positive value, with a STATICALLY-WIDEN<charT>("-") character sequence placed before the replacement of the initial conversion specifier.

Taken literally, I think that means:

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

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

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

History
Date User Action Args
2023-02-10 18:21:41adminsetmessages: + msg13340
2023-02-10 18:21:41adminsetstatus: new -> open
2022-12-20 12:57:05adminsetmessages: + msg13166
2022-12-20 00:00:00admincreate