Closed tomaszkam closed 5 years ago
This one is a question of how do these flags react with durations as opposed to time points, and is the existing wording already clear on this point.
Example program:
#include "date/date.h"
#include <iostream>
#include <sstream>
#include <string>
int
main()
{
using namespace date;
using namespace std;
using namespace std::chrono;
// Format
{
// Case 1
// format time_point with %I%p
cout << format("%F %I%p", sys_days{2019_y/August/10}+14h) << '\n';
}
{
// Case 2
// format duration with %I%p
cout << format("%I%p", 14h) << '\n';
}
// Parse
{
// Case 1
// Parse %I%p as day-of-year combined with an hour into a time_point
istringstream in{"2019-08-10 2pm"};
system_clock::time_point tp;
in >> parse("%F %I%p", tp);
cout << tp << '\n';
}
{
// Case 2
// Parse %I%p as number of hours into a duration
istringstream in{"2pm"};
system_clock::duration d;
in >> parse("%I%p", d);
cout << d << '\n';
}
}
Expected output:
2019-08-10 02PM
02PM
2019-08-10 14:00:00.000000
50400000000µs
I struggled with this and the %j
issues because from my reading of wording it is unclear which format/parse specifiers are expected to work with durations and which with time points. But I have little experience with POSIX format spec.
Mailed to LWG chair.
Original comment: