[time.cal.ym.nonmembers]

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

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

### 30.8.13 Class year_month [[time.cal.ym]](time.cal.ym#nonmembers)

#### 30.8.13.3 Non-member functions [time.cal.ym.nonmembers]

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

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

[1](#1)

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

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

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

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

[2](#2)

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

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

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

`constexpr year_month operator+(const year_month& ym, const months& dm) noexcept;
`

[3](#3)

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

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

*Returns*: A year_month value z such that z.ok() && z - ym == dm is true[.](#4.sentence-1)

[5](#5)

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

*Complexity*: O(1) with respect to the value of dm[.](#5.sentence-1)

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

`constexpr year_month operator+(const months& dm, const year_month& ym) noexcept;
`

[6](#6)

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

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

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

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

`constexpr year_month operator-(const year_month& ym, const months& dm) noexcept;
`

[8](#8)

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

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

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

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

`constexpr months operator-(const year_month& x, const year_month& y) noexcept;
`

[10](#10)

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

*Returns*: x.year() - y.year() + months{static_cast<int>(unsigned{x.month()}) -static_cast<int>(unsigned{y.month()})}

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

`constexpr year_month operator+(const year_month& ym, const years& dy) noexcept;
`

[11](#11)

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

*Returns*: (ym.year() + dy) / ym.month()[.](#11.sentence-1)

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

`constexpr year_month operator+(const years& dy, const year_month& ym) noexcept;
`

[12](#12)

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

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

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

`constexpr year_month operator-(const year_month& ym, const years& dy) noexcept;
`

[13](#13)

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

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

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

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

[14](#14)

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

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

[ð](#lib:from_stream,year_month)

`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& ym, basic_string<charT, traits, Alloc>* abbrev = nullptr,
                minutes* offset = nullptr);
`

[15](#15)

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

*Effects*: Attempts to parse the input stream is into the year_month ym 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,is.setstate(ios_base​::​failbit) is called andym 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#L6322)

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