[time.cal.ymd.members]

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

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

### 30.8.14 Class year_month_day [[time.cal.ymd]](time.cal.ymd#members)

#### 30.8.14.2 Member functions [time.cal.ymd.members]

[ð](#lib:year_month_day,constructor)

`constexpr year_month_day(const chrono::year& y, const chrono::month& m,
                         const chrono::day& d) noexcept;
`

[1](#1)

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

*Effects*: Initializesy_ with y,m_ with m, andd_ with d[.](#1.sentence-1)

[ð](#lib:year_month_day,constructor_)

`constexpr year_month_day(const year_month_day_last& ymdl) noexcept;
`

[2](#2)

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

*Effects*: Initializesy_ with ymdl.year(),m_ with ymdl.month(), andd_ with ymdl.day()[.](#2.sentence-1)

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

This conversion from year_month_day_last to year_month_day can be more efficient than converting a year_month_day_last to a sys_days,
and then converting that sys_days to a year_month_day[.](#2.sentence-2)

â *end note*]

[ð](#lib:year_month_day,constructor__)

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

[3](#3)

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

*Effects*: Constructs an object of type year_month_day that corresponds to the date represented by dp[.](#3.sentence-1)

[4](#4)

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

*Remarks*: For any value ymd of type year_month_day for which ymd.ok() is true,ymd == year_month_day{sys_days{ymd}} is true[.](#4.sentence-1)

[ð](#lib:year_month_day,constructor___)

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

[5](#5)

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

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

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

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

[6](#6)

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

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

[7](#7)

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

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

[8](#8)

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

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

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

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

[9](#9)

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

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

[10](#10)

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

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

[11](#11)

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

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

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

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

[12](#12)

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

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

[13](#13)

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

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

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

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

[14](#14)

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

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

[15](#15)

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

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

[ð](#lib:year,year_month_day)

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

[16](#16)

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

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

[ð](#lib:month,year_month_day)

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

[17](#17)

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

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

[ð](#lib:day,year_month_day)

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

[18](#18)

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

*Returns*: d_[.](#18.sentence-1)

[ð](#lib:operator_sys_days,year_month_day)

`constexpr operator sys_days() const noexcept;
`

[19](#19)

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

*Returns*: If ok(),
returns a sys_days holding a count of days from the sys_days epoch to *this (a negative value if *this represents a date prior to the sys_days epoch)[.](#19.sentence-1)

Otherwise, if y_.ok() && m_.ok() is true,
returns sys_days{y_/m_/1d} + (d_ - 1d)[.](#19.sentence-2)

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

[20](#20)

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

*Remarks*: A sys_days in the range [days{-12687428}, days{11248737}]
which is converted to a year_month_day has the same value when converted back to a sys_days[.](#20.sentence-1)

[21](#21)

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

[*Example [1](#example-1)*: static_assert(year_month_day{sys_days{2017y/January/0}} == 2016y/December/31);static_assert(year_month_day{sys_days{2017y/January/31}} == 2017y/January/31);static_assert(year_month_day{sys_days{2017y/January/32}} == 2017y/February/1); â *end example*]

[ð](#lib:operator_local_days,year_month_day)

`constexpr explicit operator local_days() const noexcept;
`

[22](#22)

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

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

[ð](#lib:ok,year_month_day)

`constexpr bool ok() const noexcept;
`

[23](#23)

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

*Returns*: If y_.ok() is true,
and m_.ok() is true,
and d_ is in the range [1d, (y_/m_/last).day()],
then returns true; otherwise returns false[.](#23.sentence-1)
