Debian Codegraph @

intl/icu_capi/bindings/cpp/ICU4XIsoDateTime.hpp

raw
1 #ifndef ICU4XIsoDateTime_HPP
2 #define ICU4XIsoDateTime_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 "ICU4XIsoDateTime.h"
13
14 class ICU4XIsoDateTime;
15 #include "ICU4XError.hpp"
16 class ICU4XIsoDate;
17 class ICU4XTime;
18 class ICU4XDateTime;
19 class ICU4XCalendar;
20 #include "ICU4XIsoWeekday.hpp"
21 class ICU4XWeekCalculator;
22 struct ICU4XWeekOf;
23
24 /**
25 * A destruction policy for using ICU4XIsoDateTime with std::unique_ptr.
26 */
27 struct ICU4XIsoDateTimeDeleter {
28 void operator()(capi::ICU4XIsoDateTime* l) const noexcept {
29 capi::ICU4XIsoDateTime_destroy(l);
30 }
31 };
32
33 /**
34 * An ICU4X DateTime object capable of containing a ISO-8601 date and time.
35 *
36 * See the [Rust documentation for `DateTime`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html) for more information.
37 */
38 class ICU4XIsoDateTime {
39 public:
40
41 /**
42 * Creates a new [`ICU4XIsoDateTime`] from the specified date and time.
43 *
44 * See the [Rust documentation for `try_new_iso_datetime`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.try_new_iso_datetime) for more information.
45 */
46 static diplomat::result<ICU4XIsoDateTime, ICU4XError> create(int32_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond);
47
48 /**
49 * Creates a new [`ICU4XIsoDateTime`] from an [`ICU4XIsoDate`] and [`ICU4XTime`] object
50 *
51 * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.new) for more information.
52 */
53 static ICU4XIsoDateTime crate_from_date_and_time(const ICU4XIsoDate& date, const ICU4XTime& time);
54
55 /**
56 * Creates a new [`ICU4XIsoDateTime`] of midnight on January 1, 1970
57 *
58 * See the [Rust documentation for `local_unix_epoch`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.local_unix_epoch) for more information.
59 */
60 static ICU4XIsoDateTime local_unix_epoch();
61
62 /**
63 * Construct from the minutes since the local unix epoch for this date (Jan 1 1970, 00:00)
64 *
65 * See the [Rust documentation for `from_minutes_since_local_unix_epoch`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.from_minutes_since_local_unix_epoch) for more information.
66 */
67 static ICU4XIsoDateTime create_from_minutes_since_local_unix_epoch(int32_t minutes);
68
69 /**
70 * Gets the date contained in this object
71 *
72 * See the [Rust documentation for `date`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#structfield.date) for more information.
73 */
74 ICU4XIsoDate date() const;
75
76 /**
77 * Gets the time contained in this object
78 *
79 * See the [Rust documentation for `time`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#structfield.time) for more information.
80 */
81 ICU4XTime time() const;
82
83 /**
84 * Converts this to an [`ICU4XDateTime`] capable of being mixed with dates of
85 * other calendars
86 *
87 * See the [Rust documentation for `to_any`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.to_any) for more information.
88 */
89 ICU4XDateTime to_any() const;
90
91 /**
92 * Gets the minutes since the local unix epoch for this date (Jan 1 1970, 00:00)
93 *
94 * See the [Rust documentation for `minutes_since_local_unix_epoch`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.minutes_since_local_unix_epoch) for more information.
95 */
96 int32_t minutes_since_local_unix_epoch() const;
97
98 /**
99 * Convert this datetime to one in a different calendar
100 *
101 * See the [Rust documentation for `to_calendar`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.to_calendar) for more information.
102 */
103 ICU4XDateTime to_calendar(const ICU4XCalendar& calendar) const;
104
105 /**
106 * Returns the hour in this time
107 *
108 * See the [Rust documentation for `hour`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.hour) for more information.
109 */
110 uint8_t hour() const;
111
112 /**
113 * Returns the minute in this time
114 *
115 * See the [Rust documentation for `minute`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.minute) for more information.
116 */
117 uint8_t minute() const;
118
119 /**
120 * Returns the second in this time
121 *
122 * See the [Rust documentation for `second`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.second) for more information.
123 */
124 uint8_t second() const;
125
126 /**
127 * Returns the nanosecond in this time
128 *
129 * See the [Rust documentation for `nanosecond`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.nanosecond) for more information.
130 */
131 uint32_t nanosecond() const;
132
133 /**
134 * Returns the 1-indexed day in the year for this date
135 *
136 * 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.
137 */
138 uint16_t day_of_year() const;
139
140 /**
141 * Returns the 1-indexed day in the month for this date
142 *
143 * 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.
144 */
145 uint32_t day_of_month() const;
146
147 /**
148 * Returns the day in the week for this day
149 *
150 * 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.
151 */
152 ICU4XIsoWeekday day_of_week() const;
153
154 /**
155 * Returns the week number in this month, 1-indexed, based on what
156 * is considered the first day of the week (often a locale preference).
157 *
158 * `first_weekday` can be obtained via `first_weekday()` on [`ICU4XWeekCalculator`]
159 *
160 * 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.
161 */
162 uint32_t week_of_month(ICU4XIsoWeekday first_weekday) const;
163
164 /**
165 * Returns the week number in this year, using week data
166 *
167 * 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.
168 */
169 diplomat::result<ICU4XWeekOf, ICU4XError> week_of_year(const ICU4XWeekCalculator& calculator) const;
170
171 /**
172 * Returns 1-indexed number of the month of this date in its year
173 *
174 * See the [Rust documentation for `month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month) for more information.
175 */
176 uint32_t month() const;
177
178 /**
179 * Returns the year number for this date
180 *
181 * See the [Rust documentation for `year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year) for more information.
182 */
183 int32_t year() const;
184
185 /**
186 * Returns whether this date is in a leap year
187 *
188 * 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.
189 */
190 bool is_in_leap_year() const;
191
192 /**
193 * Returns the number of months in the year represented by this date
194 *
195 * 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.
196 */
197 uint8_t months_in_year() const;
198
199 /**
200 * Returns the number of days in the month represented by this date
201 *
202 * 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.
203 */
204 uint8_t days_in_month() const;
205
206 /**
207 * Returns the number of days in the year represented by this date
208 *
209 * 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.
210 */
211 uint16_t days_in_year() const;
212 inline const capi::ICU4XIsoDateTime* AsFFI() const { return this->inner.get(); }
213 inline capi::ICU4XIsoDateTime* AsFFIMut() { return this->inner.get(); }
214 inline explicit ICU4XIsoDateTime(capi::ICU4XIsoDateTime* i) : inner(i) {}
215 ICU4XIsoDateTime() = default;
216 ICU4XIsoDateTime(ICU4XIsoDateTime&&) noexcept = default;
217 ICU4XIsoDateTime& operator=(ICU4XIsoDateTime&& other) noexcept = default;
218 private:
219 std::unique_ptr<capi::ICU4XIsoDateTime, ICU4XIsoDateTimeDeleter> inner;
220 };
221
222 #include "ICU4XIsoDate.hpp"
223 #include "ICU4XTime.hpp"
224 #include "ICU4XDateTime.hpp"
225 #include "ICU4XCalendar.hpp"
226 #include "ICU4XWeekCalculator.hpp"
227 #include "ICU4XWeekOf.hpp"
228
229 inline diplomat::result<ICU4XIsoDateTime, ICU4XError> ICU4XIsoDateTime::create(int32_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond) {
230 auto diplomat_result_raw_out_value = capi::ICU4XIsoDateTime_create(year, month, day, hour, minute, second, nanosecond);
231 diplomat::result<ICU4XIsoDateTime, ICU4XError> diplomat_result_out_value;
232 if (diplomat_result_raw_out_value.is_ok) {
233 diplomat_result_out_value = diplomat::Ok<ICU4XIsoDateTime>(ICU4XIsoDateTime(diplomat_result_raw_out_value.ok));
234 } else {
235 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
236 }
237 return diplomat_result_out_value;
238 }
239 inline ICU4XIsoDateTime ICU4XIsoDateTime::crate_from_date_and_time(const ICU4XIsoDate& date, const ICU4XTime& time) {
240 return ICU4XIsoDateTime(capi::ICU4XIsoDateTime_crate_from_date_and_time(date.AsFFI(), time.AsFFI()));
241 }
242 inline ICU4XIsoDateTime ICU4XIsoDateTime::local_unix_epoch() {
243 return ICU4XIsoDateTime(capi::ICU4XIsoDateTime_local_unix_epoch());
244 }
245 inline ICU4XIsoDateTime ICU4XIsoDateTime::create_from_minutes_since_local_unix_epoch(int32_t minutes) {
246 return ICU4XIsoDateTime(capi::ICU4XIsoDateTime_create_from_minutes_since_local_unix_epoch(minutes));
247 }
248 inline ICU4XIsoDate ICU4XIsoDateTime::date() const {
249 return ICU4XIsoDate(capi::ICU4XIsoDateTime_date(this->inner.get()));
250 }
251 inline ICU4XTime ICU4XIsoDateTime::time() const {
252 return ICU4XTime(capi::ICU4XIsoDateTime_time(this->inner.get()));
253 }
254 inline ICU4XDateTime ICU4XIsoDateTime::to_any() const {
255 return ICU4XDateTime(capi::ICU4XIsoDateTime_to_any(this->inner.get()));
256 }
257 inline int32_t ICU4XIsoDateTime::minutes_since_local_unix_epoch() const {
258 return capi::ICU4XIsoDateTime_minutes_since_local_unix_epoch(this->inner.get());
259 }
260 inline ICU4XDateTime ICU4XIsoDateTime::to_calendar(const ICU4XCalendar& calendar) const {
261 return ICU4XDateTime(capi::ICU4XIsoDateTime_to_calendar(this->inner.get(), calendar.AsFFI()));
262 }
263 inline uint8_t ICU4XIsoDateTime::hour() const {
264 return capi::ICU4XIsoDateTime_hour(this->inner.get());
265 }
266 inline uint8_t ICU4XIsoDateTime::minute() const {
267 return capi::ICU4XIsoDateTime_minute(this->inner.get());
268 }
269 inline uint8_t ICU4XIsoDateTime::second() const {
270 return capi::ICU4XIsoDateTime_second(this->inner.get());
271 }
272 inline uint32_t ICU4XIsoDateTime::nanosecond() const {
273 return capi::ICU4XIsoDateTime_nanosecond(this->inner.get());
274 }
275 inline uint16_t ICU4XIsoDateTime::day_of_year() const {
276 return capi::ICU4XIsoDateTime_day_of_year(this->inner.get());
277 }
278 inline uint32_t ICU4XIsoDateTime::day_of_month() const {
279 return capi::ICU4XIsoDateTime_day_of_month(this->inner.get());
280 }
281 inline ICU4XIsoWeekday ICU4XIsoDateTime::day_of_week() const {
282 return static_cast<ICU4XIsoWeekday>(capi::ICU4XIsoDateTime_day_of_week(this->inner.get()));
283 }
284 inline uint32_t ICU4XIsoDateTime::week_of_month(ICU4XIsoWeekday first_weekday) const {
285 return capi::ICU4XIsoDateTime_week_of_month(this->inner.get(), static_cast<capi::ICU4XIsoWeekday>(first_weekday));
286 }
287 inline diplomat::result<ICU4XWeekOf, ICU4XError> ICU4XIsoDateTime::week_of_year(const ICU4XWeekCalculator& calculator) const {
288 auto diplomat_result_raw_out_value = capi::ICU4XIsoDateTime_week_of_year(this->inner.get(), calculator.AsFFI());
289 diplomat::result<ICU4XWeekOf, ICU4XError> diplomat_result_out_value;
290 if (diplomat_result_raw_out_value.is_ok) {
291 capi::ICU4XWeekOf diplomat_raw_struct_out_value = diplomat_result_raw_out_value.ok;
292 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)) });
293 } else {
294 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
295 }
296 return diplomat_result_out_value;
297 }
298 inline uint32_t ICU4XIsoDateTime::month() const {
299 return capi::ICU4XIsoDateTime_month(this->inner.get());
300 }
301 inline int32_t ICU4XIsoDateTime::year() const {
302 return capi::ICU4XIsoDateTime_year(this->inner.get());
303 }
304 inline bool ICU4XIsoDateTime::is_in_leap_year() const {
305 return capi::ICU4XIsoDateTime_is_in_leap_year(this->inner.get());
306 }
307 inline uint8_t ICU4XIsoDateTime::months_in_year() const {
308 return capi::ICU4XIsoDateTime_months_in_year(this->inner.get());
309 }
310 inline uint8_t ICU4XIsoDateTime::days_in_month() const {
311 return capi::ICU4XIsoDateTime_days_in_month(this->inner.get());
312 }
313 inline uint16_t ICU4XIsoDateTime::days_in_year() const {
314 return capi::ICU4XIsoDateTime_days_in_year(this->inner.get());
315 }
316 #endif