3#ifndef TETL_CHRONO_YEAR_MONTH_DAY_HPP
4#define TETL_CHRONO_YEAR_MONTH_DAY_HPP
26 int32_t const era = (z >= 0 ? z : z - 146096) / 146097;
27 auto const doe =
static_cast<uint32_t>(z - era * 146097);
28 uint32_t const yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
30 uint32_t const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
31 uint32_t const mp = (5 * doy + 2) / 153;
32 uint32_t const d = doy - (153 * mp + 2) / 5 + 1;
33 uint32_t const m = mp < 10 ? mp + 3 : mp - 9;
36 chrono::year{
static_cast<int>(y) +
static_cast<int>(m <= 2)},
48 y -=
static_cast<int32_t>(m <= 2);
49 int32_t const era = (y >= 0 ? y : y - 399) / 400;
50 auto const yoe =
static_cast<uint32_t>(y - era * 400);
51 uint32_t const doy = (153 * (m > 2 ? m - 3 : m + 9) + 2) / 5 + d - 1;
52 uint32_t const doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
53 return days{era * 146097 +
static_cast<int32_t>(doe) - 719468};
88 [[nodiscard]]
constexpr auto year() const noexcept ->
chrono::
year {
return _y; }
92 [[nodiscard]]
constexpr auto day() const noexcept ->
chrono::
day {
return _d; }
94 [[nodiscard]]
constexpr operator sys_days() const noexcept
99 [[nodiscard]]
constexpr explicit operator local_days() const noexcept
104 [[nodiscard]]
constexpr auto ok() const noexcept ->
bool
120 return lhs.year() == rhs.year() and lhs.month() == rhs.month() and lhs.day() == rhs.day();
126 auto const ym =
year_month{lhs.year(), lhs.month()} + rhs;
127 return {ym.year(), ym.month(), lhs.day()};
139 return {lhs.year() + rhs, lhs.month(), lhs.day()};
186 return {ym.year(), ym.month(), d};
191 return {ym.year(), ym.month(),
day(
static_cast<unsigned>(d))};
196 return {y, md.month(), md.day()};
201 return {
year{y}, md.month(), md.day()};
206 return {y, md.month(), md.day()};
211 return {
year{y}, md.month(), md.day()};
local_time< etl::chrono::days > local_days
Definition local_t.hpp:27
constexpr auto operator+(day const &d, days const &ds) noexcept -> day
Definition day.hpp:92
duration< int_least32_t, ratio< 31556952 > > months
Signed integer type of at least 20 bits.
Definition duration.hpp:371
constexpr auto operator==(duration< Rep1, Period1 > const &lhs, duration< Rep2, Period2 > const &rhs) -> bool
Compares two durations. Checks if lhs and rhs are equal, i.e. the number of ticks for the type common...
Definition duration.hpp:299
duration< int_least32_t, ratio< 86400 > > days
Signed integer type of at least 25 bits.
Definition duration.hpp:365
sys_time< chrono::days > sys_days
Definition system_clock.hpp:39
constexpr auto operator/(duration< Rep1, Period1 > const &lhs, duration< Rep2, Period2 > const &rhs) -> common_type_t< Rep1, Rep2 >
Performs basic arithmetic operations between two durations or between a duration and a tick count.
Definition duration.hpp:272
duration< int_least32_t, ratio< 2629746 > > years
Signed integer type of at least 17 bits.
Definition duration.hpp:374
constexpr auto operator-(day const &d, days const &ds) noexcept -> day
Definition day.hpp:102
TETL_BUILTIN_INT32 int32_t
Signed integer type with width of exactly 32 bits.
Definition int_t.hpp:17
TETL_BUILTIN_UINT32 uint32_t
Unsigned integer type with width of exactly 32 bits.
Definition uint_t.hpp:17
The class day represents a day in a month.
Definition day.hpp:20
Definition month_day.hpp:13
The class month represents a month in a year.
Definition month.hpp:21
Definition year_month_day_last.hpp:41
Definition year_month_day.hpp:17
constexpr year_month_day(chrono::year const &y, chrono::month const &m, chrono::day const &d) noexcept
Definition year_month_day.hpp:59
constexpr auto ok() const noexcept -> bool
Definition year_month_day.hpp:104
constexpr year_month_day(sys_days const &dp) noexcept
Definition year_month_day.hpp:73
constexpr auto month() const noexcept -> chrono::month
Definition year_month_day.hpp:90
constexpr year_month_day(local_days const &dp) noexcept
Definition year_month_day.hpp:78
constexpr year_month_day(year_month_day_last const &ymdl) noexcept
Definition year_month_day.hpp:66
constexpr auto year() const noexcept -> chrono::year
Definition year_month_day.hpp:88
constexpr auto operator+=(months const &m) noexcept -> year_month_day &
Definition year_month_day.hpp:160
constexpr auto operator-=(months const &m) noexcept -> year_month_day &
Definition year_month_day.hpp:166
constexpr auto day() const noexcept -> chrono::day
Definition year_month_day.hpp:92
Definition year_month.hpp:11
static constexpr int digits
Definition numeric_limits.hpp:24