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_MONTH_H 11*81ad6265SDimitry Andric #define _LIBCPP___CHRONO_MONTH_H 12*81ad6265SDimitry Andric 13*81ad6265SDimitry Andric #include <__chrono/duration.h> 14*81ad6265SDimitry Andric #include <__config> 15*81ad6265SDimitry Andric 16*81ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17*81ad6265SDimitry Andric # pragma GCC system_header 18*81ad6265SDimitry Andric #endif 19*81ad6265SDimitry Andric 20*81ad6265SDimitry Andric #if _LIBCPP_STD_VER > 17 21*81ad6265SDimitry Andric 22*81ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 23*81ad6265SDimitry Andric 24*81ad6265SDimitry Andric namespace chrono 25*81ad6265SDimitry Andric { 26*81ad6265SDimitry Andric 27*81ad6265SDimitry Andric class month { 28*81ad6265SDimitry Andric private: 29*81ad6265SDimitry Andric unsigned char __m; 30*81ad6265SDimitry Andric public: 31*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI month() = default; 32*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {} 33*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator++() noexcept { ++__m; return *this; } 34*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; } 35*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator--() noexcept { --__m; return *this; } 36*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; } 37*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr month& operator+=(const months& __m1) noexcept; 38*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr month& operator-=(const months& __m1) noexcept; 39*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __m; } 40*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; } 41*81ad6265SDimitry Andric }; 42*81ad6265SDimitry Andric 43*81ad6265SDimitry Andric 44*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 45*81ad6265SDimitry Andric bool operator==(const month& __lhs, const month& __rhs) noexcept 46*81ad6265SDimitry Andric { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); } 47*81ad6265SDimitry Andric 48*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 49*81ad6265SDimitry Andric bool operator!=(const month& __lhs, const month& __rhs) noexcept 50*81ad6265SDimitry Andric { return !(__lhs == __rhs); } 51*81ad6265SDimitry Andric 52*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 53*81ad6265SDimitry Andric bool operator< (const month& __lhs, const month& __rhs) noexcept 54*81ad6265SDimitry Andric { return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); } 55*81ad6265SDimitry Andric 56*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 57*81ad6265SDimitry Andric bool operator> (const month& __lhs, const month& __rhs) noexcept 58*81ad6265SDimitry Andric { return __rhs < __lhs; } 59*81ad6265SDimitry Andric 60*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 61*81ad6265SDimitry Andric bool operator<=(const month& __lhs, const month& __rhs) noexcept 62*81ad6265SDimitry Andric { return !(__rhs < __lhs); } 63*81ad6265SDimitry Andric 64*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 65*81ad6265SDimitry Andric bool operator>=(const month& __lhs, const month& __rhs) noexcept 66*81ad6265SDimitry Andric { return !(__lhs < __rhs); } 67*81ad6265SDimitry Andric 68*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 69*81ad6265SDimitry Andric month operator+ (const month& __lhs, const months& __rhs) noexcept 70*81ad6265SDimitry Andric { 71*81ad6265SDimitry Andric auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1); 72*81ad6265SDimitry Andric auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12; 73*81ad6265SDimitry Andric return month{static_cast<unsigned>(__mu - __yr * 12 + 1)}; 74*81ad6265SDimitry Andric } 75*81ad6265SDimitry Andric 76*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 77*81ad6265SDimitry Andric month operator+ (const months& __lhs, const month& __rhs) noexcept 78*81ad6265SDimitry Andric { return __rhs + __lhs; } 79*81ad6265SDimitry Andric 80*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 81*81ad6265SDimitry Andric month operator- (const month& __lhs, const months& __rhs) noexcept 82*81ad6265SDimitry Andric { return __lhs + -__rhs; } 83*81ad6265SDimitry Andric 84*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 85*81ad6265SDimitry Andric months operator-(const month& __lhs, const month& __rhs) noexcept 86*81ad6265SDimitry Andric { 87*81ad6265SDimitry Andric auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs); 88*81ad6265SDimitry Andric return months(__dm <= 11 ? __dm : __dm + 12); 89*81ad6265SDimitry Andric } 90*81ad6265SDimitry Andric 91*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 92*81ad6265SDimitry Andric month& month::operator+=(const months& __dm) noexcept 93*81ad6265SDimitry Andric { *this = *this + __dm; return *this; } 94*81ad6265SDimitry Andric 95*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 96*81ad6265SDimitry Andric month& month::operator-=(const months& __dm) noexcept 97*81ad6265SDimitry Andric { *this = *this - __dm; return *this; } 98*81ad6265SDimitry Andric 99*81ad6265SDimitry Andric inline constexpr month January{1}; 100*81ad6265SDimitry Andric inline constexpr month February{2}; 101*81ad6265SDimitry Andric inline constexpr month March{3}; 102*81ad6265SDimitry Andric inline constexpr month April{4}; 103*81ad6265SDimitry Andric inline constexpr month May{5}; 104*81ad6265SDimitry Andric inline constexpr month June{6}; 105*81ad6265SDimitry Andric inline constexpr month July{7}; 106*81ad6265SDimitry Andric inline constexpr month August{8}; 107*81ad6265SDimitry Andric inline constexpr month September{9}; 108*81ad6265SDimitry Andric inline constexpr month October{10}; 109*81ad6265SDimitry Andric inline constexpr month November{11}; 110*81ad6265SDimitry Andric inline constexpr month December{12}; 111*81ad6265SDimitry Andric 112*81ad6265SDimitry Andric } // namespace chrono 113*81ad6265SDimitry Andric 114*81ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD 115*81ad6265SDimitry Andric 116*81ad6265SDimitry Andric #endif // _LIBCPP_STD_VER > 17 117*81ad6265SDimitry Andric 118*81ad6265SDimitry Andric #endif // _LIBCPP___CHRONO_MONTH_H 119