mirror of
https://github.com/HowardHinnant/date.git
synced 2024-12-27 00:14:07 +08:00
Added a few convenience field getters:
* year_month_weekday::weekday() * year_month_weekday::index() * year_month_weekday_last::weekday()
This commit is contained in:
parent
6af1976e36
commit
c8ee261043
35
date.h
35
date.h
@ -633,6 +633,8 @@ public:
|
||||
|
||||
CONSTCD11 date::year year() const noexcept;
|
||||
CONSTCD11 date::month month() const noexcept;
|
||||
CONSTCD11 date::weekday weekday() const noexcept;
|
||||
CONSTCD11 unsigned index() const noexcept;
|
||||
CONSTCD11 date::weekday_indexed weekday_indexed() const noexcept;
|
||||
|
||||
CONSTCD14 operator day_point() const noexcept;
|
||||
@ -692,6 +694,7 @@ public:
|
||||
|
||||
CONSTCD11 date::year year() const noexcept;
|
||||
CONSTCD11 date::month month() const noexcept;
|
||||
CONSTCD11 date::weekday weekday() const noexcept;
|
||||
CONSTCD11 date::weekday_last weekday_last() const noexcept;
|
||||
|
||||
CONSTCD14 operator day_point() const noexcept;
|
||||
@ -2449,6 +2452,22 @@ year_month_weekday::operator-=(const years& y) noexcept
|
||||
CONSTCD11 inline year year_month_weekday::year() const noexcept {return y_;}
|
||||
CONSTCD11 inline month year_month_weekday::month() const noexcept {return m_;}
|
||||
|
||||
CONSTCD11
|
||||
inline
|
||||
weekday
|
||||
year_month_weekday::weekday() const noexcept
|
||||
{
|
||||
return wdi_.weekday();
|
||||
}
|
||||
|
||||
CONSTCD11
|
||||
inline
|
||||
unsigned
|
||||
year_month_weekday::index() const noexcept
|
||||
{
|
||||
return wdi_.index();
|
||||
}
|
||||
|
||||
CONSTCD11
|
||||
inline
|
||||
weekday_indexed
|
||||
@ -2462,7 +2481,7 @@ inline
|
||||
year_month_weekday::operator day_point() const noexcept
|
||||
{
|
||||
auto d = day_point(y_/m_/1);
|
||||
return d + (wdi_.weekday() - weekday(d) + days{(wdi_.index()-1)*7});
|
||||
return d + (wdi_.weekday() - date::weekday(d) + days{(wdi_.index()-1)*7});
|
||||
}
|
||||
|
||||
CONSTCD14
|
||||
@ -2474,7 +2493,7 @@ year_month_weekday::ok() const noexcept
|
||||
return false;
|
||||
if (wdi_.index() <= 4)
|
||||
return true;
|
||||
auto d2 = wdi_.weekday() - weekday(y_/m_/1) + days((wdi_.index()-1)*7 + 1);
|
||||
auto d2 = wdi_.weekday() - date::weekday(y_/m_/1) + days((wdi_.index()-1)*7 + 1);
|
||||
return static_cast<unsigned>(d2.count()) <= static_cast<unsigned>((y_/m_/last).day());
|
||||
}
|
||||
|
||||
@ -2483,7 +2502,7 @@ inline
|
||||
year_month_weekday
|
||||
year_month_weekday::from_day_point(const day_point& dp) noexcept
|
||||
{
|
||||
auto const wd = weekday(dp);
|
||||
auto const wd = date::weekday(dp);
|
||||
auto const ymd = year_month_day(dp);
|
||||
return {ymd.year(), ymd.month(), wd[(static_cast<unsigned>(ymd.day())-1)/7+1]};
|
||||
}
|
||||
@ -2608,6 +2627,14 @@ year_month_weekday_last::operator-=(const years& y) noexcept
|
||||
CONSTCD11 inline year year_month_weekday_last::year() const noexcept {return y_;}
|
||||
CONSTCD11 inline month year_month_weekday_last::month() const noexcept {return m_;}
|
||||
|
||||
CONSTCD11
|
||||
inline
|
||||
weekday
|
||||
year_month_weekday_last::weekday() const noexcept
|
||||
{
|
||||
return wdl_.weekday();
|
||||
}
|
||||
|
||||
CONSTCD11
|
||||
inline
|
||||
weekday_last
|
||||
@ -2621,7 +2648,7 @@ inline
|
||||
year_month_weekday_last::operator day_point() const noexcept
|
||||
{
|
||||
auto const d = day_point(y_/m_/last);
|
||||
return d - (weekday{d} - wdl_.weekday());
|
||||
return d - (date::weekday{d} - wdl_.weekday());
|
||||
}
|
||||
|
||||
CONSTCD11
|
||||
|
@ -34,6 +34,8 @@
|
||||
//
|
||||
// constexpr date::year year() const noexcept;
|
||||
// constexpr date::month month() const noexcept;
|
||||
// constexpr date::weekday weekday() const noexcept;
|
||||
// constexpr unsigned index() const noexcept;
|
||||
// constexpr date::weekday_indexed weekday_indexed() const noexcept;
|
||||
//
|
||||
// constexpr operator day_point() const noexcept;
|
||||
@ -152,6 +154,8 @@ main()
|
||||
#endif
|
||||
static_assert(ymdl1.year() == 2015_y, "");
|
||||
static_assert(ymdl1.month() == aug, "");
|
||||
static_assert(ymdl1.weekday() == fri, "");
|
||||
static_assert(ymdl1.index() == 2u, "");
|
||||
static_assert(ymdl1.weekday_indexed() == fri[2], "");
|
||||
#if __cplusplus >= 201402
|
||||
constexpr day_point dp = ymdl1;
|
||||
|
@ -33,6 +33,7 @@
|
||||
//
|
||||
// constexpr date::year year() const noexcept;
|
||||
// constexpr date::month month() const noexcept;
|
||||
// constexpr date::weekday weekday() const noexcept;
|
||||
// constexpr date::weekday_last weekday_last() const noexcept;
|
||||
//
|
||||
// constexpr operator day_point() const noexcept;
|
||||
@ -146,6 +147,7 @@ main()
|
||||
static_assert(ymdl1.ok(), "");
|
||||
static_assert(ymdl1.year() == 2015_y, "");
|
||||
static_assert(ymdl1.month() == aug, "");
|
||||
static_assert(ymdl1.weekday() == fri, "");
|
||||
static_assert(ymdl1.weekday_last() == fri[last], "");
|
||||
#if __cplusplus >= 201402
|
||||
constexpr day_point dp = ymdl1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user