1*81ad6265SDimitry Andric // -*- C++ -*- 2*81ad6265SDimitry Andric //===----------------------------------------------------------------------===// 3*81ad6265SDimitry Andric // 4*81ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*81ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 6*81ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*81ad6265SDimitry Andric // 8*81ad6265SDimitry Andric //===----------------------------------------------------------------------===// 9*81ad6265SDimitry Andric 10*81ad6265SDimitry Andric #ifndef _LIBCPP___CHRONO_MONTHDAY_H 11*81ad6265SDimitry Andric #define _LIBCPP___CHRONO_MONTHDAY_H 12*81ad6265SDimitry Andric 13*81ad6265SDimitry Andric #include <__chrono/calendar.h> 14*81ad6265SDimitry Andric #include <__chrono/day.h> 15*81ad6265SDimitry Andric #include <__chrono/month.h> 16*81ad6265SDimitry Andric #include <__config> 17*81ad6265SDimitry Andric 18*81ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 19*81ad6265SDimitry Andric # pragma GCC system_header 20*81ad6265SDimitry Andric #endif 21*81ad6265SDimitry Andric 22*81ad6265SDimitry Andric #if _LIBCPP_STD_VER > 17 23*81ad6265SDimitry Andric 24*81ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 25*81ad6265SDimitry Andric 26*81ad6265SDimitry Andric namespace chrono 27*81ad6265SDimitry Andric { 28*81ad6265SDimitry Andric 29*81ad6265SDimitry Andric class month_day { 30*81ad6265SDimitry Andric private: 31*81ad6265SDimitry Andric chrono::month __m; 32*81ad6265SDimitry Andric chrono::day __d; 33*81ad6265SDimitry Andric public: 34*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI month_day() = default; 35*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept 36*81ad6265SDimitry Andric : __m{__mval}, __d{__dval} {} 37*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m; } 38*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d; } 39*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept; 40*81ad6265SDimitry Andric }; 41*81ad6265SDimitry Andric 42*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 43*81ad6265SDimitry Andric bool month_day::ok() const noexcept 44*81ad6265SDimitry Andric { 45*81ad6265SDimitry Andric if (!__m.ok()) return false; 46*81ad6265SDimitry Andric const unsigned __dval = static_cast<unsigned>(__d); 47*81ad6265SDimitry Andric if (__dval < 1 || __dval > 31) return false; 48*81ad6265SDimitry Andric if (__dval <= 29) return true; 49*81ad6265SDimitry Andric // Now we've got either 30 or 31 50*81ad6265SDimitry Andric const unsigned __mval = static_cast<unsigned>(__m); 51*81ad6265SDimitry Andric if (__mval == 2) return false; 52*81ad6265SDimitry Andric if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11) 53*81ad6265SDimitry Andric return __dval == 30; 54*81ad6265SDimitry Andric return true; 55*81ad6265SDimitry Andric } 56*81ad6265SDimitry Andric 57*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 58*81ad6265SDimitry Andric bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept 59*81ad6265SDimitry Andric { return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } 60*81ad6265SDimitry Andric 61*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 62*81ad6265SDimitry Andric bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept 63*81ad6265SDimitry Andric { return !(__lhs == __rhs); } 64*81ad6265SDimitry Andric 65*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 66*81ad6265SDimitry Andric month_day operator/(const month& __lhs, const day& __rhs) noexcept 67*81ad6265SDimitry Andric { return month_day{__lhs, __rhs}; } 68*81ad6265SDimitry Andric 69*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 70*81ad6265SDimitry Andric month_day operator/(const day& __lhs, const month& __rhs) noexcept 71*81ad6265SDimitry Andric { return __rhs / __lhs; } 72*81ad6265SDimitry Andric 73*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 74*81ad6265SDimitry Andric month_day operator/(const month& __lhs, int __rhs) noexcept 75*81ad6265SDimitry Andric { return __lhs / day(__rhs); } 76*81ad6265SDimitry Andric 77*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 78*81ad6265SDimitry Andric month_day operator/(int __lhs, const day& __rhs) noexcept 79*81ad6265SDimitry Andric { return month(__lhs) / __rhs; } 80*81ad6265SDimitry Andric 81*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 82*81ad6265SDimitry Andric month_day operator/(const day& __lhs, int __rhs) noexcept 83*81ad6265SDimitry Andric { return month(__rhs) / __lhs; } 84*81ad6265SDimitry Andric 85*81ad6265SDimitry Andric 86*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 87*81ad6265SDimitry Andric bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept 88*81ad6265SDimitry Andric { return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); } 89*81ad6265SDimitry Andric 90*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 91*81ad6265SDimitry Andric bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept 92*81ad6265SDimitry Andric { return __rhs < __lhs; } 93*81ad6265SDimitry Andric 94*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 95*81ad6265SDimitry Andric bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept 96*81ad6265SDimitry Andric { return !(__rhs < __lhs);} 97*81ad6265SDimitry Andric 98*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 99*81ad6265SDimitry Andric bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept 100*81ad6265SDimitry Andric { return !(__lhs < __rhs); } 101*81ad6265SDimitry Andric 102*81ad6265SDimitry Andric 103*81ad6265SDimitry Andric 104*81ad6265SDimitry Andric class month_day_last { 105*81ad6265SDimitry Andric private: 106*81ad6265SDimitry Andric chrono::month __m; 107*81ad6265SDimitry Andric public: 108*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit constexpr month_day_last(const chrono::month& __val) noexcept 109*81ad6265SDimitry Andric : __m{__val} {} 110*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m; } 111*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m.ok(); } 112*81ad6265SDimitry Andric }; 113*81ad6265SDimitry Andric 114*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 115*81ad6265SDimitry Andric bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 116*81ad6265SDimitry Andric { return __lhs.month() == __rhs.month(); } 117*81ad6265SDimitry Andric 118*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 119*81ad6265SDimitry Andric bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 120*81ad6265SDimitry Andric { return !(__lhs == __rhs); } 121*81ad6265SDimitry Andric 122*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 123*81ad6265SDimitry Andric bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept 124*81ad6265SDimitry Andric { return __lhs.month() < __rhs.month(); } 125*81ad6265SDimitry Andric 126*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 127*81ad6265SDimitry Andric bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept 128*81ad6265SDimitry Andric { return __rhs < __lhs; } 129*81ad6265SDimitry Andric 130*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 131*81ad6265SDimitry Andric bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 132*81ad6265SDimitry Andric { return !(__rhs < __lhs);} 133*81ad6265SDimitry Andric 134*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 135*81ad6265SDimitry Andric bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 136*81ad6265SDimitry Andric { return !(__lhs < __rhs); } 137*81ad6265SDimitry Andric 138*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 139*81ad6265SDimitry Andric month_day_last operator/(const month& __lhs, last_spec) noexcept 140*81ad6265SDimitry Andric { return month_day_last{__lhs}; } 141*81ad6265SDimitry Andric 142*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 143*81ad6265SDimitry Andric month_day_last operator/(last_spec, const month& __rhs) noexcept 144*81ad6265SDimitry Andric { return month_day_last{__rhs}; } 145*81ad6265SDimitry Andric 146*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 147*81ad6265SDimitry Andric month_day_last operator/(int __lhs, last_spec) noexcept 148*81ad6265SDimitry Andric { return month_day_last{month(__lhs)}; } 149*81ad6265SDimitry Andric 150*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 151*81ad6265SDimitry Andric month_day_last operator/(last_spec, int __rhs) noexcept 152*81ad6265SDimitry Andric { return month_day_last{month(__rhs)}; } 153*81ad6265SDimitry Andric 154*81ad6265SDimitry Andric } // namespace chrono 155*81ad6265SDimitry Andric 156*81ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD 157*81ad6265SDimitry Andric 158*81ad6265SDimitry Andric #endif // _LIBCPP_STD_VER > 17 159*81ad6265SDimitry Andric 160*81ad6265SDimitry Andric #endif // _LIBCPP___CHRONO_MONTHDAY_H 161