Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++20 status.

3270. Parsing and formatting%j withdurations

Section: 30.12[time.format], 30.13[time.parse]Status:C++20Submitter: Howard HinnantOpened: 2019-09-02Last modified: 2021-02-25

Priority:2

View otheractive issues in [time.format].

View all otherissues in [time.format].

View all issues withC++20 status.

Discussion:

%j represents the day number of the year when formatting and parsingtime_points. It is also handy to interpret this flag consistently when formatting and parsing durations. That is if there is not enough information in the stream to represent atime_point, and if the target of the format/parse is aduration,%j represents a number of days.

#include <chrono>#include <iostream>#include <sstream>#include <string>int main(){  using namespace std;  using namespace std::chrono;// Parse %j as number of days into a duration  istringstream in{"222"};  hours d;  in >> parse("%j", d);  cout << d << '\n';  cout << format("{:%j}", d) << '\n';}

Output:

5328h222

[2019-10 Priority set to 2 after reflector discussion]

Previous resolution [SUPERSEDED]:

This wording is relative toN4830.

  1. Modify "Table 98 — Meaning of conversion specifiers" [tab:time.format.spec] as indicated:

    Table 98 — Meaning of conversion specifiers [tab:time.format.spec]
    SpecifierReplacement
    […]
    %jThe day of the year as a decimal number. Jan 1 is001. If the result is less than three
    digits, it is left-padded with0 to three digits.If the type being formatted is a
    specialization ofduration, it is formatted as a decimal number ofdays.
    […]
  2. Modify "Table 99 — Meaning ofparse flags" [tab:time.parse.spec] as indicated:

    Table 99 — Meaning ofparse flags [tab:time.parse.spec]
    FlagParsed value
    […]
    %jThe day of the year as a decimal number. Jan 1 is1. The modified command%Nj
    specifies the maximum number of characters to read. IfN is not specified, the default
    is3. Leading zeroes are permitted but not required.If the type being parsed is a
    specialization ofduration, it is parsed as a decimal number ofdays.
    […]

[2020-02-13 After Thursday afternoon discussion in Prague, Marshall provides updated wording.]

[2020-02 Status to Immediate on Thursday night in Prague.]

Proposed resolution:

This wording is relative toN4830.

  1. Modify "Table 98 — Meaning of conversion specifiers" [tab:time.format.spec] as indicated:

    Table 98 — Meaning of conversion specifiers [tab:time.format.spec]
    SpecifierReplacement
    […]
    %jIf the type being formatted is a specialization ofduration, the decimal number ofdays
    without padding. Otherwise, the
    The day of the year as a decimal number.
    Jan 1 is001. If the result is less than three digits, it is left-padded with0 to three digits.
    […]
  2. Modify "Table 99 — Meaning ofparse flags" [tab:time.parse.spec] as indicated:

    Table 99 — Meaning ofparse flags [tab:time.parse.spec]
    FlagParsed value
    […]
    %jIf the type being parsed is a specialization ofduration,
    a decimal number ofdays. Otherwise, the
    The day of the year as a decimal number. Jan 1 is1.
    In either case, theThe modified command%Nj specifies the maximum number of characters to read.
    IfN is not specified, the default is3. Leading zeroes are permitted but not required.
    […]

[8]ページ先頭

©2009-2025 Movatter.jp