master
  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_MONTH_H
 11#define _LIBCPP___CHRONO_MONTH_H
 12
 13#include <__chrono/duration.h>
 14#include <__compare/ordering.h>
 15#include <__config>
 16
 17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 18#  pragma GCC system_header
 19#endif
 20
 21#if _LIBCPP_STD_VER >= 20
 22
 23_LIBCPP_BEGIN_NAMESPACE_STD
 24
 25namespace chrono {
 26
 27class month {
 28private:
 29  unsigned char __m_;
 30
 31public:
 32  month() = default;
 33  _LIBCPP_HIDE_FROM_ABI explicit inline constexpr month(unsigned __val) noexcept
 34      : __m_(static_cast<unsigned char>(__val)) {}
 35  _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator++() noexcept {
 36    *this += months{1};
 37    return *this;
 38  }
 39  _LIBCPP_HIDE_FROM_ABI inline constexpr month operator++(int) noexcept {
 40    month __tmp = *this;
 41    ++(*this);
 42    return __tmp;
 43  }
 44  _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator--() noexcept {
 45    *this -= months{1};
 46    return *this;
 47  }
 48  _LIBCPP_HIDE_FROM_ABI inline constexpr month operator--(int) noexcept {
 49    month __tmp = *this;
 50    --(*this);
 51    return __tmp;
 52  }
 53  _LIBCPP_HIDE_FROM_ABI constexpr month& operator+=(const months& __m1) noexcept;
 54  _LIBCPP_HIDE_FROM_ABI constexpr month& operator-=(const months& __m1) noexcept;
 55  _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __m_; }
 56  _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_ >= 1 && __m_ <= 12; }
 57};
 58
 59_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month& __lhs, const month& __rhs) noexcept {
 60  return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs);
 61}
 62
 63_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const month& __lhs, const month& __rhs) noexcept {
 64  return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
 65}
 66
 67_LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const month& __lhs, const months& __rhs) noexcept {
 68  auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
 69  auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
 70  return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
 71}
 72
 73_LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const months& __lhs, const month& __rhs) noexcept {
 74  return __rhs + __lhs;
 75}
 76
 77_LIBCPP_HIDE_FROM_ABI inline constexpr month operator-(const month& __lhs, const months& __rhs) noexcept {
 78  return __lhs + -__rhs;
 79}
 80
 81_LIBCPP_HIDE_FROM_ABI inline constexpr months operator-(const month& __lhs, const month& __rhs) noexcept {
 82  auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
 83  return months(__dm <= 11 ? __dm : __dm + 12);
 84}
 85
 86_LIBCPP_HIDE_FROM_ABI inline constexpr month& month::operator+=(const months& __dm) noexcept {
 87  *this = *this + __dm;
 88  return *this;
 89}
 90
 91_LIBCPP_HIDE_FROM_ABI inline constexpr month& month::operator-=(const months& __dm) noexcept {
 92  *this = *this - __dm;
 93  return *this;
 94}
 95
 96inline constexpr month January{1};
 97inline constexpr month February{2};
 98inline constexpr month March{3};
 99inline constexpr month April{4};
100inline constexpr month May{5};
101inline constexpr month June{6};
102inline constexpr month July{7};
103inline constexpr month August{8};
104inline constexpr month September{9};
105inline constexpr month October{10};
106inline constexpr month November{11};
107inline constexpr month December{12};
108
109} // namespace chrono
110
111_LIBCPP_END_NAMESPACE_STD
112
113#endif // _LIBCPP_STD_VER >= 20
114
115#endif // _LIBCPP___CHRONO_MONTH_H