Debian Codegraph @

intl/icu_capi/bindings/cpp/ICU4XIsoDate.hpp

raw
1 #ifndef ICU4XIsoDate_HPP
2 #define ICU4XIsoDate_HPP
3 #include <stdint.h>
4 #include <stddef.h>
5 #include <stdbool.h>
6 #include <algorithm>
7 #include <memory>
8 #include <variant>
9 #include <optional>
10 #include "diplomat_runtime.hpp"
11
12 #include "ICU4XIsoDate.h"
13
14 class ICU4XIsoDate;
15 #include "ICU4XError.hpp"
16 class ICU4XCalendar;
17 class ICU4XDate;
18 #include "ICU4XIsoWeekday.hpp"
19 class ICU4XWeekCalculator;
20 struct ICU4XWeekOf;
21
22 /**
23 * A destruction policy for using ICU4XIsoDate with std::unique_ptr.
24 */
25 struct ICU4XIsoDateDeleter {
26 void operator()(capi::ICU4XIsoDate* l) const noexcept {
27 capi::ICU4XIsoDate_destroy(l);
28 }
29 };
30
31 /**
32 * An ICU4X Date object capable of containing a ISO-8601 date
33 *
34 * See the [Rust documentation for `Date`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html) for more information.
35 */
36 class ICU4XIsoDate {
37 public:
38
39 /**
40 * Creates a new [`ICU4XIsoDate`] from the specified date and time.
41 *
42 * See the [Rust documentation for `try_new_iso_date`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.try_new_iso_date) for more information.
43 */
44 static diplomat::result<ICU4XIsoDate, ICU4XError> create(int32_t year, uint8_t month, uint8_t day);
45
46 /**
47 * Creates a new [`ICU4XIsoDate`] representing January 1, 1970.
48 *
49 * See the [Rust documentation for `unix_epoch`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.unix_epoch) for more information.
50 */
51 static ICU4XIsoDate create_for_unix_epoch();
52
53 /**
54 * Convert this date to one in a different calendar
55 *
56 * See the [Rust documentation for `to_calendar`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_calendar) for more information.
57 */
58 ICU4XDate to_calendar(const ICU4XCalendar& calendar) const;
59
60 /**
61 * See the [Rust documentation for `to_any`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_any) for more information.
62 */
63 ICU4XDate to_any() const;
64
65 /**
66 * Returns the 1-indexed day in the year for this date
67 *
68 * See the [Rust documentation for `day_of_year_info`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_year_info) for more information.
69 */
70 uint16_t day_of_year() const;
71
72 /**
73 * Returns the 1-indexed day in the month for this date
74 *
75 * See the [Rust documentation for `day_of_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_month) for more information.
76 */
77 uint32_t day_of_month() const;
78
79 /**
80 * Returns the day in the week for this day
81 *
82 * See the [Rust documentation for `day_of_week`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_week) for more information.
83 */
84 ICU4XIsoWeekday day_of_week() const;
85
86 /**
87 * Returns the week number in this month, 1-indexed, based on what
88 * is considered the first day of the week (often a locale preference).
89 *
90 * `first_weekday` can be obtained via `first_weekday()` on [`ICU4XWeekCalculator`]
91 *
92 * See the [Rust documentation for `week_of_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_month) for more information.
93 */
94 uint32_t week_of_month(ICU4XIsoWeekday first_weekday) const;
95
96 /**
97 * Returns the week number in this year, using week data
98 *
99 * See the [Rust documentation for `week_of_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_year) for more information.
100 */
101 diplomat::result<ICU4XWeekOf, ICU4XError> week_of_year(const ICU4XWeekCalculator& calculator) const;
102
103 /**
104 * Returns 1-indexed number of the month of this date in its year
105 *
106 * See the [Rust documentation for `month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month) for more information.
107 */
108 uint32_t month() const;
109
110 /**
111 * Returns the year number for this date
112 *
113 * See the [Rust documentation for `year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year) for more information.
114 */
115 int32_t year() const;
116
117 /**
118 * Returns if the year is a leap year for this date
119 *
120 * See the [Rust documentation for `is_in_leap_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.is_in_leap_year) for more information.
121 */
122 bool is_in_leap_year() const;
123
124 /**
125 * Returns the number of months in the year represented by this date
126 *
127 * See the [Rust documentation for `months_in_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.months_in_year) for more information.
128 */
129 uint8_t months_in_year() const;
130
131 /**
132 * Returns the number of days in the month represented by this date
133 *
134 * See the [Rust documentation for `days_in_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_month) for more information.
135 */
136 uint8_t days_in_month() const;
137
138 /**
139 * Returns the number of days in the year represented by this date
140 *
141 * See the [Rust documentation for `days_in_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_year) for more information.
142 */
143 uint16_t days_in_year() const;
144 inline const capi::ICU4XIsoDate* AsFFI() const { return this->inner.get(); }
145 inline capi::ICU4XIsoDate* AsFFIMut() { return this->inner.get(); }
146 inline explicit ICU4XIsoDate(capi::ICU4XIsoDate* i) : inner(i) {}
147 ICU4XIsoDate() = default;
148 ICU4XIsoDate(ICU4XIsoDate&&) noexcept = default;
149 ICU4XIsoDate& operator=(ICU4XIsoDate&& other) noexcept = default;
150 private:
151 std::unique_ptr<capi::ICU4XIsoDate, ICU4XIsoDateDeleter> inner;
152 };
153
154 #include "ICU4XCalendar.hpp"
155 #include "ICU4XDate.hpp"
156 #include "ICU4XWeekCalculator.hpp"
157 #include "ICU4XWeekOf.hpp"
158
159 inline diplomat::result<ICU4XIsoDate, ICU4XError> ICU4XIsoDate::create(int32_t year, uint8_t month, uint8_t day) {
160 auto diplomat_result_raw_out_value = capi::ICU4XIsoDate_create(year, month, day);
161 diplomat::result<ICU4XIsoDate, ICU4XError> diplomat_result_out_value;
162 if (diplomat_result_raw_out_value.is_ok) {
163 diplomat_result_out_value = diplomat::Ok<ICU4XIsoDate>(ICU4XIsoDate(diplomat_result_raw_out_value.ok));
164 } else {
165 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
166 }
167 return diplomat_result_out_value;
168 }
169 inline ICU4XIsoDate ICU4XIsoDate::create_for_unix_epoch() {
170 return ICU4XIsoDate(capi::ICU4XIsoDate_create_for_unix_epoch());
171 }
172 inline ICU4XDate ICU4XIsoDate::to_calendar(const ICU4XCalendar& calendar) const {
173 return ICU4XDate(capi::ICU4XIsoDate_to_calendar(this->inner.get(), calendar.AsFFI()));
174 }
175 inline ICU4XDate ICU4XIsoDate::to_any() const {
176 return ICU4XDate(capi::ICU4XIsoDate_to_any(this->inner.get()));
177 }
178 inline uint16_t ICU4XIsoDate::day_of_year() const {
179 return capi::ICU4XIsoDate_day_of_year(this->inner.get());
180 }
181 inline uint32_t ICU4XIsoDate::day_of_month() const {
182 return capi::ICU4XIsoDate_day_of_month(this->inner.get());
183 }
184 inline ICU4XIsoWeekday ICU4XIsoDate::day_of_week() const {
185 return static_cast<ICU4XIsoWeekday>(capi::ICU4XIsoDate_day_of_week(this->inner.get()));
186 }
187 inline uint32_t ICU4XIsoDate::week_of_month(ICU4XIsoWeekday first_weekday) const {
188 return capi::ICU4XIsoDate_week_of_month(this->inner.get(), static_cast<capi::ICU4XIsoWeekday>(first_weekday));
189 }
190 inline diplomat::result<ICU4XWeekOf, ICU4XError> ICU4XIsoDate::week_of_year(const ICU4XWeekCalculator& calculator) const {
191 auto diplomat_result_raw_out_value = capi::ICU4XIsoDate_week_of_year(this->inner.get(), calculator.AsFFI());
192 diplomat::result<ICU4XWeekOf, ICU4XError> diplomat_result_out_value;
193 if (diplomat_result_raw_out_value.is_ok) {
194 capi::ICU4XWeekOf diplomat_raw_struct_out_value = diplomat_result_raw_out_value.ok;
195 diplomat_result_out_value = diplomat::Ok<ICU4XWeekOf>(ICU4XWeekOf{ .week = std::move(diplomat_raw_struct_out_value.week), .unit = std::move(static_cast<ICU4XWeekRelativeUnit>(diplomat_raw_struct_out_value.unit)) });
196 } else {
197 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
198 }
199 return diplomat_result_out_value;
200 }
201 inline uint32_t ICU4XIsoDate::month() const {
202 return capi::ICU4XIsoDate_month(this->inner.get());
203 }
204 inline int32_t ICU4XIsoDate::year() const {
205 return capi::ICU4XIsoDate_year(this->inner.get());
206 }
207 inline bool ICU4XIsoDate::is_in_leap_year() const {
208 return capi::ICU4XIsoDate_is_in_leap_year(this->inner.get());
209 }
210 inline uint8_t ICU4XIsoDate::months_in_year() const {
211 return capi::ICU4XIsoDate_months_in_year(this->inner.get());
212 }
213 inline uint8_t ICU4XIsoDate::days_in_month() const {
214 return capi::ICU4XIsoDate_days_in_month(this->inner.get());
215 }
216 inline uint16_t ICU4XIsoDate::days_in_year() const {
217 return capi::ICU4XIsoDate_days_in_year(this->inner.get());
218 }
219 #endif