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_DAY_H 1181ad6265SDimitry Andric #define _LIBCPP___CHRONO_DAY_H 1281ad6265SDimitry Andric 1381ad6265SDimitry Andric #include <__chrono/duration.h> 1481ad6265SDimitry Andric #include <__config> 15753f127fSDimitry Andric #include <compare> 1681ad6265SDimitry Andric 1781ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1881ad6265SDimitry Andric # pragma GCC system_header 1981ad6265SDimitry Andric #endif 2081ad6265SDimitry Andric 2106c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20 2281ad6265SDimitry Andric 2381ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 2481ad6265SDimitry Andric 25*cb14a3feSDimitry Andric namespace chrono { 2681ad6265SDimitry Andric 2781ad6265SDimitry Andric class day { 2881ad6265SDimitry Andric private: 29bdd1243dSDimitry Andric unsigned char __d_; 30*cb14a3feSDimitry Andric 3181ad6265SDimitry Andric public: 3206c3fb27SDimitry Andric day() = default; 33*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit inline constexpr day(unsigned __val) noexcept 34*cb14a3feSDimitry Andric : __d_(static_cast<unsigned char>(__val)) {} 35*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator++() noexcept { 36*cb14a3feSDimitry Andric ++__d_; 37*cb14a3feSDimitry Andric return *this; 38*cb14a3feSDimitry Andric } 39*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day operator++(int) noexcept { 40*cb14a3feSDimitry Andric day __tmp = *this; 41*cb14a3feSDimitry Andric ++(*this); 42*cb14a3feSDimitry Andric return __tmp; 43*cb14a3feSDimitry Andric } 44*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator--() noexcept { 45*cb14a3feSDimitry Andric --__d_; 46*cb14a3feSDimitry Andric return *this; 47*cb14a3feSDimitry Andric } 48*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day operator--(int) noexcept { 49*cb14a3feSDimitry Andric day __tmp = *this; 50*cb14a3feSDimitry Andric --(*this); 51*cb14a3feSDimitry Andric return __tmp; 52*cb14a3feSDimitry Andric } 5381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr day& operator+=(const days& __dd) noexcept; 5481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr day& operator-=(const days& __dd) noexcept; 55bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __d_; } 56bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __d_ >= 1 && __d_ <= 31; } 5781ad6265SDimitry Andric }; 5881ad6265SDimitry Andric 59*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const day& __lhs, const day& __rhs) noexcept { 60*cb14a3feSDimitry Andric return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); 61*cb14a3feSDimitry Andric } 6281ad6265SDimitry Andric 635f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const day& __lhs, const day& __rhs) noexcept { 64753f127fSDimitry Andric return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs); 65753f127fSDimitry Andric } 6681ad6265SDimitry Andric 67*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day operator+(const day& __lhs, const days& __rhs) noexcept { 68*cb14a3feSDimitry Andric return day(static_cast<unsigned>(__lhs) + __rhs.count()); 69*cb14a3feSDimitry Andric } 7081ad6265SDimitry Andric 71*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day operator+(const days& __lhs, const day& __rhs) noexcept { 72*cb14a3feSDimitry Andric return __rhs + __lhs; 73*cb14a3feSDimitry Andric } 7481ad6265SDimitry Andric 75*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day operator-(const day& __lhs, const days& __rhs) noexcept { 76*cb14a3feSDimitry Andric return __lhs + -__rhs; 77*cb14a3feSDimitry Andric } 7881ad6265SDimitry Andric 79*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr days operator-(const day& __lhs, const day& __rhs) noexcept { 80*cb14a3feSDimitry Andric return days(static_cast<int>(static_cast<unsigned>(__lhs)) - static_cast<int>(static_cast<unsigned>(__rhs))); 81*cb14a3feSDimitry Andric } 8281ad6265SDimitry Andric 83*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day& day::operator+=(const days& __dd) noexcept { 84*cb14a3feSDimitry Andric *this = *this + __dd; 85*cb14a3feSDimitry Andric return *this; 86*cb14a3feSDimitry Andric } 8781ad6265SDimitry Andric 88*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day& day::operator-=(const days& __dd) noexcept { 89*cb14a3feSDimitry Andric *this = *this - __dd; 90*cb14a3feSDimitry Andric return *this; 91*cb14a3feSDimitry Andric } 9281ad6265SDimitry Andric 9381ad6265SDimitry Andric } // namespace chrono 9481ad6265SDimitry Andric 9581ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD 9681ad6265SDimitry Andric 9706c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20 9881ad6265SDimitry Andric 9981ad6265SDimitry Andric #endif // _LIBCPP___CHRONO_DAY_H 100