[time.cal.year]

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

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

### 30.8.5 Class year [time.cal.year]

#### [30.8.5.1](#overview) Overview [[time.cal.year.overview]](time.cal.year.overview)

namespace std::chrono {class year {short y_; // *exposition only*public: year() = default; constexpr explicit year(int y) noexcept; constexpr year& operator++() noexcept; constexpr year operator++(int) noexcept; constexpr year& operator--() noexcept; constexpr year operator--(int) noexcept; constexpr year& operator+=(const years& y) noexcept; constexpr year& operator-=(const years& y) noexcept; constexpr year operator+() const noexcept; constexpr year operator-() const noexcept; constexpr bool is_leap() const noexcept; constexpr explicit operator int() const noexcept; constexpr bool ok() const noexcept; static constexpr year min() noexcept; static constexpr year max() noexcept; };}

[1](#overview-1)

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

year represents a year in the civil calendar[.](#overview-1.sentence-1)

It can represent values in the range [min(), max()][.](#overview-1.sentence-2)

It can be constructed with any int value,
which will be subsequently truncated to fit into year's unspecified internal storage[.](#overview-1.sentence-3)

year 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,
and participates in basic arithmetic with years objects,
which represent a difference between two year objects[.](#overview-1.sentence-4)

[2](#overview-2)

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

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

#### [30.8.5.2](#members) Member functions [[time.cal.year.members]](time.cal.year.members)

[ð](#lib:year,constructor)

`constexpr explicit year(int y) noexcept;
`

[1](#members-1)

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

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

The value held is unspecified if y is not in the range [-32767, 32767][.](#members-1.sentence-2)

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

`constexpr year& operator++() noexcept;
`

[2](#members-2)

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

*Effects*: ++y_[.](#members-2.sentence-1)

[3](#members-3)

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

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

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

`constexpr year operator++(int) noexcept;
`

[4](#members-4)

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

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

[5](#members-5)

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

*Returns*: A copy of *this as it existed on entry to this member function[.](#members-5.sentence-1)

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

`constexpr year& operator--() noexcept;
`

[6](#members-6)

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

*Effects*: --y_[.](#members-6.sentence-1)

[7](#members-7)

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

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

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

`constexpr year operator--(int) noexcept;
`

[8](#members-8)

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

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

[9](#members-9)

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

*Returns*: A copy of *this as it existed on entry to this member function[.](#members-9.sentence-1)

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

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

[10](#members-10)

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

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

[11](#members-11)

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

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

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

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

[12](#members-12)

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

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

[13](#members-13)

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

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

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

`constexpr year operator+() const noexcept;
`

[14](#members-14)

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

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

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

`constexpr year operator-() const noexcept;
`

[15](#members-15)

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

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

[ð](#lib:is_leap,year)

`constexpr bool is_leap() const noexcept;
`

[16](#members-16)

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

*Returns*: y_ % 4 == 0 && (y_ % 100 != 0 || y_ % 400 == 0)[.](#members-16.sentence-1)

[ð](#lib:operator_int,year)

`constexpr explicit operator int() const noexcept;
`

[17](#members-17)

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

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

[ð](#lib:ok,year)

`constexpr bool ok() const noexcept;
`

[18](#members-18)

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

*Returns*: min().y_ <= y_ && y_ <= max().y_[.](#members-18.sentence-1)

[ð](#lib:min,year)

`static constexpr year min() noexcept;
`

[19](#members-19)

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

*Returns*: year{-32767}[.](#members-19.sentence-1)

[ð](#lib:max,year)

`static constexpr year max() noexcept;
`

[20](#members-20)

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

*Returns*: year{32767}[.](#members-20.sentence-1)

#### [30.8.5.3](#nonmembers) Non-member functions [[time.cal.year.nonmembers]](time.cal.year.nonmembers)

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

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

[1](#nonmembers-1)

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

*Returns*: int{x} == int{y}[.](#nonmembers-1.sentence-1)

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

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

[2](#nonmembers-2)

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

*Returns*: int{x} <=> int{y}[.](#nonmembers-2.sentence-1)

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

`constexpr year operator+(const year& x, const years& y) noexcept;
`

[3](#nonmembers-3)

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

*Returns*: year{int{x} + static_cast<int>(y.count())}[.](#nonmembers-3.sentence-1)

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

`constexpr year operator+(const years& x, const year& y) noexcept;
`

[4](#nonmembers-4)

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

*Returns*: y + x[.](#nonmembers-4.sentence-1)

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

`constexpr year operator-(const year& x, const years& y) noexcept;
`

[5](#nonmembers-5)

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

*Returns*: x + -y[.](#nonmembers-5.sentence-1)

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

`constexpr years operator-(const year& x, const year& y) noexcept;
`

[6](#nonmembers-6)

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

*Returns*: years{int{x} - int{y}}[.](#nonmembers-6.sentence-1)

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

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

[7](#nonmembers-7)

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

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

[ð](#lib:from_stream,year)

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

[8](#nonmembers-8)

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

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

If the parse fails to decode a valid year,is.setstate(ios_base​::​failbit) is called andy is not modified[.](#nonmembers-8.sentence-2)

If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#nonmembers-8.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[.](#nonmembers-8.sentence-4)

[9](#nonmembers-9)

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

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

[ð](#lib:operator%22%22y,year)

`constexpr chrono::year operator""y(unsigned long long y) noexcept;
`

[10](#nonmembers-10)

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

*Returns*: year{static_cast<int>(y)}[.](#nonmembers-10.sentence-1)
