[time.cal.ymwd]

# 30 Time library [[time]](./#time)

## 30.8 The civil calendar [[time.cal]](time.cal#ymwd)

### 30.8.16 Class year_month_weekday [time.cal.ymwd]

#### [30.8.16.1](#overview) Overview [[time.cal.ymwd.overview]](time.cal.ymwd.overview)

namespace std::chrono {class year_month_weekday { chrono::year y_; // *exposition only* chrono::month m_; // *exposition only* chrono::weekday_indexed wdi_; // *exposition only*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; };}

[1](#overview-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7194)

year_month_weekday represents a specific year, month,
and nth weekday of the month[.](#overview-1.sentence-1)

year_month_weekday is a field-based time point with a resolution of days[.](#overview-1.sentence-2)

[*Note [1](#overview-note-1)*:

year_month_weekday supports years- and months-oriented arithmetic,
but not days-oriented arithmetic[.](#overview-1.sentence-3)

For the latter, there is a conversion to sys_days,
which efficiently supports days-oriented arithmetic[.](#overview-1.sentence-4)

â *end note*]

year_month_weekday meets the [*Cpp17EqualityComparable*](utility.arg.requirements#:Cpp17EqualityComparable "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [28](utility.arg.requirements#tab:cpp17.equalitycomparable "Table 28: Cpp17EqualityComparable requirements")) requirements[.](#overview-1.sentence-5)

[2](#overview-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7206)

year_month_weekday is a trivially copyable and standard-layout class type[.](#overview-2.sentence-1)

#### [30.8.16.2](#members) Member functions [[time.cal.ymwd.members]](time.cal.ymwd.members)

[ð](#lib:year_month_weekday,constructor)

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

[1](#members-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7218)

*Effects*: Initializes y_ with y, m_ with m, and wdi_ with wdi[.](#members-1.sentence-1)

[ð](#lib:year_month_weekday,constructor_)

`constexpr year_month_weekday(const sys_days& dp) noexcept;
`

[2](#members-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7229)

*Effects*: Constructs an object of type year_month_weekday which corresponds to the date represented by dp[.](#members-2.sentence-1)

[3](#members-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7234)

*Remarks*: For any value ymwd of type year_month_weekday for which ymwd.ok() is true,ymwd == year_month_weekday{sys_days{ymwd}} is true[.](#members-3.sentence-1)

[ð](#lib:year_month_weekday,constructor__)

`constexpr explicit year_month_weekday(const local_days& dp) noexcept;
`

[4](#members-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7247)

*Effects*: Equivalent to constructing with sys_days{dp.time_since_epoch()}[.](#members-4.sentence-1)

[ð](#lib:operator+=,year_month_weekday)

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

[5](#members-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7258)

*Constraints*: If the argument supplied by the caller for the months parameter
is convertible to years,
its implicit conversion sequence to years is worse than its implicit conversion sequence tomonths ([[over.ics.rank]](over.ics.rank "12.2.4.3 Ranking implicit conversion sequences"))[.](#members-5.sentence-1)

[6](#members-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7266)

*Effects*: *this = *this + m[.](#members-6.sentence-1)

[7](#members-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7270)

*Returns*: *this[.](#members-7.sentence-1)

[ð](#lib:operator-=,year_month_weekday)

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

[8](#members-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7281)

*Constraints*: If the argument supplied by the caller for the months parameter
is convertible to years,
its implicit conversion sequence to years is worse than its implicit conversion sequence tomonths ([[over.ics.rank]](over.ics.rank "12.2.4.3 Ranking implicit conversion sequences"))[.](#members-8.sentence-1)

[9](#members-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7289)

*Effects*: *this = *this - m[.](#members-9.sentence-1)

[10](#members-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7293)

*Returns*: *this[.](#members-10.sentence-1)

[ð](#lib:operator+=,year_month_weekday_)

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

[11](#members-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7304)

*Effects*: *this = *this + y[.](#members-11.sentence-1)

[12](#members-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7308)

*Returns*: *this[.](#members-12.sentence-1)

[ð](#lib:operator-=,year_month_weekday_)

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

[13](#members-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7319)

*Effects*: *this = *this - y[.](#members-13.sentence-1)

[14](#members-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7323)

*Returns*: *this[.](#members-14.sentence-1)

[ð](#lib:year,year_month_weekday)

`constexpr chrono::year year() const noexcept;
`

[15](#members-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7334)

*Returns*: y_[.](#members-15.sentence-1)

[ð](#lib:month,year_month_weekday)

`constexpr chrono::month month() const noexcept;
`

[16](#members-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7345)

*Returns*: m_[.](#members-16.sentence-1)

[ð](#lib:weekday,year_month_weekday)

`constexpr chrono::weekday weekday() const noexcept;
`

[17](#members-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7356)

*Returns*: wdi_.weekday()[.](#members-17.sentence-1)

[ð](#lib:index,year_month_weekday)

`constexpr unsigned index() const noexcept;
`

[18](#members-18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7367)

*Returns*: wdi_.index()[.](#members-18.sentence-1)

[ð](#lib:weekday_indexed,year_month_weekday)

`constexpr chrono::weekday_indexed weekday_indexed() const noexcept;
`

[19](#members-19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7378)

*Returns*: wdi_[.](#members-19.sentence-1)

[ð](#lib:operator_sys_days,year_month_weekday)

`constexpr operator sys_days() const noexcept;
`

[20](#members-20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7389)

*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()[.](#members-20.sentence-1)

If index() is 0
the returned sys_days represents the date 7 days prior to
the first weekday() of year()/month()[.](#members-20.sentence-2)

Otherwise the returned value is unspecified[.](#members-20.sentence-3)

[ð](#lib:operator_local_days,year_month_weekday)

`constexpr explicit operator local_days() const noexcept;
`

[21](#members-21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7408)

*Returns*: local_days{sys_days{*this}.time_since_epoch()}[.](#members-21.sentence-1)

[ð](#lib:ok,year_month_weekday)

`constexpr bool ok() const noexcept;
`

[22](#members-22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7419)

*Returns*: If any ofy_.ok(),m_.ok(), orwdi_.ok() is false, returns false[.](#members-22.sentence-1)

Otherwise, if *this represents a valid date,
returns true[.](#members-22.sentence-2)

Otherwise, returns false[.](#members-22.sentence-3)

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

[ð](#lib:operator==,year_month_weekday)

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

[1](#nonmembers-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7439)

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

[ð](#lib:operator+,year_month_weekday)

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

[2](#nonmembers-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7452)

*Constraints*: If the argument supplied by the caller for the months parameter
is convertible to years,
its implicit conversion sequence to years is worse than its implicit conversion sequence tomonths ([[over.ics.rank]](over.ics.rank "12.2.4.3 Ranking implicit conversion sequences"))[.](#nonmembers-2.sentence-1)

[3](#nonmembers-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7460)

*Returns*: (ymwd.year() / ymwd.month() + dm) / ymwd.weekday_indexed()[.](#nonmembers-3.sentence-1)

[ð](#lib:operator+,year_month_weekday_)

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

[4](#nonmembers-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7471)

*Constraints*: If the argument supplied by the caller for the months parameter
is convertible to years,
its implicit conversion sequence to years is worse than its implicit conversion sequence tomonths ([[over.ics.rank]](over.ics.rank "12.2.4.3 Ranking implicit conversion sequences"))[.](#nonmembers-4.sentence-1)

[5](#nonmembers-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7479)

*Returns*: ymwd + dm[.](#nonmembers-5.sentence-1)

[ð](#lib:operator-,year_month_weekday)

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

[6](#nonmembers-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7490)

*Constraints*: If the argument supplied by the caller for the months parameter
is convertible to years,
its implicit conversion sequence to years is worse than its implicit conversion sequence tomonths ([[over.ics.rank]](over.ics.rank "12.2.4.3 Ranking implicit conversion sequences"))[.](#nonmembers-6.sentence-1)

[7](#nonmembers-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7498)

*Returns*: ymwd + (-dm)[.](#nonmembers-7.sentence-1)

[ð](#lib:operator+,year_month_weekday__)

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

[8](#nonmembers-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7509)

*Returns*: {ymwd.year()+dy, ymwd.month(), ymwd.weekday_indexed()}[.](#nonmembers-8.sentence-1)

[ð](#lib:operator+,year_month_weekday___)

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

[9](#nonmembers-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7520)

*Returns*: ymwd + dy[.](#nonmembers-9.sentence-1)

[ð](#lib:operator-,year_month_weekday_)

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

[10](#nonmembers-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7531)

*Returns*: ymwd + (-dy)[.](#nonmembers-10.sentence-1)

[ð](#lib:operator%3c%3c,year_month_weekday)

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

[11](#nonmembers-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L7544)

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