Project Alice
Loading...
Searching...
No Matches
date_interface.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4namespace sys {
5
6struct state;
7
9 int32_t year;
10 uint16_t month;
11 uint16_t day;
12};
13
15 int64_t days = 0;
16 absolute_time_point(int64_t days) : days(days) { }
17
18public:
19 absolute_time_point() noexcept = default;
21 absolute_time_point(absolute_time_point const&) noexcept = default;
23 absolute_time_point& operator=(absolute_time_point const&) noexcept = default;
24 absolute_time_point& operator=(absolute_time_point&&) noexcept = default;
25 constexpr int64_t to_days() const noexcept {
26 return days;
27 }
28
29 constexpr bool operator==(absolute_time_point v) const noexcept {
30 return days == v.days;
31 }
32 constexpr bool operator!=(absolute_time_point v) const noexcept {
33 return days != v.days;
34 }
35 constexpr bool operator<(absolute_time_point v) const noexcept {
36 return days < v.days;
37 }
38 constexpr bool operator<=(absolute_time_point v) const noexcept {
39 return days <= v.days;
40 }
41 constexpr bool operator>(absolute_time_point v) const noexcept {
42 return days > v.days;
43 }
44 constexpr bool operator>=(absolute_time_point v) const noexcept {
45 return days >= v.days;
46 }
47 absolute_time_point operator+(int32_t v) const noexcept {
48 return absolute_time_point(days + v);
49 }
50 absolute_time_point& operator+=(int32_t v) noexcept {
51 days += v;
52 return *this;
53 }
54};
55
56class date {
57public:
58 using value_base_t = uint16_t;
59 using zero_is_null_t = std::true_type;
60
62
63 constexpr date() noexcept = default;
64 explicit constexpr date(value_base_t v) noexcept : value(v + 1) { }
65 constexpr date(date const& v) noexcept = default;
66 constexpr date(date&& v) noexcept = default;
67 date(year_month_day const& v, absolute_time_point base) noexcept;
68
69 date& operator=(date const& v) noexcept = default;
70 date& operator=(date&& v) noexcept = default;
71 constexpr bool operator==(date v) const noexcept {
72 return value == v.value;
73 }
74 constexpr bool operator!=(date v) const noexcept {
75 return value != v.value;
76 }
77 constexpr bool operator<(date v) const noexcept {
78 return value < v.value;
79 }
80 constexpr bool operator<=(date v) const noexcept {
81 return value <= v.value;
82 }
83 constexpr bool operator>(date v) const noexcept {
84 return value > v.value;
85 }
86 constexpr bool operator>=(date v) const noexcept {
87 return value >= v.value;
88 }
89 explicit constexpr operator bool() const noexcept {
90 return value != value_base_t(0);
91 }
92
93 date operator+(int32_t v) const noexcept {
94 return date{ value_base_t(value + v - 1)};
95 }
96 date operator-(int32_t v) const noexcept {
97 return date{ value_base_t((value - v) - 1)};
98 }
99 date& operator+=(int32_t v) noexcept {
100 value = value_base_t(value + v);
101 return *this;
102 }
103
104 constexpr int32_t to_raw_value() const noexcept {
105 return int32_t(value);
106 }
107 year_month_day to_ymd(absolute_time_point base) const noexcept;
108};
109
110bool is_playable_date(date d, absolute_time_point start, absolute_time_point end);
111int32_t days_difference(year_month_day start, year_month_day end);
112bool is_leap_year(int32_t year);
113
114} // namespace sys
absolute_time_point & operator+=(int32_t v) noexcept
constexpr bool operator<=(absolute_time_point v) const noexcept
constexpr int64_t to_days() const noexcept
absolute_time_point operator+(int32_t v) const noexcept
constexpr bool operator>=(absolute_time_point v) const noexcept
constexpr bool operator<(absolute_time_point v) const noexcept
constexpr bool operator>(absolute_time_point v) const noexcept
constexpr bool operator!=(absolute_time_point v) const noexcept
constexpr bool operator==(absolute_time_point v) const noexcept
absolute_time_point() noexcept=default
constexpr date(date &&v) noexcept=default
constexpr date(date const &v) noexcept=default
year_month_day to_ymd(absolute_time_point base) const noexcept
constexpr bool operator>(date v) const noexcept
date operator-(int32_t v) const noexcept
constexpr bool operator>=(date v) const noexcept
constexpr int32_t to_raw_value() const noexcept
date & operator=(date const &v) noexcept=default
uint16_t value_base_t
date & operator=(date &&v) noexcept=default
constexpr date() noexcept=default
constexpr bool operator<(date v) const noexcept
date operator+(int32_t v) const noexcept
constexpr bool operator<=(date v) const noexcept
date & operator+=(int32_t v) noexcept
constexpr bool operator!=(date v) const noexcept
constexpr bool operator==(date v) const noexcept
value_base_t value
std::true_type zero_is_null_t
Definition: constants.hpp:4
int32_t days_difference(year_month_day start, year_month_day end)
bool is_leap_year(int32_t year)
bool is_playable_date(date d, absolute_time_point start, absolute_time_point end)