forked from HowardHinnant/date
Fix off-by-one bug in iso_week::year_lastweek_weekday
* The conversion from year_lastweek_weekday to sys_days and local_days had an off by one error. * Added test for this case.
This commit is contained in:
@@ -1314,7 +1314,7 @@ inline
|
|||||||
year_lastweek_weekday::operator sys_days() const NOEXCEPT
|
year_lastweek_weekday::operator sys_days() const NOEXCEPT
|
||||||
{
|
{
|
||||||
return sys_days(date::year{static_cast<int>(y_)}/date::dec/date::thu[date::last])
|
return sys_days(date::year{static_cast<int>(y_)}/date::dec/date::thu[date::last])
|
||||||
+ (mon - thu) - (mon - wd_);
|
+ (sun - thu) - (sun - wd_);
|
||||||
}
|
}
|
||||||
|
|
||||||
CONSTCD14
|
CONSTCD14
|
||||||
@@ -1322,7 +1322,7 @@ inline
|
|||||||
year_lastweek_weekday::operator local_days() const NOEXCEPT
|
year_lastweek_weekday::operator local_days() const NOEXCEPT
|
||||||
{
|
{
|
||||||
return local_days(date::year{static_cast<int>(y_)}/date::dec/date::thu[date::last])
|
return local_days(date::year{static_cast<int>(y_)}/date::dec/date::thu[date::last])
|
||||||
+ (mon - thu) - (mon - wd_);
|
+ (sun - thu) - (sun - wd_);
|
||||||
}
|
}
|
||||||
|
|
||||||
CONSTCD11
|
CONSTCD11
|
||||||
|
@@ -115,4 +115,15 @@ main()
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << x0;
|
os << x0;
|
||||||
assert(os.str() == "2015-W last-Tue");
|
assert(os.str() == "2015-W last-Tue");
|
||||||
|
|
||||||
|
for (auto y = 1950_y; y <= 2050_y; ++y)
|
||||||
|
{
|
||||||
|
auto wd = mon;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
auto x = y/last/wd;
|
||||||
|
assert(date::year_month_day{x} == date::year_month_day{year_weeknum_weekday{x}});
|
||||||
|
++wd;
|
||||||
|
} while (wd != mon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user