181ad6265SDimitry Andric // -*- C++ -*- 281ad6265SDimitry Andric //===----------------------------------------------------------------------===// 381ad6265SDimitry Andric // 481ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 581ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 681ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 781ad6265SDimitry Andric // 881ad6265SDimitry Andric //===----------------------------------------------------------------------===// 981ad6265SDimitry Andric 1081ad6265SDimitry Andric #ifndef _LIBCPP___CHRONO_MONTHDAY_H 1181ad6265SDimitry Andric #define _LIBCPP___CHRONO_MONTHDAY_H 1281ad6265SDimitry Andric 1381ad6265SDimitry Andric #include <__chrono/calendar.h> 1481ad6265SDimitry Andric #include <__chrono/day.h> 1581ad6265SDimitry Andric #include <__chrono/month.h> 1681ad6265SDimitry Andric #include <__config> 17bdd1243dSDimitry Andric #include <compare> 1881ad6265SDimitry Andric 1981ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2081ad6265SDimitry Andric # pragma GCC system_header 2181ad6265SDimitry Andric #endif 2281ad6265SDimitry Andric 2306c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20 2481ad6265SDimitry Andric 2581ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 2681ad6265SDimitry Andric 2781ad6265SDimitry Andric namespace chrono 2881ad6265SDimitry Andric { 2981ad6265SDimitry Andric 3081ad6265SDimitry Andric class month_day { 3181ad6265SDimitry Andric private: 32bdd1243dSDimitry Andric chrono::month __m_; 33bdd1243dSDimitry Andric chrono::day __d_; 3481ad6265SDimitry Andric public: 3506c3fb27SDimitry Andric month_day() = default; 3681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept 37bdd1243dSDimitry Andric : __m_{__mval}, __d_{__dval} {} 38bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } 39bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; } 4081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept; 4181ad6265SDimitry Andric }; 4281ad6265SDimitry Andric 4381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 4481ad6265SDimitry Andric bool month_day::ok() const noexcept 4581ad6265SDimitry Andric { 46bdd1243dSDimitry Andric if (!__m_.ok()) return false; 47bdd1243dSDimitry Andric const unsigned __dval = static_cast<unsigned>(__d_); 4881ad6265SDimitry Andric if (__dval < 1 || __dval > 31) return false; 4981ad6265SDimitry Andric if (__dval <= 29) return true; 5081ad6265SDimitry Andric // Now we've got either 30 or 31 51bdd1243dSDimitry Andric const unsigned __mval = static_cast<unsigned>(__m_); 5281ad6265SDimitry Andric if (__mval == 2) return false; 5381ad6265SDimitry Andric if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11) 5481ad6265SDimitry Andric return __dval == 30; 5581ad6265SDimitry Andric return true; 5681ad6265SDimitry Andric } 5781ad6265SDimitry Andric 5881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 5981ad6265SDimitry Andric bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept 6081ad6265SDimitry Andric { return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } 6181ad6265SDimitry Andric 62*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept { 63bdd1243dSDimitry Andric if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0) 64bdd1243dSDimitry Andric return __c; 65bdd1243dSDimitry Andric return __lhs.day() <=> __rhs.day(); 66bdd1243dSDimitry Andric } 6781ad6265SDimitry Andric 6881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 6981ad6265SDimitry Andric month_day operator/(const month& __lhs, const day& __rhs) noexcept 7081ad6265SDimitry Andric { return month_day{__lhs, __rhs}; } 7181ad6265SDimitry Andric 72*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 7381ad6265SDimitry Andric month_day operator/(const day& __lhs, const month& __rhs) noexcept 7481ad6265SDimitry Andric { return __rhs / __lhs; } 7581ad6265SDimitry Andric 7681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 7781ad6265SDimitry Andric month_day operator/(const month& __lhs, int __rhs) noexcept 7881ad6265SDimitry Andric { return __lhs / day(__rhs); } 7981ad6265SDimitry Andric 80*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 8181ad6265SDimitry Andric month_day operator/(int __lhs, const day& __rhs) noexcept 8281ad6265SDimitry Andric { return month(__lhs) / __rhs; } 8381ad6265SDimitry Andric 84*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 8581ad6265SDimitry Andric month_day operator/(const day& __lhs, int __rhs) noexcept 8681ad6265SDimitry Andric { return month(__rhs) / __lhs; } 8781ad6265SDimitry Andric 8881ad6265SDimitry Andric class month_day_last { 8981ad6265SDimitry Andric private: 90bdd1243dSDimitry Andric chrono::month __m_; 9181ad6265SDimitry Andric public: 9281ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit constexpr month_day_last(const chrono::month& __val) noexcept 93bdd1243dSDimitry Andric : __m_{__val} {} 94bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } 95bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok(); } 9681ad6265SDimitry Andric }; 9781ad6265SDimitry Andric 9881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 9981ad6265SDimitry Andric bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 10081ad6265SDimitry Andric { return __lhs.month() == __rhs.month(); } 10181ad6265SDimitry Andric 102*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering 103bdd1243dSDimitry Andric operator<=>(const month_day_last& __lhs, const month_day_last& __rhs) noexcept { 104bdd1243dSDimitry Andric return __lhs.month() <=> __rhs.month(); 105bdd1243dSDimitry Andric } 10681ad6265SDimitry Andric 10781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 10881ad6265SDimitry Andric month_day_last operator/(const month& __lhs, last_spec) noexcept 10981ad6265SDimitry Andric { return month_day_last{__lhs}; } 11081ad6265SDimitry Andric 11181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 11281ad6265SDimitry Andric month_day_last operator/(last_spec, const month& __rhs) noexcept 11381ad6265SDimitry Andric { return month_day_last{__rhs}; } 11481ad6265SDimitry Andric 11581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 11681ad6265SDimitry Andric month_day_last operator/(int __lhs, last_spec) noexcept 11781ad6265SDimitry Andric { return month_day_last{month(__lhs)}; } 11881ad6265SDimitry Andric 11981ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 12081ad6265SDimitry Andric month_day_last operator/(last_spec, int __rhs) noexcept 12181ad6265SDimitry Andric { return month_day_last{month(__rhs)}; } 12281ad6265SDimitry Andric 12381ad6265SDimitry Andric } // namespace chrono 12481ad6265SDimitry Andric 12581ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD 12681ad6265SDimitry Andric 12706c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20 12881ad6265SDimitry Andric 12981ad6265SDimitry Andric #endif // _LIBCPP___CHRONO_MONTHDAY_H 130