| 1 |
import wasm from "./diplomat-wasm.mjs" |
| 2 |
import * as diplomatRuntime from "./diplomat-runtime.mjs" |
| 3 |
import { ICU4XDateTime } from "./ICU4XDateTime.mjs" |
| 4 |
import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs" |
| 5 |
import { ICU4XIsoDate } from "./ICU4XIsoDate.mjs" |
| 6 |
import { ICU4XIsoWeekday_js_to_rust, ICU4XIsoWeekday_rust_to_js } from "./ICU4XIsoWeekday.mjs" |
| 7 |
import { ICU4XTime } from "./ICU4XTime.mjs" |
| 8 |
import { ICU4XWeekOf } from "./ICU4XWeekOf.mjs" |
| 9 |
import { ICU4XWeekRelativeUnit_js_to_rust, ICU4XWeekRelativeUnit_rust_to_js } from "./ICU4XWeekRelativeUnit.mjs" |
| 10 |
|
| 11 |
const ICU4XIsoDateTime_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 12 |
wasm.ICU4XIsoDateTime_destroy(underlying); |
| 13 |
}); |
| 14 |
|
| 15 |
export class ICU4XIsoDateTime { |
| 16 |
#lifetimeEdges = []; |
| 17 |
constructor(underlying, owned, edges) { |
| 18 |
this.underlying = underlying; |
| 19 |
this.#lifetimeEdges.push(...edges); |
| 20 |
if (owned) { |
| 21 |
ICU4XIsoDateTime_box_destroy_registry.register(this, underlying); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
static create(arg_year, arg_month, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond) { |
| 26 |
return (() => { |
| 27 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 28 |
wasm.ICU4XIsoDateTime_create(diplomat_receive_buffer, arg_year, arg_month, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond); |
| 29 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 30 |
if (is_ok) { |
| 31 |
const ok_value = new ICU4XIsoDateTime(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 32 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 33 |
return ok_value; |
| 34 |
} else { |
| 35 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 36 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 37 |
throw new diplomatRuntime.FFIError(throw_value); |
| 38 |
} |
| 39 |
})(); |
| 40 |
} |
| 41 |
|
| 42 |
static crate_from_date_and_time(arg_date, arg_time) { |
| 43 |
return new ICU4XIsoDateTime(wasm.ICU4XIsoDateTime_crate_from_date_and_time(arg_date.underlying, arg_time.underlying), true, []); |
| 44 |
} |
| 45 |
|
| 46 |
static local_unix_epoch() { |
| 47 |
return new ICU4XIsoDateTime(wasm.ICU4XIsoDateTime_local_unix_epoch(), true, []); |
| 48 |
} |
| 49 |
|
| 50 |
static create_from_minutes_since_local_unix_epoch(arg_minutes) { |
| 51 |
return new ICU4XIsoDateTime(wasm.ICU4XIsoDateTime_create_from_minutes_since_local_unix_epoch(arg_minutes), true, []); |
| 52 |
} |
| 53 |
|
| 54 |
date() { |
| 55 |
return new ICU4XIsoDate(wasm.ICU4XIsoDateTime_date(this.underlying), true, []); |
| 56 |
} |
| 57 |
|
| 58 |
time() { |
| 59 |
return new ICU4XTime(wasm.ICU4XIsoDateTime_time(this.underlying), true, []); |
| 60 |
} |
| 61 |
|
| 62 |
to_any() { |
| 63 |
return new ICU4XDateTime(wasm.ICU4XIsoDateTime_to_any(this.underlying), true, []); |
| 64 |
} |
| 65 |
|
| 66 |
minutes_since_local_unix_epoch() { |
| 67 |
return wasm.ICU4XIsoDateTime_minutes_since_local_unix_epoch(this.underlying); |
| 68 |
} |
| 69 |
|
| 70 |
to_calendar(arg_calendar) { |
| 71 |
return new ICU4XDateTime(wasm.ICU4XIsoDateTime_to_calendar(this.underlying, arg_calendar.underlying), true, []); |
| 72 |
} |
| 73 |
|
| 74 |
hour() { |
| 75 |
return wasm.ICU4XIsoDateTime_hour(this.underlying); |
| 76 |
} |
| 77 |
|
| 78 |
minute() { |
| 79 |
return wasm.ICU4XIsoDateTime_minute(this.underlying); |
| 80 |
} |
| 81 |
|
| 82 |
second() { |
| 83 |
return wasm.ICU4XIsoDateTime_second(this.underlying); |
| 84 |
} |
| 85 |
|
| 86 |
nanosecond() { |
| 87 |
return wasm.ICU4XIsoDateTime_nanosecond(this.underlying); |
| 88 |
} |
| 89 |
|
| 90 |
day_of_year() { |
| 91 |
return wasm.ICU4XIsoDateTime_day_of_year(this.underlying); |
| 92 |
} |
| 93 |
|
| 94 |
day_of_month() { |
| 95 |
return wasm.ICU4XIsoDateTime_day_of_month(this.underlying); |
| 96 |
} |
| 97 |
|
| 98 |
day_of_week() { |
| 99 |
return ICU4XIsoWeekday_rust_to_js[wasm.ICU4XIsoDateTime_day_of_week(this.underlying)]; |
| 100 |
} |
| 101 |
|
| 102 |
week_of_month(arg_first_weekday) { |
| 103 |
return wasm.ICU4XIsoDateTime_week_of_month(this.underlying, ICU4XIsoWeekday_js_to_rust[arg_first_weekday]); |
| 104 |
} |
| 105 |
|
| 106 |
week_of_year(arg_calculator) { |
| 107 |
return (() => { |
| 108 |
const diplomat_receive_buffer = wasm.diplomat_alloc(9, 4); |
| 109 |
wasm.ICU4XIsoDateTime_week_of_year(diplomat_receive_buffer, this.underlying, arg_calculator.underlying); |
| 110 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 8); |
| 111 |
if (is_ok) { |
| 112 |
const ok_value = new ICU4XWeekOf(diplomat_receive_buffer); |
| 113 |
wasm.diplomat_free(diplomat_receive_buffer, 9, 4); |
| 114 |
return ok_value; |
| 115 |
} else { |
| 116 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 117 |
wasm.diplomat_free(diplomat_receive_buffer, 9, 4); |
| 118 |
throw new diplomatRuntime.FFIError(throw_value); |
| 119 |
} |
| 120 |
})(); |
| 121 |
} |
| 122 |
|
| 123 |
month() { |
| 124 |
return wasm.ICU4XIsoDateTime_month(this.underlying); |
| 125 |
} |
| 126 |
|
| 127 |
year() { |
| 128 |
return wasm.ICU4XIsoDateTime_year(this.underlying); |
| 129 |
} |
| 130 |
|
| 131 |
is_in_leap_year() { |
| 132 |
return wasm.ICU4XIsoDateTime_is_in_leap_year(this.underlying); |
| 133 |
} |
| 134 |
|
| 135 |
months_in_year() { |
| 136 |
return wasm.ICU4XIsoDateTime_months_in_year(this.underlying); |
| 137 |
} |
| 138 |
|
| 139 |
days_in_month() { |
| 140 |
return wasm.ICU4XIsoDateTime_days_in_month(this.underlying); |
| 141 |
} |
| 142 |
|
| 143 |
days_in_year() { |
| 144 |
return wasm.ICU4XIsoDateTime_days_in_year(this.underlying); |
| 145 |
} |
| 146 |
} |