Title
Parsing and formatting %j with durations
Status
immediate
Section
[time.format][time.parse]
Submitter
Howard Hinnant

Created on 2019-09-02.00:00:00 last changed 3 days ago

Messages

Date: 2020-02-14.07:30:42

Proposed resolution:

This wording is relative to N4830.

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

    Table 98 — Meaning of conversion specifiers [tab:time.format.spec]
    Specifier Replacement
    […]
    %j If the type being formatted is a specialization of duration, the decimal number of days
    without padding. Otherwise, the
    The day of the year as a decimal number.
    Jan 1 is 001. If the result is less than three digits, it is left-padded with 0 to three digits.
    […]
  2. Modify "Table 99 — Meaning of parse flags" [tab:time.parse.spec] as indicated:

    Table 99 — Meaning of parse flags [tab:time.parse.spec]
    Flag Parsed value
    […]
    %j If the type being parsed is a specialization of duration,
    a decimal number of days. Otherwise, the
    The day of the year as a decimal number. Jan 1 is 1.
    In either case, theThe modified command %Nj specifies the maximum number of characters to read.
    If N is not specified, the default is 3. Leading zeroes are permitted but not required.
    […]
Date: 2020-02-14.07:30:42

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

Date: 2020-02-13.00:00:00

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

Date: 2020-02-13.18:06:22

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

Previous resolution [SUPERSEDED]:

This wording is relative to N4830.

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

    Table 98 — Meaning of conversion specifiers [tab:time.format.spec]
    Specifier Replacement
    […]
    %j The day of the year as a decimal number. Jan 1 is 001. If the result is less than three
    digits, it is left-padded with 0 to three digits. If the type being formatted is a
    specialization of duration, it is formatted as a decimal number of days.
    […]
  2. Modify "Table 99 — Meaning of parse flags" [tab:time.parse.spec] as indicated:

    Table 99 — Meaning of parse flags [tab:time.parse.spec]
    Flag Parsed value
    […]
    %j The day of the year as a decimal number. Jan 1 is 1. The modified command %Nj
    specifies the maximum number of characters to read. If N is not specified, the default
    is 3. Leading zeroes are permitted but not required. If the type being parsed is a
    specialization of duration, it is parsed as a decimal number of days.
    […]
Date: 2019-09-02.00:00:00

%j represents the day number of the year when formatting and parsing time_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 a time_point, and if the target of the format/parse is a duration, %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:

5328h
222
History
Date User Action Args
2020-02-14 07:30:42adminsetmessages: + msg11095
2020-02-14 07:30:42adminsetstatus: new -> immediate
2020-02-13 18:06:22adminsetmessages: + msg11074
2019-10-07 02:21:30adminsetmessages: + msg10677
2019-09-14 10:25:21adminsetmessages: + msg10601
2019-09-02 00:00:00admincreate