Date.d.hpp (8778B)
1 #ifndef icu4x_Date_D_HPP 2 #define icu4x_Date_D_HPP 3 4 #include <stdio.h> 5 #include <stdint.h> 6 #include <stddef.h> 7 #include <stdbool.h> 8 #include <memory> 9 #include <functional> 10 #include <optional> 11 #include <cstdlib> 12 #include "../diplomat_runtime.hpp" 13 14 namespace icu4x { 15 namespace capi { struct Calendar; } 16 class Calendar; 17 namespace capi { struct Date; } 18 class Date; 19 namespace capi { struct IsoDate; } 20 class IsoDate; 21 class CalendarError; 22 class Rfc9557ParseError; 23 class Weekday; 24 } 25 26 27 namespace icu4x { 28 namespace capi { 29 struct Date; 30 } // namespace capi 31 } // namespace 32 33 namespace icu4x { 34 /** 35 * An ICU4X Date object capable of containing a date for any calendar. 36 * 37 * See the [Rust documentation for `Date`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html) for more information. 38 */ 39 class Date { 40 public: 41 42 /** 43 * Creates a new [`Date`] representing the ISO date 44 * given but in a given calendar 45 * 46 * See the [Rust documentation for `new_from_iso`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.new_from_iso) for more information. 47 */ 48 inline static diplomat::result<std::unique_ptr<icu4x::Date>, icu4x::CalendarError> from_iso_in_calendar(int32_t year, uint8_t month, uint8_t day, const icu4x::Calendar& calendar); 49 50 /** 51 * Creates a new [`Date`] from the given codes, which are interpreted in the given calendar system 52 * 53 * An empty era code will treat the year as an extended year 54 * 55 * See the [Rust documentation for `try_new_from_codes`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.try_new_from_codes) for more information. 56 */ 57 inline static diplomat::result<std::unique_ptr<icu4x::Date>, icu4x::CalendarError> from_codes_in_calendar(std::string_view era_code, int32_t year, std::string_view month_code, uint8_t day, const icu4x::Calendar& calendar); 58 59 /** 60 * Creates a new [`Date`] from the given Rata Die 61 * 62 * See the [Rust documentation for `from_rata_die`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.from_rata_die) for more information. 63 */ 64 inline static diplomat::result<std::unique_ptr<icu4x::Date>, icu4x::CalendarError> from_rata_die(int64_t rd, const icu4x::Calendar& calendar); 65 66 /** 67 * Creates a new [`Date`] from an IXDTF string. 68 * 69 * See the [Rust documentation for `try_from_str`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.try_from_str) for more information. 70 */ 71 inline static diplomat::result<std::unique_ptr<icu4x::Date>, icu4x::Rfc9557ParseError> from_string(std::string_view v, const icu4x::Calendar& calendar); 72 73 /** 74 * Convert this date to one in a different calendar 75 * 76 * See the [Rust documentation for `to_calendar`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_calendar) for more information. 77 */ 78 inline std::unique_ptr<icu4x::Date> to_calendar(const icu4x::Calendar& calendar) const; 79 80 /** 81 * Converts this date to ISO 82 * 83 * See the [Rust documentation for `to_iso`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_iso) for more information. 84 */ 85 inline std::unique_ptr<icu4x::IsoDate> to_iso() const; 86 87 /** 88 * Returns this date's Rata Die 89 * 90 * See the [Rust documentation for `to_rata_die`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_rata_die) for more information. 91 */ 92 inline int64_t to_rata_die() const; 93 94 /** 95 * Returns the 1-indexed day in the year for this date 96 * 97 * See the [Rust documentation for `day_of_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_year) for more information. 98 */ 99 inline uint16_t day_of_year() const; 100 101 /** 102 * Returns the 1-indexed day in the month for this date 103 * 104 * 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. 105 */ 106 inline uint8_t day_of_month() const; 107 108 /** 109 * Returns the day in the week for this day 110 * 111 * 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. 112 */ 113 inline icu4x::Weekday day_of_week() const; 114 115 /** 116 * Returns 1-indexed number of the month of this date in its year 117 * 118 * Note that for lunar calendars this may not lead to the same month 119 * having the same ordinal month across years; use month_code if you care 120 * about month identity. 121 * 122 * See the [Rust documentation for `month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month) for more information. 123 * 124 * See the [Rust documentation for `ordinal`](https://docs.rs/icu/latest/icu/calendar/types/struct.MonthInfo.html#structfield.ordinal) for more information. 125 */ 126 inline uint8_t ordinal_month() const; 127 128 /** 129 * Returns the month code for this date. Typically something 130 * like "M01", "M02", but can be more complicated for lunar calendars. 131 * 132 * See the [Rust documentation for `standard_code`](https://docs.rs/icu/latest/icu/calendar/types/struct.MonthInfo.html#structfield.standard_code) for more information. 133 * 134 * Additional information: [1](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month) 135 */ 136 inline std::string month_code() const; 137 138 /** 139 * Returns the month number of this month. 140 * 141 * See the [Rust documentation for `month_number`](https://docs.rs/icu/latest/icu/calendar/types/struct.MonthInfo.html#method.month_number) for more information. 142 */ 143 inline uint8_t month_number() const; 144 145 /** 146 * Returns whether the month is a leap month. 147 * 148 * See the [Rust documentation for `is_leap`](https://docs.rs/icu/latest/icu/calendar/types/struct.MonthInfo.html#method.is_leap) for more information. 149 */ 150 inline bool month_is_leap() const; 151 152 /** 153 * Returns the year number in the current era for this date 154 * 155 * For calendars without an era, returns the related ISO year. 156 * 157 * See the [Rust documentation for `era_year_or_related_iso`](https://docs.rs/icu/latest/icu/calendar/types/enum.YearInfo.html#method.era_year_or_related_iso) for more information. 158 * 159 * Additional information: [1](https://docs.rs/icu/latest/icu/calendar/types/struct.EraYear.html#structfield.year), [2](https://docs.rs/icu/latest/icu/calendar/types/struct.CyclicYear.html#structfield.related_iso), [3](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year) 160 */ 161 inline int32_t era_year_or_related_iso() const; 162 163 /** 164 * Returns the extended year in the Date 165 * 166 * See the [Rust documentation for `extended_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.extended_year) for more information. 167 */ 168 inline int32_t extended_year() const; 169 170 /** 171 * Returns the era for this date, or an empty string 172 * 173 * See the [Rust documentation for `era`](https://docs.rs/icu/latest/icu/calendar/types/struct.EraYear.html#structfield.era) for more information. 174 * 175 * Additional information: [1](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year) 176 */ 177 inline std::string era() const; 178 179 /** 180 * Returns the number of months in the year represented by this date 181 * 182 * 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. 183 */ 184 inline uint8_t months_in_year() const; 185 186 /** 187 * Returns the number of days in the month represented by this date 188 * 189 * 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. 190 */ 191 inline uint8_t days_in_month() const; 192 193 /** 194 * Returns the number of days in the year represented by this date 195 * 196 * 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. 197 */ 198 inline uint16_t days_in_year() const; 199 200 /** 201 * Returns the [`Calendar`] object backing this date 202 * 203 * See the [Rust documentation for `calendar`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.calendar) for more information. 204 */ 205 inline std::unique_ptr<icu4x::Calendar> calendar() const; 206 207 inline const icu4x::capi::Date* AsFFI() const; 208 inline icu4x::capi::Date* AsFFI(); 209 inline static const icu4x::Date* FromFFI(const icu4x::capi::Date* ptr); 210 inline static icu4x::Date* FromFFI(icu4x::capi::Date* ptr); 211 inline static void operator delete(void* ptr); 212 private: 213 Date() = delete; 214 Date(const icu4x::Date&) = delete; 215 Date(icu4x::Date&&) noexcept = delete; 216 Date operator=(const icu4x::Date&) = delete; 217 Date operator=(icu4x::Date&&) noexcept = delete; 218 static void operator delete[](void*, size_t) = delete; 219 }; 220 221 } // namespace 222 #endif // icu4x_Date_D_HPP