mirror of
https://github.com/HowardHinnant/date.git
synced 2024-12-25 23:40:53 +08:00
Expose iso_week::year::is_leap()
This commit is contained in:
parent
50acf3ffd8
commit
cc4685a21e
@ -148,6 +148,8 @@ public:
|
||||
year& operator+=(const years& y) NOEXCEPT;
|
||||
year& operator-=(const years& y) NOEXCEPT;
|
||||
|
||||
CONSTCD14 bool is_leap() const NOEXCEPT;
|
||||
|
||||
CONSTCD11 explicit operator int() const NOEXCEPT;
|
||||
CONSTCD11 bool ok() const NOEXCEPT;
|
||||
|
||||
@ -599,6 +601,17 @@ inline year year::operator--(int) NOEXCEPT {auto tmp(*this); --(*this); return t
|
||||
inline year& year::operator+=(const years& y) NOEXCEPT {*this = *this + y; return *this;}
|
||||
inline year& year::operator-=(const years& y) NOEXCEPT {*this = *this - y; return *this;}
|
||||
|
||||
CONSTCD14
|
||||
inline
|
||||
bool
|
||||
year::is_leap() const NOEXCEPT
|
||||
{
|
||||
const auto y = date::year{static_cast<int>(y_)};
|
||||
const auto s0 = sys_days((y-years{1})/12/date::thu[date::last]);
|
||||
const auto s1 = sys_days(y/12/date::thu[date::last]);
|
||||
return s1-s0 != days{7*52};
|
||||
}
|
||||
|
||||
CONSTCD11 inline year::operator int() const NOEXCEPT {return y_;}
|
||||
CONSTCD11 inline bool year::ok() const NOEXCEPT {return min() <= *this && *this <= max();}
|
||||
|
||||
@ -1020,10 +1033,7 @@ inline
|
||||
weeknum
|
||||
year_lastweek::weeknum() const NOEXCEPT
|
||||
{
|
||||
const auto y = date::year{static_cast<int>(y_)};
|
||||
const auto s0 = sys_days((y-years{1})/12/date::thu[date::last]);
|
||||
const auto s1 = sys_days(y/12/date::thu[date::last]);
|
||||
return iso_week::weeknum(static_cast<unsigned>(date::trunc<weeks>(s1-s0).count()));
|
||||
return iso_week::weeknum(y_.is_leap() ? 53u : 52u);
|
||||
}
|
||||
|
||||
CONSTCD11 inline bool year_lastweek::ok() const NOEXCEPT {return y_.ok();}
|
||||
|
@ -93,6 +93,9 @@ main()
|
||||
static_assert(year{2015} <= 2015_y, "");
|
||||
static_assert(year{2016} >= 2015_y, "");
|
||||
|
||||
static_assert(year{2015}.is_leap(), "");
|
||||
static_assert(!year{2016}.is_leap(), "");
|
||||
|
||||
auto y = year{2014};
|
||||
assert(++y == year{2015});
|
||||
assert(y == year{2015});
|
||||
|
Loading…
x
Reference in New Issue
Block a user