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> 15*753f127fSDimitry 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 2181ad6265SDimitry Andric #if _LIBCPP_STD_VER > 17 2281ad6265SDimitry Andric 2381ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 2481ad6265SDimitry Andric 2581ad6265SDimitry Andric namespace chrono 2681ad6265SDimitry Andric { 2781ad6265SDimitry Andric 2881ad6265SDimitry Andric class day { 2981ad6265SDimitry Andric private: 3081ad6265SDimitry Andric unsigned char __d; 3181ad6265SDimitry Andric public: 3281ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI day() = default; 3381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {} 3481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator++() noexcept { ++__d; return *this; } 3581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; } 3681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator--() noexcept { --__d; return *this; } 3781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; } 3881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr day& operator+=(const days& __dd) noexcept; 3981ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr day& operator-=(const days& __dd) noexcept; 4081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __d; } 4181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; } 4281ad6265SDimitry Andric }; 4381ad6265SDimitry Andric 4481ad6265SDimitry Andric 4581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 4681ad6265SDimitry Andric bool operator==(const day& __lhs, const day& __rhs) noexcept 4781ad6265SDimitry Andric { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); } 4881ad6265SDimitry Andric 49*753f127fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const day& __lhs, const day& __rhs) noexcept { 50*753f127fSDimitry Andric return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs); 51*753f127fSDimitry Andric } 5281ad6265SDimitry Andric 5381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 5481ad6265SDimitry Andric day operator+ (const day& __lhs, const days& __rhs) noexcept 5581ad6265SDimitry Andric { return day(static_cast<unsigned>(__lhs) + __rhs.count()); } 5681ad6265SDimitry Andric 5781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 5881ad6265SDimitry Andric day operator+ (const days& __lhs, const day& __rhs) noexcept 5981ad6265SDimitry Andric { return __rhs + __lhs; } 6081ad6265SDimitry Andric 6181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 6281ad6265SDimitry Andric day operator- (const day& __lhs, const days& __rhs) noexcept 6381ad6265SDimitry Andric { return __lhs + -__rhs; } 6481ad6265SDimitry Andric 6581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 6681ad6265SDimitry Andric days operator-(const day& __lhs, const day& __rhs) noexcept 6781ad6265SDimitry Andric { return days(static_cast<int>(static_cast<unsigned>(__lhs)) - 6881ad6265SDimitry Andric static_cast<int>(static_cast<unsigned>(__rhs))); } 6981ad6265SDimitry Andric 7081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 7181ad6265SDimitry Andric day& day::operator+=(const days& __dd) noexcept 7281ad6265SDimitry Andric { *this = *this + __dd; return *this; } 7381ad6265SDimitry Andric 7481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr 7581ad6265SDimitry Andric day& day::operator-=(const days& __dd) noexcept 7681ad6265SDimitry Andric { *this = *this - __dd; return *this; } 7781ad6265SDimitry Andric 7881ad6265SDimitry Andric } // namespace chrono 7981ad6265SDimitry Andric 8081ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD 8181ad6265SDimitry Andric 8281ad6265SDimitry Andric #endif // _LIBCPP_STD_VER > 17 8381ad6265SDimitry Andric 8481ad6265SDimitry Andric #endif // _LIBCPP___CHRONO_DAY_H 85