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_DAY_H 11*81ad6265SDimitry Andric #define _LIBCPP___CHRONO_DAY_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 day { 28*81ad6265SDimitry Andric private: 29*81ad6265SDimitry Andric unsigned char __d; 30*81ad6265SDimitry Andric public: 31*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI day() = default; 32*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {} 33*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator++() noexcept { ++__d; return *this; } 34*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; } 35*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator--() noexcept { --__d; return *this; } 36*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; } 37*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr day& operator+=(const days& __dd) noexcept; 38*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr day& operator-=(const days& __dd) noexcept; 39*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __d; } 40*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; } 41*81ad6265SDimitry Andric }; 42*81ad6265SDimitry Andric 43*81ad6265SDimitry Andric 44*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 45*81ad6265SDimitry Andric bool operator==(const day& __lhs, const day& __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 day& __lhs, const day& __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 day& __lhs, const day& __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 day& __lhs, const day& __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 day& __lhs, const day& __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 day& __lhs, const day& __rhs) noexcept 66*81ad6265SDimitry Andric { return !(__lhs < __rhs); } 67*81ad6265SDimitry Andric 68*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 69*81ad6265SDimitry Andric day operator+ (const day& __lhs, const days& __rhs) noexcept 70*81ad6265SDimitry Andric { return day(static_cast<unsigned>(__lhs) + __rhs.count()); } 71*81ad6265SDimitry Andric 72*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 73*81ad6265SDimitry Andric day operator+ (const days& __lhs, const day& __rhs) noexcept 74*81ad6265SDimitry Andric { return __rhs + __lhs; } 75*81ad6265SDimitry Andric 76*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 77*81ad6265SDimitry Andric day operator- (const day& __lhs, const days& __rhs) noexcept 78*81ad6265SDimitry Andric { return __lhs + -__rhs; } 79*81ad6265SDimitry Andric 80*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 81*81ad6265SDimitry Andric days operator-(const day& __lhs, const day& __rhs) noexcept 82*81ad6265SDimitry Andric { return days(static_cast<int>(static_cast<unsigned>(__lhs)) - 83*81ad6265SDimitry Andric static_cast<int>(static_cast<unsigned>(__rhs))); } 84*81ad6265SDimitry Andric 85*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 86*81ad6265SDimitry Andric day& day::operator+=(const days& __dd) noexcept 87*81ad6265SDimitry Andric { *this = *this + __dd; return *this; } 88*81ad6265SDimitry Andric 89*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 90*81ad6265SDimitry Andric day& day::operator-=(const days& __dd) noexcept 91*81ad6265SDimitry Andric { *this = *this - __dd; return *this; } 92*81ad6265SDimitry Andric 93*81ad6265SDimitry Andric } // namespace chrono 94*81ad6265SDimitry Andric 95*81ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD 96*81ad6265SDimitry Andric 97*81ad6265SDimitry Andric #endif // _LIBCPP_STD_VER > 17 98*81ad6265SDimitry Andric 99*81ad6265SDimitry Andric #endif // _LIBCPP___CHRONO_DAY_H 100