[time.cal.ymd.nonmembers]

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

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

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

#### 30.8.14.3 Non-member functions [time.cal.ymd.nonmembers]

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

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

[1](#1)

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

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

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

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

[2](#2)

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

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

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

`constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept;
`

[3](#3)

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

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

[4](#4)

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

*Returns*: (ymd.year() / ymd.month() + dm) / ymd.day()[.](#4.sentence-1)

[5](#5)

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

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

If ymd.day() is in the range [1d, 28d],ok() will return true for
the resultant year_month_day[.](#5.sentence-1)

â *end note*]

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

`constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept;
`

[6](#6)

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

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

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

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

`constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept;
`

[8](#8)

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

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

[9](#9)

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

*Returns*: ymd + (-dm)[.](#9.sentence-1)

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

`constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept;
`

[10](#10)

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

*Returns*: (ymd.year() + dy) / ymd.month() / ymd.day()[.](#10.sentence-1)

[11](#11)

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

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

If ymd.month() is February
and ymd.day() is not in the range [1d, 28d],ok() can return false for
the resultant year_month_day[.](#11.sentence-1)

â *end note*]

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

`constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept;
`

[12](#12)

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

*Returns*: ymd + dy[.](#12.sentence-1)

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

`constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept;
`

[13](#13)

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

*Returns*: ymd + (-dy)[.](#13.sentence-1)

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

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

[14](#14)

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

*Effects*: Equivalent to:return os << (ymd.ok() ? format(*STATICALLY-WIDEN*<charT>("{:%F}"), ymd) : format(*STATICALLY-WIDEN*<charT>("{:%F} is not a valid date"), ymd));

[ð](#lib:from_stream,year_month_day)

`template<class charT, class traits, class Alloc = allocator<charT>>
  basic_istream<charT, traits>&
    from_stream(basic_istream<charT, traits>& is, const charT* fmt,
                year_month_day& ymd, basic_string<charT, traits, Alloc>* abbrev = nullptr,
                minutes* offset = nullptr);
`

[15](#15)

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

*Effects*: Attempts to parse the input stream is into the year_month_day ymd using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13 Parsing")[.](#15.sentence-1)

If the parse fails to decode a valid year_month_day,is.setstate(ios_base​::​failbit) is called andymd is not modified[.](#15.sentence-2)

If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#15.sentence-3)

If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#15.sentence-4)

[16](#16)

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

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