return __parts;
}
+ // pre: _M_year is set
[[__gnu__::__always_inline__]]
_ChronoParts
_M_fill_aux(chrono::local_days __ld, _ChronoParts __parts)
return __parts;
}
+ // pre: _M_year is set
[[__gnu__::__always_inline__]]
_ChronoParts
_M_fill_ldays(chrono::local_days __ld, _ChronoParts __parts)
if (__parts == 0)
return _M_f._M_format(__cd, __fc);
- chrono::local_days __ld(__t);
- __cd._M_fill_ldays(__ld, __parts);
+ __cd._M_fill_ldays(chrono::local_days(__t), __parts);
return _M_f._M_format(__cd, __fc);
}
format(const chrono::year_month_day_last& __t,
basic_format_context<_Out, _CharT>& __fc) const
{
+ using enum __format::_ChronoParts;
+
__format::_ChronoData<_CharT> __cd{};
auto __parts = _M_f._M_spec._M_needed;
__parts = __cd._M_fill_year_month(__t, __parts);
+ if (_M_f._M_spec._M_needs(_Day|_WeekdayIndex))
+ __parts = __cd._M_fill_day(__t.day(), __parts);
if (__parts == 0)
return _M_f._M_format(__cd, __fc);
- chrono::local_days __ld(__t);
- __parts = __cd._M_fill_ldays(__ld, __parts);
- if (__parts == 0)
- return _M_f._M_format(__cd, __fc);
-
- chrono::year_month_day __ymd(__ld);
- __cd._M_fill_day(__ymd.day(), __parts);
+ __cd._M_fill_ldays(chrono::local_days(__t), __parts);
return _M_f._M_format(__cd, __fc);
}
auto __parts = _M_f._M_spec._M_needed;
__parts = __cd._M_fill_year_month(__t, __parts);
__parts = __cd._M_fill_weekday(__t.weekday_indexed(), __parts);
+ if (__t.index() == 0) [[unlikely]]
+ // n.b. day cannot be negative, so any 0th weekday uses
+ // value-initialized (0) day of month
+ __parts -= __format::_ChronoParts::_Day;
if (__parts == 0)
return _M_f._M_format(__cd, __fc);
if (__parts == 0)
return _M_f._M_format(__cd, __fc);
- chrono::year_month_day __ymd(__ld);
+ auto __dom = __ld - chrono::local_days(__t.year()/__t.month()/0);
// n.b. weekday index is supplied by input, do not override it
- __cd._M_day = __ymd.day();
+ __cd._M_day = chrono::day(__dom.count());
return _M_f._M_format(__cd, __fc);
}
if (__parts == 0)
return _M_f._M_format(__cd, __fc);
- chrono::year_month_day __ymd(__ld);
- __cd._M_fill_day(__ymd.day(), __parts);
+ auto __dom = __ld - chrono::local_days(__t.year()/__t.month()/0);
+ __cd._M_fill_day(chrono::day(__dom.count()), __parts);
return _M_f._M_format(__cd, __fc);
}
VERIFY( s == "2024-09-01 245" );
s = std::format("{:%Y-%m-%d %j}", 2024y/September/Sunday[5]);
VERIFY( s == "2024-09-29 273" );
- // see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121929
// first weeks of next month
s = std::format("{:%Y-%m-%d %j}", 2024y/September/Sunday[6]);
- VERIFY( s == "2024-09-06 280" );
+ VERIFY( s == "2024-09-36 280" );
s = std::format("{:%Y-%m-%d %j}", 2024y/September/Sunday[7]);
- VERIFY( s == "2024-09-13 287" );
+ VERIFY( s == "2024-09-43 287" );
// last week on previous month
s = std::format("{:%Y-%m-%d %j}", 2024y/September/Saturday[0]);
- VERIFY( s == "2024-09-31 244" );
+ VERIFY( s == "2024-09-00 244" );
s = std::format("{:%Y-%m-%d %j}", 2024y/September/Sunday[0]);
- VERIFY( s == "2024-09-25 238" );
+ VERIFY( s == "2024-09-00 238" ); // day is de-facto -6
// %U: Week number for weeks starting on Sunday
s = std::format("{:%Y-U%U}", 2023y/January/Sunday[0]);