[time.cal.month.nonmembers] (original) (raw)

30 Time library [time]

30.8 The civil calendar [time.cal]

30.8.4 Class month [time.cal.month]

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

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

Returns: unsigned{x} == unsigned{y}.

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

Returns: unsigned{x} <=> unsigned{y}.

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

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.

[Note 1:

Given a divisor of 12, Euclidean division truncates towards negative infinity and always produces a remainder in the range of [0, 11].

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().

— _end note_]

[Example 1:

February + months{11} == January.

— _end example_]

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

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

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

Returns: If x.ok() == trueand y.ok() == true, returns a value min the range [months{0}, months{11}] satisfying y + m == x.

Otherwise the value returned is unspecified.

[Example 2:

January - February == months{11}.

— _end example_]

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

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)));

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);

Effects: Attempts to parse the input stream isinto the month m using the format flags given in the NTCTS fmtas specified in [time.parse].

If the parse fails to decode a valid month,is.setstate(ios_base​::​failbit) is called andm is not modified.

If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null.

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