4#ifndef TETL_CHRONO_MONTH_HPP
5#define TETL_CHRONO_MONTH_HPP
7#include <etl/_chrono/duration.hpp>
8#include <etl/_contracts/check.hpp>
9#include <etl/_limits/numeric_limits.hpp>
25 constexpr explicit month(
unsigned m)
noexcept
26 : _count{
static_cast<
unsigned char>(m)}
28 TETL_PRECONDITION(m < etl::numeric_limits<
unsigned char>::max());
33 return (_count > 0U)
and (_count <= 12U);
36 constexpr explicit operator unsigned()
const noexcept
46 constexpr auto operator+=(months
const& m)
noexcept ->
month&;
47 constexpr auto operator-=(months
const& m)
noexcept ->
month&;
55 return static_cast<
unsigned>(lhs) ==
static_cast<
unsigned>(rhs);
60 return static_cast<
unsigned>(lhs) <
static_cast<
unsigned>(rhs);
65 return static_cast<
unsigned>(lhs) <=
static_cast<
unsigned>(rhs);
70 return static_cast<
unsigned>(lhs) >
static_cast<
unsigned>(rhs);
75 return static_cast<
unsigned>(lhs) >=
static_cast<
unsigned>(rhs);
80 auto const mo =
static_cast<
long long>(
static_cast<
unsigned>(m)) + (ms
.count() - 1);
81 auto const div = (mo >= 0 ? mo : mo - 11) / 12;
82 return month{static_cast<
unsigned int>(mo - (div * 12) + 1)
};
97 auto const delta =
static_cast<
unsigned>(m1) -
static_cast<
unsigned>(m2);
98 return months{
static_cast<
etl::int_least32_t>(delta <= 11 ? delta : delta + 12)};
103 *
this = *
this + months{1};
116 *
this = *
this - months{1};
constexpr auto February
Definition month.hpp:140
constexpr auto July
Definition month.hpp:145
constexpr auto October
Definition month.hpp:148
constexpr auto January
Definition month.hpp:139
constexpr auto August
Definition month.hpp:146
constexpr auto June
Definition month.hpp:144
constexpr auto operator+(month const &m, months const &ms) noexcept -> month
Definition month.hpp:78
constexpr auto operator<=(month lhs, month rhs) noexcept -> bool
Definition month.hpp:63
constexpr auto March
Definition month.hpp:141
constexpr auto April
Definition month.hpp:142
constexpr auto operator+(months const &ms, month const &m) noexcept -> month
Definition month.hpp:85
constexpr auto May
Definition month.hpp:143
constexpr auto November
Definition month.hpp:149
constexpr auto September
Definition month.hpp:147
constexpr auto operator==(month lhs, month rhs) noexcept -> bool
Definition month.hpp:53
constexpr auto operator>(month lhs, month rhs) noexcept -> bool
Definition month.hpp:68
constexpr auto operator-(month const &m, months const &ms) noexcept -> month
Definition month.hpp:90
constexpr auto December
Definition month.hpp:150
constexpr auto operator<(month lhs, month rhs) noexcept -> bool
Definition month.hpp:58
constexpr auto operator>=(month lhs, month rhs) noexcept -> bool
Definition month.hpp:73
constexpr auto operator-(month const &m1, month const &m2) noexcept -> months
Definition month.hpp:95
Definition adjacent_find.hpp:9
constexpr auto count() const -> rep
Returns the number of ticks for this duration.
Definition duration.hpp:98
constexpr auto operator-() const -> etl::common_type_t< duration >
Implements unary plus and unary minus for the durations.
Definition duration.hpp:128
The class month represents a month in a year.
Definition month.hpp:22
constexpr auto operator-=(months const &m) noexcept -> month &
Definition month.hpp:133
constexpr auto operator++(int) noexcept -> month
Definition month.hpp:107
constexpr operator unsigned() const noexcept
Definition month.hpp:36
constexpr auto ok() const noexcept -> bool
Definition month.hpp:31
constexpr auto operator+=(months const &m) noexcept -> month &
Definition month.hpp:127
constexpr month(unsigned m) noexcept
Definition month.hpp:25
constexpr auto operator--() noexcept -> month &
Definition month.hpp:114
constexpr auto operator++() noexcept -> month &
Definition month.hpp:101
constexpr auto operator--(int) noexcept -> month
Definition month.hpp:120