1d7862497SMark de Wever // -*- C++ -*- 2d7862497SMark de Wever //===----------------------------------------------------------------------===// 3d7862497SMark de Wever // 4d7862497SMark de Wever // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5d7862497SMark de Wever // See https://llvm.org/LICENSE.txt for license information. 6d7862497SMark de Wever // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7d7862497SMark de Wever // 8d7862497SMark de Wever //===----------------------------------------------------------------------===// 9d7862497SMark de Wever 10d7862497SMark de Wever #ifndef _LIBCPP___CHRONO_MONTHDAY_H 11d7862497SMark de Wever #define _LIBCPP___CHRONO_MONTHDAY_H 12d7862497SMark de Wever 13d7862497SMark de Wever #include <__chrono/calendar.h> 14d7862497SMark de Wever #include <__chrono/day.h> 15d7862497SMark de Wever #include <__chrono/month.h> 16*09e3a360SLouis Dionne #include <__compare/ordering.h> 17d7862497SMark de Wever #include <__config> 18d7862497SMark de Wever 19d7862497SMark de Wever #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 20d7862497SMark de Wever # pragma GCC system_header 21d7862497SMark de Wever #endif 22d7862497SMark de Wever 234f15267dSNikolas Klauser #if _LIBCPP_STD_VER >= 20 24d7862497SMark de Wever 25d7862497SMark de Wever _LIBCPP_BEGIN_NAMESPACE_STD 26d7862497SMark de Wever 279783f28cSLouis Dionne namespace chrono { 28d7862497SMark de Wever 29d7862497SMark de Wever class month_day { 30d7862497SMark de Wever private: 3184fc2c3cSNikolas Klauser chrono::month __m_; 3284fc2c3cSNikolas Klauser chrono::day __d_; 339783f28cSLouis Dionne 34d7862497SMark de Wever public: 3583ce1397SNikolas Klauser month_day() = default; 36d7862497SMark de Wever _LIBCPP_HIDE_FROM_ABI constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept 3784fc2c3cSNikolas Klauser : __m_{__mval}, __d_{__dval} {} 3884fc2c3cSNikolas Klauser _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } 3984fc2c3cSNikolas Klauser _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; } 40d7862497SMark de Wever _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept; 41d7862497SMark de Wever }; 42d7862497SMark de Wever 439783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr bool month_day::ok() const noexcept { 449783f28cSLouis Dionne if (!__m_.ok()) 459783f28cSLouis Dionne return false; 4684fc2c3cSNikolas Klauser const unsigned __dval = static_cast<unsigned>(__d_); 479783f28cSLouis Dionne if (__dval < 1 || __dval > 31) 489783f28cSLouis Dionne return false; 499783f28cSLouis Dionne if (__dval <= 29) 509783f28cSLouis Dionne return true; 51d7862497SMark de Wever // Now we've got either 30 or 31 5284fc2c3cSNikolas Klauser const unsigned __mval = static_cast<unsigned>(__m_); 539783f28cSLouis Dionne if (__mval == 2) 549783f28cSLouis Dionne return false; 55d7862497SMark de Wever if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11) 56d7862497SMark de Wever return __dval == 30; 57d7862497SMark de Wever return true; 58d7862497SMark de Wever } 59d7862497SMark de Wever 609783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept { 619783f28cSLouis Dionne return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); 629783f28cSLouis Dionne } 63d7862497SMark de Wever 649783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering 659783f28cSLouis Dionne operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept { 6641f7bb99SMark de Wever if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0) 6741f7bb99SMark de Wever return __c; 6841f7bb99SMark de Wever return __lhs.day() <=> __rhs.day(); 6941f7bb99SMark de Wever } 70d7862497SMark de Wever 719783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, const day& __rhs) noexcept { 729783f28cSLouis Dionne return month_day{__lhs, __rhs}; 739783f28cSLouis Dionne } 74d7862497SMark de Wever 759783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, const month& __rhs) noexcept { 769783f28cSLouis Dionne return __rhs / __lhs; 779783f28cSLouis Dionne } 78d7862497SMark de Wever 799783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, int __rhs) noexcept { 809783f28cSLouis Dionne return __lhs / day(__rhs); 819783f28cSLouis Dionne } 82d7862497SMark de Wever 839783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(int __lhs, const day& __rhs) noexcept { 849783f28cSLouis Dionne return month(__lhs) / __rhs; 859783f28cSLouis Dionne } 86d7862497SMark de Wever 879783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, int __rhs) noexcept { 889783f28cSLouis Dionne return month(__rhs) / __lhs; 899783f28cSLouis Dionne } 90d7862497SMark de Wever 91d7862497SMark de Wever class month_day_last { 92d7862497SMark de Wever private: 9384fc2c3cSNikolas Klauser chrono::month __m_; 949783f28cSLouis Dionne 95d7862497SMark de Wever public: 969783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI explicit constexpr month_day_last(const chrono::month& __val) noexcept : __m_{__val} {} 9784fc2c3cSNikolas Klauser _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } 9884fc2c3cSNikolas Klauser _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok(); } 99d7862497SMark de Wever }; 100d7862497SMark de Wever 1019783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr bool 1029783f28cSLouis Dionne operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept { 1039783f28cSLouis Dionne return __lhs.month() == __rhs.month(); 1049783f28cSLouis Dionne } 105d7862497SMark de Wever 106b81c6941SLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering 10741f7bb99SMark de Wever operator<=>(const month_day_last& __lhs, const month_day_last& __rhs) noexcept { 10841f7bb99SMark de Wever return __lhs.month() <=> __rhs.month(); 10941f7bb99SMark de Wever } 110d7862497SMark de Wever 1119783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(const month& __lhs, last_spec) noexcept { 1129783f28cSLouis Dionne return month_day_last{__lhs}; 1139783f28cSLouis Dionne } 114d7862497SMark de Wever 1159783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, const month& __rhs) noexcept { 1169783f28cSLouis Dionne return month_day_last{__rhs}; 1179783f28cSLouis Dionne } 118d7862497SMark de Wever 1199783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(int __lhs, last_spec) noexcept { 1209783f28cSLouis Dionne return month_day_last{month(__lhs)}; 1219783f28cSLouis Dionne } 122d7862497SMark de Wever 1239783f28cSLouis Dionne _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, int __rhs) noexcept { 1249783f28cSLouis Dionne return month_day_last{month(__rhs)}; 1259783f28cSLouis Dionne } 126d7862497SMark de Wever 127d7862497SMark de Wever } // namespace chrono 128d7862497SMark de Wever 129d7862497SMark de Wever _LIBCPP_END_NAMESPACE_STD 130d7862497SMark de Wever 1314f15267dSNikolas Klauser #endif // _LIBCPP_STD_VER >= 20 132d7862497SMark de Wever 133d7862497SMark de Wever #endif // _LIBCPP___CHRONO_MONTHDAY_H 134