4809to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
4811 const std::chrono::seconds* offset_sec)
4814 using detail::weekday_names;
4815 using detail::month_names;
4816 using detail::ampm_names;
4823 using std::chrono::duration_cast;
4824 using std::chrono::seconds;
4825 using std::chrono::minutes;
4826 using std::chrono::hours;
4829 os.flags(std::ios::skipws | std::ios::dec);
4832 bool insert_negative = fds.
has_tod && fds.
tod.to_duration() < Duration::zero();
4834 auto& facet = std::use_facet<std::time_put<CharT>>(os.getloc());
4836 const CharT* command =
nullptr;
4837 CharT modified = CharT{};
4846 if (modified == CharT{})
4848 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
4852 const CharT f[] = {
'%', *fmt};
4853 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
4855 os << weekday_names().first[tm.tm_wday+7*(*fmt ==
'a')];
4860 os << CharT{
'%'} << modified << *fmt;
4873 if (modified == CharT{})
4875 tm.tm_mon =
static_cast<int>(extract_month(os, fds)) - 1;
4877 const CharT f[] = {
'%', *fmt};
4878 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
4880 os << month_names().first[tm.tm_mon+12*(*fmt !=
'B')];
4885 os << CharT{
'%'} << modified << *fmt;
4897 if (modified == CharT{
'O'})
4898 os << CharT{
'%'} << modified << *fmt;
4902 os.setstate(std::ios::failbit);
4903 if (*fmt ==
'c' && !fds.
has_tod)
4904 os.setstate(std::ios::failbit);
4907 auto const& ymd = fds.
ymd;
4911 tm.tm_sec =
static_cast<int>(fds.
tod.seconds().count());
4912 tm.tm_min =
static_cast<int>(fds.
tod.minutes().count());
4913 tm.tm_hour =
static_cast<int>(fds.
tod.hours().count());
4915 tm.tm_mday =
static_cast<int>(
static_cast<unsigned>(ymd.day()));
4916 tm.tm_mon =
static_cast<int>(extract_month(os, fds) - 1);
4917 tm.tm_year =
static_cast<int>(ymd.year()) - 1900;
4918 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
4921 tm.tm_yday =
static_cast<int>((ld -
local_days(ymd.year()/1/1)).count());
4923 auto fe = std::begin(f) + 1;
4924 if (modified == CharT{
'E'})
4927 facet.put(os, os, os.fill(), &tm, std::begin(f), fe);
4931 auto wd =
static_cast<int>(extract_weekday(os, fds));
4932 os << weekday_names().first[
static_cast<unsigned>(wd)+7]
4934 os << month_names().first[extract_month(os, fds)-1+12] <<
' ';
4935 auto d =
static_cast<int>(
static_cast<unsigned>(fds.
ymd.
day()));
4939 <<
make_time(duration_cast<seconds>(fds.
tod.to_duration()))
4945 auto const& ymd = fds.
ymd;
4946 save_ostream<CharT, Traits> _(os);
4948 os.flags(std::ios::dec | std::ios::right);
4950 os << static_cast<unsigned>(ymd.month()) << CharT{
'/'};
4952 os << static_cast<unsigned>(ymd.day()) << CharT{
'/'};
4954 os << static_cast<int>(ymd.year()) % 100;
4967 if (modified == CharT{
'O'})
4968 os << CharT{
'%'} << modified << *fmt;
4972 os.setstate(std::ios::failbit);
4973 auto y =
static_cast<int>(fds.
ymd.
year());
4975 if (modified == CharT{})
4978 save_ostream<CharT, Traits> _(os);
4980 os.flags(std::ios::dec | std::ios::right);
4994 else if (modified == CharT{
'E'})
4996 tm.tm_year = y - 1900;
4997 CharT f[3] = {
'%',
'E',
'C'};
4998 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5012 if (modified == CharT{
'E'})
5013 os << CharT{
'%'} << modified << *fmt;
5017 os.setstate(std::ios::failbit);
5018 auto d =
static_cast<int>(
static_cast<unsigned>(fds.
ymd.
day()));
5020 if (modified == CharT{})
5023 save_ostream<CharT, Traits> _(os);
5024 if (*fmt == CharT{
'd'})
5028 os.flags(std::ios::dec | std::ios::right);
5033 else if (modified == CharT{
'O'})
5036 CharT f[3] = {
'%',
'O', *fmt};
5037 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5050 if (modified == CharT{})
5053 os.setstate(std::ios::failbit);
5054 auto const& ymd = fds.
ymd;
5055 save_ostream<CharT, Traits> _(os);
5057 os.flags(std::ios::dec | std::ios::right);
5059 os << static_cast<unsigned>(ymd.month()) << CharT{
'/'};
5061 os << static_cast<unsigned>(ymd.day()) << CharT{
'/'};
5063 os << static_cast<int>(ymd.year()) % 100;
5067 os << CharT{
'%'} << modified << *fmt;
5078 if (modified == CharT{})
5081 os.setstate(std::ios::failbit);
5082 auto const& ymd = fds.
ymd;
5083 save_ostream<CharT, Traits> _(os);
5084 os.imbue(std::locale::classic());
5086 os.flags(std::ios::dec | std::ios::right);
5088 os << static_cast<int>(ymd.year()) << CharT{
'-'};
5090 os << static_cast<unsigned>(ymd.month()) << CharT{
'-'};
5092 os << static_cast<unsigned>(ymd.day());
5096 os << CharT{
'%'} << modified << *fmt;
5108 if (modified == CharT{})
5111 os.setstate(std::ios::failbit);
5118 if (*fmt == CharT{
'G'})
5122 save_ostream<CharT, Traits> _(os);
5124 os.flags(std::ios::dec | std::ios::right);
5126 os << std::abs(static_cast<int>(y)) % 100;
5131 os << CharT{
'%'} << modified << *fmt;
5143 if (modified == CharT{
'E'})
5144 os << CharT{
'%'} << modified << *fmt;
5148 os.setstate(std::ios::failbit);
5149 if (insert_negative)
5152 insert_negative =
false;
5156 if (modified == CharT{})
5159 auto h = *fmt == CharT{
'I'} ?
date::make12(hms.hours()) : hms.hours();
5165 else if (modified == CharT{
'O'})
5167 const CharT f[] = {
'%', modified, *fmt};
5168 tm.tm_hour =
static_cast<int>(hms.hours().count());
5169 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5182 if (modified == CharT{})
5195 doy = duration_cast<days>(fds.
tod.to_duration());
5197 save_ostream<CharT, Traits> _(os);
5199 os.flags(std::ios::dec | std::ios::right);
5205 os.setstate(std::ios::failbit);
5210 os << CharT{
'%'} << modified << *fmt;
5221 if (modified == CharT{
'E'})
5222 os << CharT{
'%'} << modified << *fmt;
5226 os.setstate(std::ios::failbit);
5227 auto m =
static_cast<unsigned>(fds.
ymd.
month());
5229 if (modified == CharT{})
5237 else if (modified == CharT{
'O'})
5239 const CharT f[] = {
'%', modified, *fmt};
5240 tm.tm_mon =
static_cast<int>(m-1);
5241 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5254 if (modified == CharT{
'E'})
5255 os << CharT{
'%'} << modified << *fmt;
5259 os.setstate(std::ios::failbit);
5260 if (insert_negative)
5263 insert_negative =
false;
5266 if (modified == CharT{})
5269 if (fds.
tod.minutes() < minutes{10})
5271 os << fds.
tod.minutes().count();
5274 else if (modified == CharT{
'O'})
5276 const CharT f[] = {
'%', modified, *fmt};
5277 tm.tm_min =
static_cast<int>(fds.
tod.minutes().count());
5278 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5291 if (modified == CharT{})
5295 os << CharT{
'%'} << modified << *fmt;
5306 if (modified == CharT{})
5309 os.setstate(std::ios::failbit);
5311 const CharT f[] = {
'%', *fmt};
5312 tm.tm_hour =
static_cast<int>(fds.
tod.hours().count());
5313 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5316 os << ampm_names().first[0];
5318 os << ampm_names().first[1];
5323 os << CharT{
'%'} << modified << *fmt;
5335 if (modified == CharT{})
5338 os.setstate(std::ios::failbit);
5339 auto d = fds.
tod.to_duration();
5341 os << get_units<CharT>(
typename decltype(d)::period::type{});
5347 os << CharT{
'%'} << modified << *fmt;
5358 if (modified == CharT{})
5361 os.setstate(std::ios::failbit);
5363 const CharT f[] = {
'%', *fmt};
5364 tm.tm_hour =
static_cast<int>(fds.
tod.hours().count());
5365 tm.tm_min =
static_cast<int>(fds.
tod.minutes().count());
5366 tm.tm_sec =
static_cast<int>(fds.
tod.seconds().count());
5367 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5370 save_ostream<CharT, Traits> _(os);
5375 os << tod.
minutes().count() << CharT{
':'};
5377 os << tod.
seconds().count() << CharT{
' '};
5379 os << ampm_names().first[0];
5381 os << ampm_names().first[1];
5386 os << CharT{
'%'} << modified << *fmt;
5397 if (modified == CharT{})
5400 os.setstate(std::ios::failbit);
5401 if (fds.
tod.hours() < hours{10})
5403 os << fds.
tod.hours().count() << CharT{
':'};
5404 if (fds.
tod.minutes() < minutes{10})
5406 os << fds.
tod.minutes().count();
5410 os << CharT{
'%'} << modified << *fmt;
5421 if (modified == CharT{
'E'})
5422 os << CharT{
'%'} << modified << *fmt;
5426 os.setstate(std::ios::failbit);
5427 if (insert_negative)
5430 insert_negative =
false;
5433 if (modified == CharT{})
5439 else if (modified == CharT{
'O'})
5441 const CharT f[] = {
'%', modified, *fmt};
5442 tm.tm_sec =
static_cast<int>(fds.
tod.s_.seconds().count());
5443 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5456 if (modified == CharT{})
5460 os << CharT{
'%'} << modified << *fmt;
5471 if (modified == CharT{})
5474 os.setstate(std::ios::failbit);
5479 os << CharT{
'%'} << modified << *fmt;
5490 if (modified == CharT{
'E'})
5491 os << CharT{
'%'} << modified << *fmt;
5494 auto wd = extract_weekday(os, fds);
5496 if (modified == CharT{})
5499 os << (wd != 0 ? wd : 7u);
5502 else if (modified == CharT{
'O'})
5504 const CharT f[] = {
'%', modified, *fmt};
5505 tm.tm_wday =
static_cast<int>(wd);
5506 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5519 if (modified == CharT{
'E'})
5520 os << CharT{
'%'} << modified << *fmt;
5523 auto const& ymd = fds.
ymd;
5525 os.setstate(std::ios::failbit);
5528 if (modified == CharT{})
5533 os << CharT{
'0'} << CharT{
'0'};
5536 auto wn = duration_cast<weeks>(ld - st).count() + 1;
5543 else if (modified == CharT{
'O'})
5545 const CharT f[] = {
'%', modified, *fmt};
5546 tm.tm_year =
static_cast<int>(ymd.year()) - 1900;
5547 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
5550 tm.tm_yday =
static_cast<int>((ld -
local_days(ymd.year()/1/1)).count());
5551 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5564 if (modified == CharT{
'E'})
5565 os << CharT{
'%'} << modified << *fmt;
5569 os.setstate(std::ios::failbit);
5572 if (modified == CharT{})
5584 auto wn = duration_cast<weeks>(ld - st).count() + 1;
5590 else if (modified == CharT{
'O'})
5592 const CharT f[] = {
'%', modified, *fmt};
5593 auto const& ymd = fds.
ymd;
5594 tm.tm_year =
static_cast<int>(ymd.year()) - 1900;
5595 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
5598 tm.tm_yday =
static_cast<int>((ld -
local_days(ymd.year()/1/1)).count());
5599 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5612 auto wd = extract_weekday(os, fds);
5616 if (modified == CharT{})
5618 if (modified != CharT{
'E'})
5624 else if (modified == CharT{
'O'})
5626 const CharT f[] = {
'%', modified, *fmt};
5627 tm.tm_wday =
static_cast<int>(wd);
5628 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5633 os << CharT{
'%'} << modified << *fmt;
5644 if (modified == CharT{
'E'})
5645 os << CharT{
'%'} << modified << *fmt;
5648 auto const& ymd = fds.
ymd;
5650 os.setstate(std::ios::failbit);
5653 if (modified == CharT{})
5658 os << CharT{
'0'} << CharT{
'0'};
5661 auto wn = duration_cast<weeks>(ld - st).count() + 1;
5668 else if (modified == CharT{
'O'})
5670 const CharT f[] = {
'%', modified, *fmt};
5671 tm.tm_year =
static_cast<int>(ymd.year()) - 1900;
5672 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
5675 tm.tm_yday =
static_cast<int>((ld -
local_days(ymd.year()/1/1)).count());
5676 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5689 if (modified == CharT{
'O'})
5690 os << CharT{
'%'} << modified << *fmt;
5694 os.setstate(std::ios::failbit);
5697 tm.tm_sec =
static_cast<int>(fds.
tod.seconds().count());
5698 tm.tm_min =
static_cast<int>(fds.
tod.minutes().count());
5699 tm.tm_hour =
static_cast<int>(fds.
tod.hours().count());
5701 auto fe = std::begin(f) + 1;
5702 if (modified == CharT{
'E'})
5705 facet.put(os, os, os.fill(), &tm, std::begin(f), fe);
5720 os.setstate(std::ios::failbit);
5721 auto y =
static_cast<int>(fds.
ymd.
year());
5723 if (modified == CharT{})
5726 y = std::abs(y) % 100;
5734 const CharT f[] = {
'%', modified, *fmt};
5735 tm.tm_year = y - 1900;
5736 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5748 if (modified == CharT{
'O'})
5749 os << CharT{
'%'} << modified << *fmt;
5753 os.setstate(std::ios::failbit);
5756 if (modified == CharT{})
5759 save_ostream<CharT, Traits> _(os);
5760 os.imbue(std::locale::classic());
5764 else if (modified == CharT{
'E'})
5766 const CharT f[] = {
'%', modified, *fmt};
5767 tm.tm_year =
static_cast<int>(y) - 1900;
5768 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5781 if (offset_sec ==
nullptr)
5784 os.setstate(ios::failbit);
5787 auto m = duration_cast<minutes>(*offset_sec);
5788 auto neg = m < minutes{0};
5790 auto h = duration_cast<hours>(m);
5799 if (modified != CharT{})
5801 if (m < minutes{10})
5813 if (modified == CharT{})
5815 if (abbrev ==
nullptr)
5818 os.setstate(ios::failbit);
5821 for (
auto c : *abbrev)
5826 os << CharT{
'%'} << modified << *fmt;
5838 if (modified == CharT{})
5844 os << CharT{
'%'} << modified << *fmt;
5855 if (modified == CharT{})
5862 os << CharT{
'%'} << modified << CharT{
'%'};
5876 if (modified != CharT{})
5887 if (modified != CharT{})
6308 std::chrono::minutes* offset)
6310 using std::numeric_limits;
6312 using std::chrono::duration;
6313 using std::chrono::duration_cast;
6314 using std::chrono::seconds;
6315 using std::chrono::minutes;
6316 using std::chrono::hours;
6317 typename std::basic_istream<CharT, Traits>::sentry ok{is,
true};
6322 is.flags(std::ios::skipws | std::ios::dec);
6325 auto& f = std::use_facet<std::time_get<CharT>>(is.getloc());
6328 const CharT* command =
nullptr;
6329 auto modified = CharT{};
6332 CONSTDATA int not_a_year = numeric_limits<int>::min();
6334 CONSTDATA int not_a_century = not_a_year / 100;
6337 CONSTDATA int not_a_hour = numeric_limits<int>::min();
6339 CONSTDATA int not_a_minute = not_a_hour;
6340 CONSTDATA Duration not_a_second = Duration::min();
6345 CONSTDATA minutes not_a_offset = minutes::min();
6348 int y = not_a_2digit_year;
6349 int g = not_a_2digit_year;
6351 int C = not_a_century;
6352 int m = not_a_month;
6355 int wd = not_a_weekday;
6357 int I = not_a_hour_12_value;
6359 int M = not_a_minute;
6360 Duration s = not_a_second;
6361 int U = not_a_week_num;
6362 int V = not_a_week_num;
6363 int W = not_a_week_num;
6364 std::basic_string<CharT, Traits, Alloc> temp_abbrev;
6365 minutes temp_offset = not_a_offset;
6372 for (; *fmt != CharT{} && !is.fail(); ++fmt)
6382 int trial_wd = not_a_weekday;
6383 if (*fmt ==
'a' || *fmt ==
'A')
6385 if (modified == CharT{})
6388 ios::iostate err = ios::goodbit;
6389 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6392 trial_wd = tm.tm_wday;
6394 auto nm = detail::weekday_names();
6395 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6401 read(is, CharT{
'%'}, width, modified, *fmt);
6406 if (modified == CharT{})
6408 if (modified != CharT{
'E'})
6411 read(is, ru{trial_wd, 1, width == -1 ?
6412 1u :
static_cast<unsigned>(width)});
6417 if (!(1 <= trial_wd && trial_wd <= 7))
6419 trial_wd = not_a_weekday;
6420 is.setstate(ios::failbit);
6422 else if (trial_wd == 7)
6427 if (!(0 <= trial_wd && trial_wd <= 6))
6429 trial_wd = not_a_weekday;
6430 is.setstate(ios::failbit);
6436 else if (modified == CharT{
'O'})
6438 ios::iostate err = ios::goodbit;
6439 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6442 trial_wd = tm.tm_wday;
6446 read(is, CharT{
'%'}, width, modified, *fmt);
6448 if (trial_wd != not_a_weekday)
6449 checked_set(wd, trial_wd, not_a_weekday, is);
6462 if (modified == CharT{})
6464 int ttm = not_a_month;
6466 ios::iostate err = ios::goodbit;
6467 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6468 if ((err & ios::failbit) == 0)
6469 ttm = tm.tm_mon + 1;
6472 auto nm = detail::month_names();
6473 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6477 checked_set(m, ttm, not_a_month, is);
6480 read(is, CharT{
'%'}, width, modified, *fmt);
6491 if (modified != CharT{
'O'})
6494 ios::iostate err = ios::goodbit;
6495 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6496 if ((err & ios::failbit) == 0)
6498 checked_set(Y, tm.tm_year + 1900, not_a_year, is);
6499 checked_set(m, tm.tm_mon + 1, not_a_month, is);
6500 checked_set(d, tm.tm_mday, not_a_day, is);
6501 checked_set(H, tm.tm_hour, not_a_hour, is);
6502 checked_set(M, tm.tm_min, not_a_minute, is);
6503 checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
6509 auto nm = detail::weekday_names();
6510 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6511 checked_set(wd,
static_cast<int>(i % 7), not_a_weekday, is);
6513 nm = detail::month_names();
6514 i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6515 checked_set(m,
static_cast<int>(i % 12 + 1), not_a_month, is);
6518 read(is, rs{td, 1, 2});
6519 checked_set(d, td, not_a_day, is);
6522 CONSTDATA auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
6526 read(is, ru{tH, 1, 2}, CharT{
':'}, ru{tM, 1, 2},
6527 CharT{
':'}, rld{S, 1, w});
6528 checked_set(H, tH, not_a_hour, is);
6529 checked_set(M, tM, not_a_minute, is);
6533 int tY = not_a_year;
6534 read(is, rs{tY, 1, 4u});
6535 checked_set(Y, tY, not_a_year, is);
6539 read(is, CharT{
'%'}, width, modified, *fmt);
6550 if (modified != CharT{
'O'})
6553 ios::iostate err = ios::goodbit;
6554 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6555 if ((err & ios::failbit) == 0)
6557 checked_set(Y, tm.tm_year + 1900, not_a_year, is);
6558 checked_set(m, tm.tm_mon + 1, not_a_month, is);
6559 checked_set(d, tm.tm_mday, not_a_day, is);
6564 int ty = not_a_2digit_year;
6565 int tm = not_a_month;
6567 read(is, ru{tm, 1, 2}, CharT{
'/'}, ru{td, 1, 2}, CharT{
'/'},
6569 checked_set(y, ty, not_a_2digit_year, is);
6570 checked_set(m, tm, not_a_month, is);
6571 checked_set(d, td, not_a_day, is);
6575 read(is, CharT{
'%'}, width, modified, *fmt);
6586 if (modified != CharT{
'O'})
6589 ios::iostate err = ios::goodbit;
6590 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6591 if ((err & ios::failbit) == 0)
6593 checked_set(H, tm.tm_hour, not_a_hour, is);
6594 checked_set(M, tm.tm_min, not_a_minute, is);
6595 checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
6602 CONSTDATA auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
6603 int tH = not_a_hour;
6604 int tM = not_a_minute;
6606 read(is, ru{tH, 1, 2}, CharT{
':'}, ru{tM, 1, 2},
6607 CharT{
':'}, rld{S, 1, w});
6608 checked_set(H, tH, not_a_hour, is);
6609 checked_set(M, tM, not_a_minute, is);
6615 read(is, CharT{
'%'}, width, modified, *fmt);
6626 int tC = not_a_century;
6628 if (modified == CharT{})
6631 read(is, rs{tC, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6636 ios::iostate err = ios::goodbit;
6637 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6638 if ((err & ios::failbit) == 0)
6640 auto tY = tm.tm_year + 1900;
6641 tC = (tY >= 0 ? tY : tY-99) / 100;
6646 checked_set(C, tC, not_a_century, is);
6657 if (modified == CharT{})
6659 int tn = not_a_month;
6661 int ty = not_a_2digit_year;
6662 read(is, ru{tn, 1, 2}, CharT{
'\0'}, CharT{
'/'}, CharT{
'\0'},
6663 ru{td, 1, 2}, CharT{
'\0'}, CharT{
'/'}, CharT{
'\0'},
6665 checked_set(y, ty, not_a_2digit_year, is);
6666 checked_set(m, tn, not_a_month, is);
6667 checked_set(d, td, not_a_day, is);
6670 read(is, CharT{
'%'}, width, modified, *fmt);
6681 if (modified == CharT{})
6683 int tY = not_a_year;
6684 int tn = not_a_month;
6686 read(is, rs{tY, 1, width == -1 ? 4u :
static_cast<unsigned>(width)},
6687 CharT{
'-'}, ru{tn, 1, 2}, CharT{
'-'}, ru{td, 1, 2});
6688 checked_set(Y, tY, not_a_year, is);
6689 checked_set(m, tn, not_a_month, is);
6690 checked_set(d, td, not_a_day, is);
6693 read(is, CharT{
'%'}, width, modified, *fmt);
6706 if (modified == CharT{})
6708 if (modified != CharT{
'E'})
6712 read(is, rs{td, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6713 checked_set(d, td, not_a_day, is);
6716 else if (modified == CharT{
'O'})
6718 ios::iostate err = ios::goodbit;
6719 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6723 if ((err & ios::failbit) == 0)
6724 checked_set(d, tm.tm_mday, not_a_day, is);
6729 read(is, CharT{
'%'}, width, modified, *fmt);
6741 if (modified == CharT{})
6743 if (modified != CharT{
'E'})
6746 int tH = not_a_hour;
6747 read(is, ru{tH, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6748 checked_set(H, tH, not_a_hour, is);
6751 else if (modified == CharT{
'O'})
6753 ios::iostate err = ios::goodbit;
6754 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6755 if ((err & ios::failbit) == 0)
6756 checked_set(H, tm.tm_hour, not_a_hour, is);
6761 read(is, CharT{
'%'}, width, modified, *fmt);
6772 if (modified == CharT{})
6774 int tI = not_a_hour_12_value;
6776 read(is, rs{tI, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6777 if (!(1 <= tI && tI <= 12))
6778 is.setstate(ios::failbit);
6779 checked_set(I, tI, not_a_hour_12_value, is);
6782 read(is, CharT{
'%'}, width, modified, *fmt);
6793 if (modified == CharT{})
6796 read(is, ru{tj, 1, width == -1 ? 3u :
static_cast<unsigned>(width)});
6797 checked_set(j, tj, not_a_doy, is);
6800 read(is, CharT{
'%'}, width, modified, *fmt);
6812 if (modified == CharT{})
6814 if (modified != CharT{
'E'})
6817 int tM = not_a_minute;
6818 read(is, ru{tM, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6819 checked_set(M, tM, not_a_minute, is);
6822 else if (modified == CharT{
'O'})
6824 ios::iostate err = ios::goodbit;
6825 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6826 if ((err & ios::failbit) == 0)
6827 checked_set(M, tm.tm_min, not_a_minute, is);
6832 read(is, CharT{
'%'}, width, modified, *fmt);
6844 if (modified == CharT{})
6846 if (modified != CharT{
'E'})
6849 int tn = not_a_month;
6850 read(is, rs{tn, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6851 checked_set(m, tn, not_a_month, is);
6854 else if (modified == CharT{
'O'})
6856 ios::iostate err = ios::goodbit;
6857 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6858 if ((err & ios::failbit) == 0)
6859 checked_set(m, tm.tm_mon + 1, not_a_month, is);
6864 read(is, CharT{
'%'}, width, modified, *fmt);
6876 if (modified == CharT{})
6880 auto ic = is.peek();
6881 if (Traits::eq_int_type(ic, Traits::eof()))
6883 ios::iostate err = ios::eofbit;
6885 err |= ios::failbit;
6893 else if (*fmt ==
'n')
6894 is.setstate(ios::failbit);
6897 read(is, CharT{
'%'}, width, modified, *fmt);
6908 if (modified == CharT{})
6910 int tp = not_a_ampm;
6914 ios::iostate err = ios::goodbit;
6915 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6917 if (tm.tm_hour == 1)
6919 else if (tm.tm_hour == 13)
6924 auto nm = detail::ampm_names();
6925 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6928 checked_set(p, tp, not_a_ampm, is);
6931 read(is, CharT{
'%'}, width, modified, *fmt);
6943 if (modified == CharT{})
6946 ios::iostate err = ios::goodbit;
6947 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6948 if ((err & ios::failbit) == 0)
6950 checked_set(H, tm.tm_hour, not_a_hour, is);
6951 checked_set(M, tm.tm_min, not_a_hour, is);
6952 checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
6959 CONSTDATA auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
6961 int tI = not_a_hour_12_value;
6962 int tM = not_a_minute;
6963 read(is, ru{tI, 1, 2}, CharT{
':'}, ru{tM, 1, 2},
6964 CharT{
':'}, rld{S, 1, w});
6965 checked_set(I, tI, not_a_hour_12_value, is);
6966 checked_set(M, tM, not_a_minute, is);
6970 auto nm = detail::ampm_names();
6971 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6972 checked_set(p,
static_cast<int>(i), not_a_ampm, is);
6976 read(is, CharT{
'%'}, width, modified, *fmt);
6987 if (modified == CharT{})
6989 int tH = not_a_hour;
6990 int tM = not_a_minute;
6991 read(is, ru{tH, 1, 2}, CharT{
'\0'}, CharT{
':'}, CharT{
'\0'},
6992 ru{tM, 1, 2}, CharT{
'\0'});
6993 checked_set(H, tH, not_a_hour, is);
6994 checked_set(M, tM, not_a_minute, is);
6997 read(is, CharT{
'%'}, width, modified, *fmt);
7009 if (modified == CharT{})
7011 if (modified != CharT{
'E'})
7015 CONSTDATA auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
7017 read(is, rld{S, 1, width == -1 ? w :
static_cast<unsigned>(width)});
7022 else if (modified == CharT{
'O'})
7024 ios::iostate err = ios::goodbit;
7025 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
7026 if ((err & ios::failbit) == 0)
7027 checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
7033 read(is, CharT{
'%'}, width, modified, *fmt);
7044 if (modified == CharT{})
7047 CONSTDATA auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
7048 int tH = not_a_hour;
7049 int tM = not_a_minute;
7051 read(is, ru{tH, 1, 2}, CharT{
':'}, ru{tM, 1, 2},
7052 CharT{
':'}, rld{S, 1, w});
7053 checked_set(H, tH, not_a_hour, is);
7054 checked_set(M, tM, not_a_minute, is);
7059 read(is, CharT{
'%'}, width, modified, *fmt);
7071 if (modified == CharT{})
7073 if (modified != CharT{
'O'})
7076 int tY = not_a_year;
7077 read(is, rs{tY, 1, width == -1 ? 4u :
static_cast<unsigned>(width)});
7078 checked_set(Y, tY, not_a_year, is);
7081 else if (modified == CharT{
'E'})
7083 ios::iostate err = ios::goodbit;
7084 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
7085 if ((err & ios::failbit) == 0)
7086 checked_set(Y, tm.tm_year + 1900, not_a_year, is);
7091 read(is, CharT{
'%'}, width, modified, *fmt);
7103 if (modified == CharT{})
7106 int ty = not_a_2digit_year;
7107 read(is, ru{ty, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
7108 checked_set(y, ty, not_a_2digit_year, is);
7113 ios::iostate err = ios::goodbit;
7114 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
7115 if ((err & ios::failbit) == 0)
7116 checked_set(Y, tm.tm_year + 1900, not_a_year, is);
7130 if (modified == CharT{})
7132 int tg = not_a_2digit_year;
7133 read(is, ru{tg, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
7134 checked_set(g, tg, not_a_2digit_year, is);
7137 read(is, CharT{
'%'}, width, modified, *fmt);
7148 if (modified == CharT{})
7150 int tG = not_a_year;
7151 read(is, rs{tG, 1, width == -1 ? 4u :
static_cast<unsigned>(width)});
7152 checked_set(G, tG, not_a_year, is);
7155 read(is, CharT{
'%'}, width, modified, *fmt);
7166 if (modified == CharT{})
7168 int tU = not_a_week_num;
7169 read(is, ru{tU, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
7170 checked_set(U, tU, not_a_week_num, is);
7173 read(is, CharT{
'%'}, width, modified, *fmt);
7184 if (modified == CharT{})
7186 int tV = not_a_week_num;
7187 read(is, ru{tV, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
7188 checked_set(V, tV, not_a_week_num, is);
7191 read(is, CharT{
'%'}, width, modified, *fmt);
7202 if (modified == CharT{})
7204 int tW = not_a_week_num;
7205 read(is, ru{tW, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
7206 checked_set(W, tW, not_a_week_num, is);
7209 read(is, CharT{
'%'}, width, modified, *fmt);
7221 if (modified == CharT{})
7227 read(is, CharT{
'%'}, width, modified, *fmt);
7239 if (modified == CharT{})
7242 read(is, CharT{
'%'}, width, modified, *fmt);
7254 minutes toff = not_a_offset;
7256 auto ic = is.peek();
7257 if (!Traits::eq_int_type(ic, Traits::eof()))
7259 auto c =
static_cast<char>(Traits::to_char_type(ic));
7263 if (modified == CharT{})
7265 read(is, rs{tH, 2, 2});
7267 toff = hours{std::abs(tH)};
7271 if (!Traits::eq_int_type(ic, Traits::eof()))
7273 auto c =
static_cast<char>(Traits::to_char_type(ic));
7274 if (
'0' <= c && c <=
'9')
7276 read(is, ru{tM, 2, 2});
7278 toff += minutes{tM};
7285 read(is, rs{tH, 1, 2});
7287 toff = hours{std::abs(tH)};
7291 if (!Traits::eq_int_type(ic, Traits::eof()))
7293 auto c =
static_cast<char>(Traits::to_char_type(ic));
7297 read(is, ru{tM, 2, 2});
7299 toff += minutes{tM};
7306 checked_set(temp_offset, toff, not_a_offset, is);
7317 if (modified == CharT{})
7319 std::basic_string<CharT, Traits, Alloc> buf;
7320 while (is.rdstate() == std::ios::goodbit)
7322 auto i = is.rdbuf()->sgetc();
7323 if (Traits::eq_int_type(i, Traits::eof()))
7325 is.setstate(ios::eofbit);
7328 auto wc = Traits::to_char_type(i);
7329 auto c =
static_cast<char>(wc);
7331 if (!(CharT{1} < wc && wc < CharT{127}) || !(isalnum(c) ||
7332 c ==
'_' || c ==
'/' || c ==
'-' || c ==
'+'))
7335 is.rdbuf()->sbumpc();
7338 is.setstate(ios::failbit);
7339 checked_set(temp_abbrev, buf, {}, is);
7342 read(is, CharT{
'%'}, width, modified, *fmt);
7353 if (width == -1 && modified == CharT{} &&
'0' <= *fmt && *fmt <=
'9')
7355 width =
static_cast<char>(*fmt) -
'0';
7356 while (
'0' <= fmt[1] && fmt[1] <=
'9')
7357 width = 10*width +
static_cast<char>(*++fmt) -
'0';
7361 if (modified == CharT{})
7362 read(is, CharT{
'%'}, width, *fmt);
7364 read(is, CharT{
'%'}, width, modified, *fmt);
7372 if (isspace(
static_cast<unsigned char>(*fmt)))
7385 if (is.rdstate() == ios::goodbit && command)
7387 if (modified == CharT{})
7388 read(is, CharT{
'%'}, width);
7390 read(is, CharT{
'%'}, width, modified);
7394 if (y != not_a_2digit_year)
7397 if (!(0 <= y && y <= 99))
7399 if (C == not_a_century)
7401 if (Y == not_a_year)
7410 C = (Y >= 0 ? Y : Y-100) / 100;
7417 tY = 100*(C+1) - (y == 0 ? 100 : y);
7418 if (Y != not_a_year && Y != tY)
7422 if (g != not_a_2digit_year)
7425 if (!(0 <= g && g <= 99))
7427 if (C == not_a_century)
7429 if (G == not_a_year)
7438 C = (G >= 0 ? G : G-100) / 100;
7445 tG = 100*(C+1) - (g == 0 ? 100 : g);
7446 if (G != not_a_year && G != tG)
7452 bool computed =
false;
7453 if (G != not_a_year && V != not_a_week_num && wd != not_a_weekday)
7458 if (Y == not_a_year)
7459 Y =
static_cast<int>(ymd_trial.
year());
7460 else if (
year{Y} != ymd_trial.
year())
7462 if (m == not_a_month)
7463 m =
static_cast<int>(
static_cast<unsigned>(ymd_trial.
month()));
7464 else if (
month(
static_cast<unsigned>(m)) != ymd_trial.
month())
7467 d =
static_cast<int>(
static_cast<unsigned>(ymd_trial.
day()));
7468 else if (
day(
static_cast<unsigned>(d)) != ymd_trial.
day())
7472 if (Y != not_a_year && U != not_a_week_num && wd != not_a_weekday)
7477 if (Y == not_a_year)
7478 Y =
static_cast<int>(ymd_trial.
year());
7479 else if (
year{Y} != ymd_trial.
year())
7481 if (m == not_a_month)
7482 m =
static_cast<int>(
static_cast<unsigned>(ymd_trial.
month()));
7483 else if (
month(
static_cast<unsigned>(m)) != ymd_trial.
month())
7486 d =
static_cast<int>(
static_cast<unsigned>(ymd_trial.
day()));
7487 else if (
day(
static_cast<unsigned>(d)) != ymd_trial.
day())
7491 if (Y != not_a_year && W != not_a_week_num && wd != not_a_weekday)
7496 if (Y == not_a_year)
7497 Y =
static_cast<int>(ymd_trial.
year());
7498 else if (
year{Y} != ymd_trial.
year())
7500 if (m == not_a_month)
7501 m =
static_cast<int>(
static_cast<unsigned>(ymd_trial.
month()));
7502 else if (
month(
static_cast<unsigned>(m)) != ymd_trial.
month())
7505 d =
static_cast<int>(
static_cast<unsigned>(ymd_trial.
day()));
7506 else if (
day(
static_cast<unsigned>(d)) != ymd_trial.
day())
7510 if (j != not_a_doy && Y != not_a_year)
7514 m =
static_cast<int>(
static_cast<unsigned>(ymd_trial.month()));
7515 else if (
month(
static_cast<unsigned>(m)) != ymd_trial.
month())
7518 d =
static_cast<int>(
static_cast<unsigned>(ymd_trial.day()));
7519 else if (
day(
static_cast<unsigned>(d)) != ymd_trial.
day())
7523 auto ymd =
year{Y}/m/d;
7526 if (wd == not_a_weekday)
7532 if (G != not_a_year || V != not_a_week_num)
7541 if (V != not_a_week_num)
7545 if (G != not_a_year && G !=
static_cast<int>(G_trial))
7547 if (V != not_a_week_num)
7549 auto V_trial = duration_cast<weeks>(sd - start).count() + 1;
7554 if (U != not_a_week_num)
7561 if (W != not_a_week_num)
7571 if (I != not_a_hour_12_value)
7573 if (!(1 <= I && I <= 12))
7575 if (p != not_a_ampm)
7583 if (H == not_a_hour)
7591 if (H != not_a_hour)
7595 if (H != 0 && H != 12)
7598 else if (!(I == H || I == H+12))
7605 if (H != not_a_hour)
7610 if (M != not_a_minute)
7613 fds.
tod.m_ = minutes{M};
7615 if (s != not_a_second)
7625 if (wd != not_a_weekday)
7626 fds.
wd =
weekday{
static_cast<unsigned>(wd)};
7627 if (abbrev !=
nullptr)
7628 *abbrev = std::move(temp_abbrev);
7629 if (offset !=
nullptr && temp_offset != not_a_offset)
7630 *offset = temp_offset;
7635 is.setstate(ios::failbit);