This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Open status.

3844. Non-numeric formats for negative durations

Section: 29.12 [time.format] Status: Open Submitter: Jonathan Wakely Opened: 2022-12-20 Last modified: 2023-02-10

Priority: 3

View other active issues in [time.format].

View all other issues in [time.format].

View all issues with Open status.

Discussion:

The wording of 29.12 [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.

[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 29.12 [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.

Proposed resolution:

This wording is relative to N4928.

  1. Modify 29.12 [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.