1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___CHRONO_DAY_H 11 #define _LIBCPP___CHRONO_DAY_H 12 13 #include <__chrono/duration.h> 14 #include <__config> 15 #include <compare> 16 17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 18 # pragma GCC system_header 19 #endif 20 21 #if _LIBCPP_STD_VER > 17 22 23 _LIBCPP_BEGIN_NAMESPACE_STD 24 25 namespace chrono 26 { 27 28 class day { 29 private: 30 unsigned char __d; 31 public: 32 _LIBCPP_HIDE_FROM_ABI day() = default; 33 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {} 34 _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator++() noexcept { ++__d; return *this; } 35 _LIBCPP_HIDE_FROM_ABI inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; } 36 _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator--() noexcept { --__d; return *this; } 37 _LIBCPP_HIDE_FROM_ABI inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; } 38 _LIBCPP_HIDE_FROM_ABI constexpr day& operator+=(const days& __dd) noexcept; 39 _LIBCPP_HIDE_FROM_ABI constexpr day& operator-=(const days& __dd) noexcept; 40 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __d; } 41 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; } 42 }; 43 44 45 _LIBCPP_HIDE_FROM_ABI inline constexpr 46 bool operator==(const day& __lhs, const day& __rhs) noexcept 47 { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); } 48 49 _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const day& __lhs, const day& __rhs) noexcept { 50 return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs); 51 } 52 53 _LIBCPP_HIDE_FROM_ABI inline constexpr 54 day operator+ (const day& __lhs, const days& __rhs) noexcept 55 { return day(static_cast<unsigned>(__lhs) + __rhs.count()); } 56 57 _LIBCPP_HIDE_FROM_ABI inline constexpr 58 day operator+ (const days& __lhs, const day& __rhs) noexcept 59 { return __rhs + __lhs; } 60 61 _LIBCPP_HIDE_FROM_ABI inline constexpr 62 day operator- (const day& __lhs, const days& __rhs) noexcept 63 { return __lhs + -__rhs; } 64 65 _LIBCPP_HIDE_FROM_ABI inline constexpr 66 days operator-(const day& __lhs, const day& __rhs) noexcept 67 { return days(static_cast<int>(static_cast<unsigned>(__lhs)) - 68 static_cast<int>(static_cast<unsigned>(__rhs))); } 69 70 _LIBCPP_HIDE_FROM_ABI inline constexpr 71 day& day::operator+=(const days& __dd) noexcept 72 { *this = *this + __dd; return *this; } 73 74 _LIBCPP_HIDE_FROM_ABI inline constexpr 75 day& day::operator-=(const days& __dd) noexcept 76 { *this = *this - __dd; return *this; } 77 78 } // namespace chrono 79 80 _LIBCPP_END_NAMESPACE_STD 81 82 #endif // _LIBCPP_STD_VER > 17 83 84 #endif // _LIBCPP___CHRONO_DAY_H 85