2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___CHRONO_MONTH_H
11 #define _LIBCPP___CHRONO_MONTH_H
13 #include <__chrono/duration.h>
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 # pragma GCC system_header
21 #if _LIBCPP_STD_VER >= 20
23 _LIBCPP_BEGIN_NAMESPACE_STD
33 _LIBCPP_HIDE_FROM_ABI
explicit inline constexpr month(unsigned __val
) noexcept
: __m_(static_cast<unsigned char>(__val
)) {}
34 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
& operator++() noexcept
{ *this += months
{1}; return *this; }
35 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
operator++(int) noexcept
{ month __tmp
= *this; ++(*this); return __tmp
; }
36 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
& operator--() noexcept
{ *this -= months
{1}; return *this; }
37 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
operator--(int) noexcept
{ month __tmp
= *this; --(*this); return __tmp
; }
38 _LIBCPP_HIDE_FROM_ABI
constexpr month
& operator+=(const months
& __m1
) noexcept
;
39 _LIBCPP_HIDE_FROM_ABI
constexpr month
& operator-=(const months
& __m1
) noexcept
;
40 _LIBCPP_HIDE_FROM_ABI
explicit inline constexpr operator unsigned() const noexcept
{ return __m_
; }
41 _LIBCPP_HIDE_FROM_ABI
inline constexpr bool ok() const noexcept
{ return __m_
>= 1 && __m_
<= 12; }
45 _LIBCPP_HIDE_FROM_ABI
inline constexpr
46 bool operator==(const month
& __lhs
, const month
& __rhs
) noexcept
47 { return static_cast<unsigned>(__lhs
) == static_cast<unsigned>(__rhs
); }
49 _LIBCPP_HIDE_FROM_ABI
constexpr strong_ordering
operator<=>(const month
& __lhs
, const month
& __rhs
) noexcept
{
50 return static_cast<unsigned>(__lhs
) <=> static_cast<unsigned>(__rhs
);
53 _LIBCPP_HIDE_FROM_ABI
inline constexpr
54 month
operator+ (const month
& __lhs
, const months
& __rhs
) noexcept
56 auto const __mu
= static_cast<long long>(static_cast<unsigned>(__lhs
)) + (__rhs
.count() - 1);
57 auto const __yr
= (__mu
>= 0 ? __mu
: __mu
- 11) / 12;
58 return month
{static_cast<unsigned>(__mu
- __yr
* 12 + 1)};
61 _LIBCPP_HIDE_FROM_ABI
inline constexpr
62 month
operator+ (const months
& __lhs
, const month
& __rhs
) noexcept
63 { return __rhs
+ __lhs
; }
65 _LIBCPP_HIDE_FROM_ABI
inline constexpr
66 month
operator- (const month
& __lhs
, const months
& __rhs
) noexcept
67 { return __lhs
+ -__rhs
; }
69 _LIBCPP_HIDE_FROM_ABI
inline constexpr
70 months
operator-(const month
& __lhs
, const month
& __rhs
) noexcept
72 auto const __dm
= static_cast<unsigned>(__lhs
) - static_cast<unsigned>(__rhs
);
73 return months(__dm
<= 11 ? __dm
: __dm
+ 12);
76 _LIBCPP_HIDE_FROM_ABI
inline constexpr
77 month
& month::operator+=(const months
& __dm
) noexcept
78 { *this = *this + __dm
; return *this; }
80 _LIBCPP_HIDE_FROM_ABI
inline constexpr
81 month
& month::operator-=(const months
& __dm
) noexcept
82 { *this = *this - __dm
; return *this; }
84 inline constexpr month January
{1};
85 inline constexpr month February
{2};
86 inline constexpr month March
{3};
87 inline constexpr month April
{4};
88 inline constexpr month May
{5};
89 inline constexpr month June
{6};
90 inline constexpr month July
{7};
91 inline constexpr month August
{8};
92 inline constexpr month September
{9};
93 inline constexpr month October
{10};
94 inline constexpr month November
{11};
95 inline constexpr month December
{12};
99 _LIBCPP_END_NAMESPACE_STD
101 #endif // _LIBCPP_STD_VER >= 20
103 #endif // _LIBCPP___CHRONO_MONTH_H