[time.cal.ymdlast]

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

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

### 30.8.15 Class year_month_day_last [time.cal.ymdlast]

#### [30.8.15.1](#overview) Overview [[time.cal.ymdlast.overview]](time.cal.ymdlast.overview)

namespace std::chrono {class year_month_day_last { chrono::year y_; // *exposition only* chrono::month_day_last mdl_; // *exposition only*public:constexpr year_month_day_last(const chrono::year& y, const chrono::month_day_last& mdl) noexcept; constexpr year_month_day_last& operator+=(const months& m) noexcept; constexpr year_month_day_last& operator-=(const months& m) noexcept; constexpr year_month_day_last& operator+=(const years& y) noexcept; constexpr year_month_day_last& operator-=(const years& y) noexcept; constexpr chrono::year year() const noexcept; constexpr chrono::month month() const noexcept; constexpr chrono::month_day_last month_day_last() const noexcept; constexpr chrono::day day() 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#L6823)

year_month_day_last represents the last day of a specific year and month[.](#overview-1.sentence-1)

year_month_day_last is a field-based time point with a resolution of days,
except that it is restricted to pointing to the last day of a year and month[.](#overview-1.sentence-2)

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

year_month_day_last 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_day_last 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"))
and [*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [29](utility.arg.requirements#tab:cpp17.lessthancomparable "Table 29: Cpp17LessThanComparable requirements")) requirements[.](#overview-1.sentence-5)

[2](#overview-2)

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

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

#### [30.8.15.2](#members) Member functions [[time.cal.ymdlast.members]](time.cal.ymdlast.members)

[ð](#lib:year_month_day_last,constructor)

`constexpr year_month_day_last(const chrono::year& y,
                              const chrono::month_day_last& mdl) noexcept;
`

[1](#members-1)

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

*Effects*: Initializes y_ with y and mdl_ with mdl[.](#members-1.sentence-1)

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

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

[2](#members-2)

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

*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-2.sentence-1)

[3](#members-3)

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

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

[4](#members-4)

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

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

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

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

[5](#members-5)

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

*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#L6890)

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

[7](#members-7)

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

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

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

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

[8](#members-8)

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

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

[9](#members-9)

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

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

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

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

[10](#members-10)

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

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

[11](#members-11)

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

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

[ð](#lib:year,year_month_day_last)

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

[12](#members-12)

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

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

[ð](#lib:month,year_month_day_last)

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

[13](#members-13)

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

*Returns*: mdl_.month()[.](#members-13.sentence-1)

[ð](#lib:month_day_last,year_month_day_last)

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

[14](#members-14)

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

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

[ð](#lib:day,year_month_day_last)

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

[15](#members-15)

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

*Returns*: If ok() is true,
returns a day representing
the last day of the (year, month) pair
represented by *this[.](#members-15.sentence-1)

Otherwise, the returned value is unspecified[.](#members-15.sentence-2)

[16](#members-16)

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

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

This value might be computed on demand[.](#members-16.sentence-1)

â *end note*]

[ð](#lib:operator_sys_days,year_month_day_last)

`constexpr operator sys_days() const noexcept;
`

[17](#members-17)

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

*Returns*: sys_days{year()/month()/day()}[.](#members-17.sentence-1)

[ð](#lib:operator_local_days,year_month_day_last)

`constexpr explicit operator local_days() const noexcept;
`

[18](#members-18)

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

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

[ð](#lib:ok,year_month_day_last)

`constexpr bool ok() const noexcept;
`

[19](#members-19)

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

*Returns*: y_.ok() && mdl_.ok()[.](#members-19.sentence-1)

#### [30.8.15.3](#nonmembers) Non-member functions [[time.cal.ymdlast.nonmembers]](time.cal.ymdlast.nonmembers)

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

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

[1](#nonmembers-1)

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

*Returns*: x.year() == y.year() && x.month_day_last() == y.month_day_last()[.](#nonmembers-1.sentence-1)

[ð](#lib:operator%3c=%3e,year_month_day_last)

`constexpr strong_ordering operator<=>(const year_month_day_last& x,
                                      const year_month_day_last& y) noexcept;
`

[2](#nonmembers-2)

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

*Effects*: Equivalent to:if (auto c = x.year() <=> y.year(); c != 0) return c;return x.month_day_last() <=> y.month_day_last();

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

`constexpr year_month_day_last
  operator+(const year_month_day_last& ymdl, const months& dm) noexcept;
`

[3](#nonmembers-3)

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

*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-3.sentence-1)

[4](#nonmembers-4)

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

*Returns*: (ymdl.year() / ymdl.month() + dm) / last[.](#nonmembers-4.sentence-1)

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

`constexpr year_month_day_last
  operator+(const months& dm, const year_month_day_last& ymdl) noexcept;
`

[5](#nonmembers-5)

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

*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-5.sentence-1)

[6](#nonmembers-6)

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

*Returns*: ymdl + dm[.](#nonmembers-6.sentence-1)

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

`constexpr year_month_day_last
  operator-(const year_month_day_last& ymdl, const months& dm) noexcept;
`

[7](#nonmembers-7)

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

*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-7.sentence-1)

[8](#nonmembers-8)

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

*Returns*: ymdl + (-dm)[.](#nonmembers-8.sentence-1)

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

`constexpr year_month_day_last
  operator+(const year_month_day_last& ymdl, const years& dy) noexcept;
`

[9](#nonmembers-9)

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

*Returns*: {ymdl.year()+dy, ymdl.month_day_last()}[.](#nonmembers-9.sentence-1)

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

`constexpr year_month_day_last
  operator+(const years& dy, const year_month_day_last& ymdl) noexcept;
`

[10](#nonmembers-10)

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

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

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

`constexpr year_month_day_last
  operator-(const year_month_day_last& ymdl, const years& dy) noexcept;
`

[11](#nonmembers-11)

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

*Returns*: ymdl + (-dy)[.](#nonmembers-11.sentence-1)

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

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

[12](#nonmembers-12)

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

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