File indexing completed on 2026-05-03 08:13:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03___CHRONO_YEAR_MONTH_H
0011 #define _LIBCPP___CXX03___CHRONO_YEAR_MONTH_H
0012
0013 #include <__cxx03/__chrono/duration.h>
0014 #include <__cxx03/__chrono/month.h>
0015 #include <__cxx03/__chrono/year.h>
0016 #include <__cxx03/__config>
0017 #include <__cxx03/compare>
0018
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 # pragma GCC system_header
0021 #endif
0022
0023 #if _LIBCPP_STD_VER >= 20
0024
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026
0027 namespace chrono {
0028
0029 class year_month {
0030 chrono::year __y_;
0031 chrono::month __m_;
0032
0033 public:
0034 year_month() = default;
0035 _LIBCPP_HIDE_FROM_ABI constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
0036 : __y_{__yval}, __m_{__mval} {}
0037 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; }
0038 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
0039 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const months& __dm) noexcept;
0040 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const months& __dm) noexcept;
0041 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const years& __dy) noexcept;
0042 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const years& __dy) noexcept;
0043 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __m_.ok(); }
0044 };
0045
0046 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator/(const year& __y, const month& __m) noexcept {
0047 return year_month{__y, __m};
0048 }
0049
0050 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator/(const year& __y, int __m) noexcept {
0051 return year_month{__y, month(__m)};
0052 }
0053
0054 _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept {
0055 return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month();
0056 }
0057
0058 _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
0059 operator<=>(const year_month& __lhs, const year_month& __rhs) noexcept {
0060 if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
0061 return __c;
0062 return __lhs.month() <=> __rhs.month();
0063 }
0064
0065 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept {
0066 int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
0067 const int __dy = (__dmi >= 0 ? __dmi : __dmi - 11) / 12;
0068 __dmi = __dmi - __dy * 12 + 1;
0069 return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
0070 }
0071
0072 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept {
0073 return __rhs + __lhs;
0074 }
0075
0076 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept {
0077 return (__lhs.year() + __rhs) / __lhs.month();
0078 }
0079
0080 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept {
0081 return __rhs + __lhs;
0082 }
0083
0084 _LIBCPP_HIDE_FROM_ABI inline constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept {
0085 return (__lhs.year() - __rhs.year()) +
0086 months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month()));
0087 }
0088
0089 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept {
0090 return __lhs + -__rhs;
0091 }
0092
0093 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept {
0094 return __lhs + -__rhs;
0095 }
0096
0097 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator+=(const months& __dm) noexcept {
0098 *this = *this + __dm;
0099 return *this;
0100 }
0101
0102 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator-=(const months& __dm) noexcept {
0103 *this = *this - __dm;
0104 return *this;
0105 }
0106
0107 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator+=(const years& __dy) noexcept {
0108 *this = *this + __dy;
0109 return *this;
0110 }
0111
0112 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator-=(const years& __dy) noexcept {
0113 *this = *this - __dy;
0114 return *this;
0115 }
0116
0117 }
0118
0119 _LIBCPP_END_NAMESPACE_STD
0120
0121 #endif
0122
0123 #endif