| 1 |
import wasm from "./diplomat-wasm.mjs" |
| 2 |
import * as diplomatRuntime from "./diplomat-runtime.mjs" |
| 3 |
import { ICU4XCalendar } from "./ICU4XCalendar.mjs" |
| 4 |
import { ICU4XDate } from "./ICU4XDate.mjs" |
| 5 |
import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs" |
| 6 |
import { ICU4XIsoDateTime } from "./ICU4XIsoDateTime.mjs" |
| 7 |
import { ICU4XIsoWeekday_js_to_rust, ICU4XIsoWeekday_rust_to_js } from "./ICU4XIsoWeekday.mjs" |
| 8 |
import { ICU4XTime } from "./ICU4XTime.mjs" |
| 9 |
import { ICU4XWeekOf } from "./ICU4XWeekOf.mjs" |
| 10 |
import { ICU4XWeekRelativeUnit_js_to_rust, ICU4XWeekRelativeUnit_rust_to_js } from "./ICU4XWeekRelativeUnit.mjs" |
| 11 |
|
| 12 |
const ICU4XDateTime_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 13 |
wasm.ICU4XDateTime_destroy(underlying); |
| 14 |
}); |
| 15 |
|
| 16 |
export class ICU4XDateTime { |
| 17 |
#lifetimeEdges = []; |
| 18 |
constructor(underlying, owned, edges) { |
| 19 |
this.underlying = underlying; |
| 20 |
this.#lifetimeEdges.push(...edges); |
| 21 |
if (owned) { |
| 22 |
ICU4XDateTime_box_destroy_registry.register(this, underlying); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
static create_from_iso_in_calendar(arg_year, arg_month, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond, arg_calendar) { |
| 27 |
return (() => { |
| 28 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 29 |
wasm.ICU4XDateTime_create_from_iso_in_calendar(diplomat_receive_buffer, arg_year, arg_month, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond, arg_calendar.underlying); |
| 30 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 31 |
if (is_ok) { |
| 32 |
const ok_value = new ICU4XDateTime(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 33 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 34 |
return ok_value; |
| 35 |
} else { |
| 36 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 37 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 38 |
throw new diplomatRuntime.FFIError(throw_value); |
| 39 |
} |
| 40 |
})(); |
| 41 |
} |
| 42 |
|
| 43 |
static create_from_codes_in_calendar(arg_era_code, arg_year, arg_month_code, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond, arg_calendar) { |
| 44 |
const buf_arg_era_code = diplomatRuntime.DiplomatBuf.str8(wasm, arg_era_code); |
| 45 |
const buf_arg_month_code = diplomatRuntime.DiplomatBuf.str8(wasm, arg_month_code); |
| 46 |
const diplomat_out = (() => { |
| 47 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 48 |
wasm.ICU4XDateTime_create_from_codes_in_calendar(diplomat_receive_buffer, buf_arg_era_code.ptr, buf_arg_era_code.size, arg_year, buf_arg_month_code.ptr, buf_arg_month_code.size, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond, arg_calendar.underlying); |
| 49 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 50 |
if (is_ok) { |
| 51 |
const ok_value = new ICU4XDateTime(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 52 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 53 |
return ok_value; |
| 54 |
} else { |
| 55 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 56 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 57 |
throw new diplomatRuntime.FFIError(throw_value); |
| 58 |
} |
| 59 |
})(); |
| 60 |
buf_arg_era_code.free(); |
| 61 |
buf_arg_month_code.free(); |
| 62 |
return diplomat_out; |
| 63 |
} |
| 64 |
|
| 65 |
static create_from_date_and_time(arg_date, arg_time) { |
| 66 |
return new ICU4XDateTime(wasm.ICU4XDateTime_create_from_date_and_time(arg_date.underlying, arg_time.underlying), true, []); |
| 67 |
} |
| 68 |
|
| 69 |
date() { |
| 70 |
return new ICU4XDate(wasm.ICU4XDateTime_date(this.underlying), true, []); |
| 71 |
} |
| 72 |
|
| 73 |
time() { |
| 74 |
return new ICU4XTime(wasm.ICU4XDateTime_time(this.underlying), true, []); |
| 75 |
} |
| 76 |
|
| 77 |
to_iso() { |
| 78 |
return new ICU4XIsoDateTime(wasm.ICU4XDateTime_to_iso(this.underlying), true, []); |
| 79 |
} |
| 80 |
|
| 81 |
to_calendar(arg_calendar) { |
| 82 |
return new ICU4XDateTime(wasm.ICU4XDateTime_to_calendar(this.underlying, arg_calendar.underlying), true, []); |
| 83 |
} |
| 84 |
|
| 85 |
hour() { |
| 86 |
return wasm.ICU4XDateTime_hour(this.underlying); |
| 87 |
} |
| 88 |
|
| 89 |
minute() { |
| 90 |
return wasm.ICU4XDateTime_minute(this.underlying); |
| 91 |
} |
| 92 |
|
| 93 |
second() { |
| 94 |
return wasm.ICU4XDateTime_second(this.underlying); |
| 95 |
} |
| 96 |
|
| 97 |
nanosecond() { |
| 98 |
return wasm.ICU4XDateTime_nanosecond(this.underlying); |
| 99 |
} |
| 100 |
|
| 101 |
day_of_year() { |
| 102 |
return wasm.ICU4XDateTime_day_of_year(this.underlying); |
| 103 |
} |
| 104 |
|
| 105 |
day_of_month() { |
| 106 |
return wasm.ICU4XDateTime_day_of_month(this.underlying); |
| 107 |
} |
| 108 |
|
| 109 |
day_of_week() { |
| 110 |
return ICU4XIsoWeekday_rust_to_js[wasm.ICU4XDateTime_day_of_week(this.underlying)]; |
| 111 |
} |
| 112 |
|
| 113 |
week_of_month(arg_first_weekday) { |
| 114 |
return wasm.ICU4XDateTime_week_of_month(this.underlying, ICU4XIsoWeekday_js_to_rust[arg_first_weekday]); |
| 115 |
} |
| 116 |
|
| 117 |
week_of_year(arg_calculator) { |
| 118 |
return (() => { |
| 119 |
const diplomat_receive_buffer = wasm.diplomat_alloc(9, 4); |
| 120 |
wasm.ICU4XDateTime_week_of_year(diplomat_receive_buffer, this.underlying, arg_calculator.underlying); |
| 121 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 8); |
| 122 |
if (is_ok) { |
| 123 |
const ok_value = new ICU4XWeekOf(diplomat_receive_buffer); |
| 124 |
wasm.diplomat_free(diplomat_receive_buffer, 9, 4); |
| 125 |
return ok_value; |
| 126 |
} else { |
| 127 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 128 |
wasm.diplomat_free(diplomat_receive_buffer, 9, 4); |
| 129 |
throw new diplomatRuntime.FFIError(throw_value); |
| 130 |
} |
| 131 |
})(); |
| 132 |
} |
| 133 |
|
| 134 |
ordinal_month() { |
| 135 |
return wasm.ICU4XDateTime_ordinal_month(this.underlying); |
| 136 |
} |
| 137 |
|
| 138 |
month_code() { |
| 139 |
return diplomatRuntime.withWriteable(wasm, (writeable) => { |
| 140 |
return (() => { |
| 141 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 142 |
wasm.ICU4XDateTime_month_code(diplomat_receive_buffer, this.underlying, writeable); |
| 143 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 144 |
if (is_ok) { |
| 145 |
const ok_value = {}; |
| 146 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 147 |
return ok_value; |
| 148 |
} else { |
| 149 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 150 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 151 |
throw new diplomatRuntime.FFIError(throw_value); |
| 152 |
} |
| 153 |
})(); |
| 154 |
}); |
| 155 |
} |
| 156 |
|
| 157 |
year_in_era() { |
| 158 |
return wasm.ICU4XDateTime_year_in_era(this.underlying); |
| 159 |
} |
| 160 |
|
| 161 |
era() { |
| 162 |
return diplomatRuntime.withWriteable(wasm, (writeable) => { |
| 163 |
return (() => { |
| 164 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 165 |
wasm.ICU4XDateTime_era(diplomat_receive_buffer, this.underlying, writeable); |
| 166 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 167 |
if (is_ok) { |
| 168 |
const ok_value = {}; |
| 169 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 170 |
return ok_value; |
| 171 |
} else { |
| 172 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 173 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 174 |
throw new diplomatRuntime.FFIError(throw_value); |
| 175 |
} |
| 176 |
})(); |
| 177 |
}); |
| 178 |
} |
| 179 |
|
| 180 |
months_in_year() { |
| 181 |
return wasm.ICU4XDateTime_months_in_year(this.underlying); |
| 182 |
} |
| 183 |
|
| 184 |
days_in_month() { |
| 185 |
return wasm.ICU4XDateTime_days_in_month(this.underlying); |
| 186 |
} |
| 187 |
|
| 188 |
days_in_year() { |
| 189 |
return wasm.ICU4XDateTime_days_in_year(this.underlying); |
| 190 |
} |
| 191 |
|
| 192 |
calendar() { |
| 193 |
return new ICU4XCalendar(wasm.ICU4XDateTime_calendar(this.underlying), true, []); |
| 194 |
} |
| 195 |
} |