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>
14 #include <__compare/ordering.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
34 : __m_(static_cast<unsigned char>(__val
)) {}
35 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
& operator++() noexcept
{
39 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
operator++(int) noexcept
{
44 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
& operator--() noexcept
{
48 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
operator--(int) noexcept
{
53 _LIBCPP_HIDE_FROM_ABI
constexpr month
& operator+=(const months
& __m1
) noexcept
;
54 _LIBCPP_HIDE_FROM_ABI
constexpr month
& operator-=(const months
& __m1
) noexcept
;
55 _LIBCPP_HIDE_FROM_ABI
explicit inline constexpr operator unsigned() const noexcept
{ return __m_
; }
56 _LIBCPP_HIDE_FROM_ABI
inline constexpr bool ok() const noexcept
{ return __m_
>= 1 && __m_
<= 12; }
59 _LIBCPP_HIDE_FROM_ABI
inline constexpr bool operator==(const month
& __lhs
, const month
& __rhs
) noexcept
{
60 return static_cast<unsigned>(__lhs
) == static_cast<unsigned>(__rhs
);
63 _LIBCPP_HIDE_FROM_ABI
inline constexpr strong_ordering
operator<=>(const month
& __lhs
, const month
& __rhs
) noexcept
{
64 return static_cast<unsigned>(__lhs
) <=> static_cast<unsigned>(__rhs
);
67 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
operator+(const month
& __lhs
, const months
& __rhs
) noexcept
{
68 auto const __mu
= static_cast<long long>(static_cast<unsigned>(__lhs
)) + (__rhs
.count() - 1);
69 auto const __yr
= (__mu
>= 0 ? __mu
: __mu
- 11) / 12;
70 return month
{static_cast<unsigned>(__mu
- __yr
* 12 + 1)};
73 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
operator+(const months
& __lhs
, const month
& __rhs
) noexcept
{
77 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
operator-(const month
& __lhs
, const months
& __rhs
) noexcept
{
78 return __lhs
+ -__rhs
;
81 _LIBCPP_HIDE_FROM_ABI
inline constexpr months
operator-(const month
& __lhs
, const month
& __rhs
) noexcept
{
82 auto const __dm
= static_cast<unsigned>(__lhs
) - static_cast<unsigned>(__rhs
);
83 return months(__dm
<= 11 ? __dm
: __dm
+ 12);
86 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
& month::operator+=(const months
& __dm
) noexcept
{
91 _LIBCPP_HIDE_FROM_ABI
inline constexpr month
& month::operator-=(const months
& __dm
) noexcept
{
96 inline constexpr month January
{1};
97 inline constexpr month February
{2};
98 inline constexpr month March
{3};
99 inline constexpr month April
{4};
100 inline constexpr month May
{5};
101 inline constexpr month June
{6};
102 inline constexpr month July
{7};
103 inline constexpr month August
{8};
104 inline constexpr month September
{9};
105 inline constexpr month October
{10};
106 inline constexpr month November
{11};
107 inline constexpr month December
{12};
109 } // namespace chrono
111 _LIBCPP_END_NAMESPACE_STD
113 #endif // _LIBCPP_STD_VER >= 20
115 #endif // _LIBCPP___CHRONO_MONTH_H