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_MONTHDAY_H
11 #define _LIBCPP___CHRONO_MONTHDAY_H
13 #include <__chrono/calendar.h>
14 #include <__chrono/day.h>
15 #include <__chrono/month.h>
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 # pragma GCC system_header
23 #if _LIBCPP_STD_VER >= 20
25 _LIBCPP_BEGIN_NAMESPACE_STD
35 month_day() = default;
36 _LIBCPP_HIDE_FROM_ABI
constexpr month_day(const chrono::month
& __mval
, const chrono::day
& __dval
) noexcept
37 : __m_
{__mval
}, __d_
{__dval
} {}
38 _LIBCPP_HIDE_FROM_ABI
inline constexpr chrono::month
month() const noexcept
{ return __m_
; }
39 _LIBCPP_HIDE_FROM_ABI
inline constexpr chrono::day
day() const noexcept
{ return __d_
; }
40 _LIBCPP_HIDE_FROM_ABI
constexpr bool ok() const noexcept
;
43 _LIBCPP_HIDE_FROM_ABI
inline constexpr
44 bool month_day::ok() const noexcept
46 if (!__m_
.ok()) return false;
47 const unsigned __dval
= static_cast<unsigned>(__d_
);
48 if (__dval
< 1 || __dval
> 31) return false;
49 if (__dval
<= 29) return true;
50 // Now we've got either 30 or 31
51 const unsigned __mval
= static_cast<unsigned>(__m_
);
52 if (__mval
== 2) return false;
53 if (__mval
== 4 || __mval
== 6 || __mval
== 9 || __mval
== 11)
58 _LIBCPP_HIDE_FROM_ABI
inline constexpr
59 bool operator==(const month_day
& __lhs
, const month_day
& __rhs
) noexcept
60 { return __lhs
.month() == __rhs
.month() && __lhs
.day() == __rhs
.day(); }
62 _LIBCPP_HIDE_FROM_ABI
constexpr strong_ordering
operator<=>(const month_day
& __lhs
, const month_day
& __rhs
) noexcept
{
63 if (auto __c
= __lhs
.month() <=> __rhs
.month(); __c
!= 0)
65 return __lhs
.day() <=> __rhs
.day();
68 _LIBCPP_HIDE_FROM_ABI
inline constexpr
69 month_day
operator/(const month
& __lhs
, const day
& __rhs
) noexcept
70 { return month_day
{__lhs
, __rhs
}; }
72 _LIBCPP_HIDE_FROM_ABI
constexpr
73 month_day
operator/(const day
& __lhs
, const month
& __rhs
) noexcept
74 { return __rhs
/ __lhs
; }
76 _LIBCPP_HIDE_FROM_ABI
inline constexpr
77 month_day
operator/(const month
& __lhs
, int __rhs
) noexcept
78 { return __lhs
/ day(__rhs
); }
80 _LIBCPP_HIDE_FROM_ABI
constexpr
81 month_day
operator/(int __lhs
, const day
& __rhs
) noexcept
82 { return month(__lhs
) / __rhs
; }
84 _LIBCPP_HIDE_FROM_ABI
constexpr
85 month_day
operator/(const day
& __lhs
, int __rhs
) noexcept
86 { return month(__rhs
) / __lhs
; }
88 class month_day_last
{
92 _LIBCPP_HIDE_FROM_ABI
explicit constexpr month_day_last(const chrono::month
& __val
) noexcept
94 _LIBCPP_HIDE_FROM_ABI
inline constexpr chrono::month
month() const noexcept
{ return __m_
; }
95 _LIBCPP_HIDE_FROM_ABI
inline constexpr bool ok() const noexcept
{ return __m_
.ok(); }
98 _LIBCPP_HIDE_FROM_ABI
inline constexpr
99 bool operator==(const month_day_last
& __lhs
, const month_day_last
& __rhs
) noexcept
100 { return __lhs
.month() == __rhs
.month(); }
102 _LIBCPP_HIDE_FROM_ABI
constexpr strong_ordering
103 operator<=>(const month_day_last
& __lhs
, const month_day_last
& __rhs
) noexcept
{
104 return __lhs
.month() <=> __rhs
.month();
107 _LIBCPP_HIDE_FROM_ABI
inline constexpr
108 month_day_last
operator/(const month
& __lhs
, last_spec
) noexcept
109 { return month_day_last
{__lhs
}; }
111 _LIBCPP_HIDE_FROM_ABI
inline constexpr
112 month_day_last
operator/(last_spec
, const month
& __rhs
) noexcept
113 { return month_day_last
{__rhs
}; }
115 _LIBCPP_HIDE_FROM_ABI
inline constexpr
116 month_day_last
operator/(int __lhs
, last_spec
) noexcept
117 { return month_day_last
{month(__lhs
)}; }
119 _LIBCPP_HIDE_FROM_ABI
inline constexpr
120 month_day_last
operator/(last_spec
, int __rhs
) noexcept
121 { return month_day_last
{month(__rhs
)}; }
123 } // namespace chrono
125 _LIBCPP_END_NAMESPACE_STD
127 #endif // _LIBCPP_STD_VER >= 20
129 #endif // _LIBCPP___CHRONO_MONTHDAY_H