[time.cal.ymwd] (original) (raw)

30 Time library [time]

30.8 The civil calendar [time.cal]

30.8.16 Class year_month_weekday [time.cal.ymwd]

30.8.16.1 Overview [time.cal.ymwd.overview]

namespace std::chrono { class year_month_weekday { chrono::year y_; chrono::month m_; chrono::weekday_indexed wdi_; public: year_month_weekday() = default;constexpr year_month_weekday(const chrono::year& y, const chrono::month& m,const chrono::weekday_indexed& wdi) noexcept;constexpr year_month_weekday(const sys_days& dp) noexcept;constexpr explicit year_month_weekday(const local_days& dp) noexcept;constexpr year_month_weekday& operator+=(const months& m) noexcept;constexpr year_month_weekday& operator-=(const months& m) noexcept;constexpr year_month_weekday& operator+=(const years& y) noexcept;constexpr year_month_weekday& operator-=(const years& y) noexcept;constexpr chrono::year year() const noexcept;constexpr chrono::month month() const noexcept;constexpr chrono::weekday weekday() const noexcept;constexpr unsigned index() const noexcept;constexpr chrono::weekday_indexed weekday_indexed() const noexcept;constexpr operator sys_days() const noexcept;constexpr explicit operator local_days() const noexcept;constexpr bool ok() const noexcept;};}

year_month_weekday represents a specific year, month, and weekday of the month.

year_month_weekday is a field-based time point with a resolution of days.

[Note 1:

year_month_weekday supports years- and months-oriented arithmetic, but not days-oriented arithmetic.

For the latter, there is a conversion to sys_days, which efficiently supports days-oriented arithmetic.

— _end note_]

year_month_weekday is a trivially copyable and standard-layout class type.

30.8.16.2 Member functions [time.cal.ymwd.members]

constexpr year_month_weekday(const chrono::year& y, const chrono::month& m,const chrono::weekday_indexed& wdi) noexcept;

Effects: Initializes y_ with y, m_ with m, and wdi_ with wdi.

constexpr year_month_weekday(const sys_days& dp) noexcept;

Effects: Constructs an object of type year_month_weekdaywhich corresponds to the date represented by dp.

Remarks: For any value ymwd of type year_month_weekdayfor which ymwd.ok() is true,ymwd == year_month_weekday{sys_days{ymwd}} is true.

constexpr explicit year_month_weekday(const local_days& dp) noexcept;

Effects: Equivalent to constructing with sys_days{dp.time_since_epoch()}.

constexpr year_month_weekday& operator+=(const months& m) noexcept;

Constraints: If the argument supplied by the caller for the months parameter is convertible to years, its implicit conversion sequence to yearsis worse than its implicit conversion sequence tomonths ([over.ics.rank]).

Effects: *this = *this + m.

constexpr year_month_weekday& operator-=(const months& m) noexcept;

Constraints: If the argument supplied by the caller for the months parameter is convertible to years, its implicit conversion sequence to yearsis worse than its implicit conversion sequence tomonths ([over.ics.rank]).

Effects: *this = *this - m.

constexpr year_month_weekday& operator+=(const years& y) noexcept;

Effects: *this = *this + y.

constexpr year_month_weekday& operator-=(const years& y) noexcept;

Effects: *this = *this - y.

constexpr chrono::year year() const noexcept;

constexpr chrono::month month() const noexcept;

constexpr chrono::weekday weekday() const noexcept;

constexpr unsigned index() const noexcept;

constexpr chrono::weekday_indexed weekday_indexed() const noexcept;

constexpr operator sys_days() const noexcept;

Returns: If y_.ok() && m_.ok() && wdi_.weekday().ok(), returns a sys_days that represents the date (index() - 1) * 7 days after the first weekday() of year()/month().

If index() is 0 the returned sys_daysrepresents the date 7 days prior to the first weekday() of year()/month().

Otherwise the returned value is unspecified.

constexpr explicit operator local_days() const noexcept;

Returns: local_days{sys_days{*this}.time_since_epoch()}.

constexpr bool ok() const noexcept;

Returns: If any ofy_.ok(),m_.ok(), orwdi_.ok()is false, returns false.

Otherwise, if *this represents a valid date, returns true.

Otherwise, returns false.

30.8.16.3 Non-member functions [time.cal.ymwd.nonmembers]

constexpr bool operator==(const year_month_weekday& x, const year_month_weekday& y) noexcept;

Returns: x.year() == y.year() && x.month() == y.month() && x.weekday_indexed() == y.weekday_indexed()

constexpr year_month_weekday operator+(const year_month_weekday& ymwd, const months& dm) noexcept;

Constraints: If the argument supplied by the caller for the months parameter is convertible to years, its implicit conversion sequence to yearsis worse than its implicit conversion sequence tomonths ([over.ics.rank]).

Returns: (ymwd.year() / ymwd.month() + dm) / ymwd.weekday_indexed().

constexpr year_month_weekday operator+(const months& dm, const year_month_weekday& ymwd) noexcept;

Constraints: If the argument supplied by the caller for the months parameter is convertible to years, its implicit conversion sequence to yearsis worse than its implicit conversion sequence tomonths ([over.ics.rank]).

constexpr year_month_weekday operator-(const year_month_weekday& ymwd, const months& dm) noexcept;

Constraints: If the argument supplied by the caller for the months parameter is convertible to years, its implicit conversion sequence to yearsis worse than its implicit conversion sequence tomonths ([over.ics.rank]).

constexpr year_month_weekday operator+(const year_month_weekday& ymwd, const years& dy) noexcept;

Returns: {ymwd.year()+dy, ymwd.month(), ymwd.weekday_indexed()}.

constexpr year_month_weekday operator+(const years& dy, const year_month_weekday& ymwd) noexcept;

constexpr year_month_weekday operator-(const year_month_weekday& ymwd, const years& dy) noexcept;

template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const year_month_weekday& ymwd);

Effects: Equivalent to:return os << format(os.getloc(), _STATICALLY-WIDEN_<charT>("{}/{:L}/{:L}"), ymwd.year(), ymwd.month(), ymwd.weekday_indexed());