[time.cal.month]

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

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

### 30.8.4 Class month [time.cal.month]

#### [30.8.4.1](#overview) Overview [[time.cal.month.overview]](time.cal.month.overview)

namespace std::chrono {class month {unsigned char m_; // *exposition only*public: month() = default; constexpr explicit month(unsigned m) noexcept; constexpr month& operator++() noexcept; constexpr month operator++(int) noexcept; constexpr month& operator--() noexcept; constexpr month operator--(int) noexcept; constexpr month& operator+=(const months& m) noexcept; constexpr month& operator-=(const months& m) noexcept; constexpr explicit operator unsigned() const noexcept; constexpr bool ok() const noexcept; };}

[1](#overview-1)

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

month represents a month of a year[.](#overview-1.sentence-1)

It normally holds values in the range 1 to 12,
but may hold non-negative values outside this range[.](#overview-1.sentence-2)

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

month 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 months objects,
which represent a difference between two month objects[.](#overview-1.sentence-4)

[2](#overview-2)

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

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

#### [30.8.4.2](#members) Member functions [[time.cal.month.members]](time.cal.month.members)

[ð](#lib:month,constructor)

`constexpr explicit month(unsigned m) noexcept;
`

[1](#members-1)

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

*Effects*: Initializes m_ with m[.](#members-1.sentence-1)

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

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

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

[2](#members-2)

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

*Effects*: *this += months{1}[.](#members-2.sentence-1)

[3](#members-3)

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

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

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

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

[4](#members-4)

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

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

[5](#members-5)

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

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

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

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

[6](#members-6)

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

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

[7](#members-7)

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

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

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

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

[8](#members-8)

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

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

[9](#members-9)

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

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

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

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

[10](#members-10)

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

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

[11](#members-11)

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

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

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

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

[12](#members-12)

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

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

[13](#members-13)

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

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

[ð](#lib:operator_unsigned,month)

`constexpr explicit operator unsigned() const noexcept;
`

[14](#members-14)

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

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

[ð](#lib:ok,month)

`constexpr bool ok() const noexcept;
`

[15](#members-15)

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

*Returns*: 1 <= m_ && m_ <= 12[.](#members-15.sentence-1)

#### [30.8.4.3](#nonmembers) Non-member functions [[time.cal.month.nonmembers]](time.cal.month.nonmembers)

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

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

[1](#nonmembers-1)

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

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

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

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

[2](#nonmembers-2)

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

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

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

`constexpr month operator+(const month& x, const months& y) noexcept;
`

[3](#nonmembers-3)

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

*Returns*: month{modulo(static_cast<long long>(unsigned{x}) + (y.count() - 1), 12) + 1} where modulo(n, 12) computes the remainder of n divided by 12 using Euclidean division[.](#nonmembers-3.sentence-1)

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

Given a divisor of 12, Euclidean division truncates towards negative infinity and
always produces a remainder in the range of [0, 11][.](#nonmembers-3.sentence-2)

Assuming no overflow in the signed summation,
this operation results in a month holding a value in the range [1, 12] even if !x.ok()[.](#nonmembers-3.sentence-3)

â *end note*]

[*Example [1](#nonmembers-example-1)*:

February + months{11} == January[.](#nonmembers-3.sentence-4)

â *end example*]

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

`constexpr month operator+(const months& x, const month& y) noexcept;
`

[4](#nonmembers-4)

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

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

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

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

[5](#nonmembers-5)

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

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

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

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

[6](#nonmembers-6)

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

*Returns*: If x.ok() == true and y.ok() == true,
returns a value m in the range [months{0}, months{11}]
satisfying y + m == x[.](#nonmembers-6.sentence-1)

Otherwise the value returned is unspecified[.](#nonmembers-6.sentence-2)

[*Example [2](#nonmembers-example-2)*:

January - February == months{11}[.](#nonmembers-6.sentence-3)

â *end example*]

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

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

[7](#nonmembers-7)

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

*Effects*: Equivalent to:return os << (m.ok() ? format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%b}"), m) : format(os.getloc(), *STATICALLY-WIDEN*<charT>("{} is not a valid month"), static_cast<unsigned>(m)));

[ð](#lib:from_stream,month)

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

[8](#nonmembers-8)

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

*Effects*: Attempts to parse the input stream is into the month m 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 month,is.setstate(ios_base​::​failbit) is called andm 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#L4532)

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