| 1 |
import wasm from "./diplomat-wasm.mjs" |
| 2 |
import * as diplomatRuntime from "./diplomat-runtime.mjs" |
| 3 |
import { ICU4XDateLength_js_to_rust, ICU4XDateLength_rust_to_js } from "./ICU4XDateLength.mjs" |
| 4 |
import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs" |
| 5 |
import { ICU4XIsoTimeZoneFormat_js_to_rust, ICU4XIsoTimeZoneFormat_rust_to_js } from "./ICU4XIsoTimeZoneFormat.mjs" |
| 6 |
import { ICU4XIsoTimeZoneMinuteDisplay_js_to_rust, ICU4XIsoTimeZoneMinuteDisplay_rust_to_js } from "./ICU4XIsoTimeZoneMinuteDisplay.mjs" |
| 7 |
import { ICU4XIsoTimeZoneSecondDisplay_js_to_rust, ICU4XIsoTimeZoneSecondDisplay_rust_to_js } from "./ICU4XIsoTimeZoneSecondDisplay.mjs" |
| 8 |
import { ICU4XTimeLength_js_to_rust, ICU4XTimeLength_rust_to_js } from "./ICU4XTimeLength.mjs" |
| 9 |
|
| 10 |
const ICU4XZonedDateTimeFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 11 |
wasm.ICU4XZonedDateTimeFormatter_destroy(underlying); |
| 12 |
}); |
| 13 |
|
| 14 |
export class ICU4XZonedDateTimeFormatter { |
| 15 |
#lifetimeEdges = []; |
| 16 |
constructor(underlying, owned, edges) { |
| 17 |
this.underlying = underlying; |
| 18 |
this.#lifetimeEdges.push(...edges); |
| 19 |
if (owned) { |
| 20 |
ICU4XZonedDateTimeFormatter_box_destroy_registry.register(this, underlying); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
static create_with_lengths(arg_provider, arg_locale, arg_date_length, arg_time_length) { |
| 25 |
return (() => { |
| 26 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 27 |
wasm.ICU4XZonedDateTimeFormatter_create_with_lengths(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ICU4XDateLength_js_to_rust[arg_date_length], ICU4XTimeLength_js_to_rust[arg_time_length]); |
| 28 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 29 |
if (is_ok) { |
| 30 |
const ok_value = new ICU4XZonedDateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 31 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 32 |
return ok_value; |
| 33 |
} else { |
| 34 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 35 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 36 |
throw new diplomatRuntime.FFIError(throw_value); |
| 37 |
} |
| 38 |
})(); |
| 39 |
} |
| 40 |
|
| 41 |
static create_with_lengths_and_iso_8601_time_zone_fallback(arg_provider, arg_locale, arg_date_length, arg_time_length, arg_zone_options) { |
| 42 |
const field_format_arg_zone_options = arg_zone_options["format"]; |
| 43 |
const field_minutes_arg_zone_options = arg_zone_options["minutes"]; |
| 44 |
const field_seconds_arg_zone_options = arg_zone_options["seconds"]; |
| 45 |
return (() => { |
| 46 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 47 |
wasm.ICU4XZonedDateTimeFormatter_create_with_lengths_and_iso_8601_time_zone_fallback(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ICU4XDateLength_js_to_rust[arg_date_length], ICU4XTimeLength_js_to_rust[arg_time_length], ICU4XIsoTimeZoneFormat_js_to_rust[field_format_arg_zone_options], ICU4XIsoTimeZoneMinuteDisplay_js_to_rust[field_minutes_arg_zone_options], ICU4XIsoTimeZoneSecondDisplay_js_to_rust[field_seconds_arg_zone_options]); |
| 48 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 49 |
if (is_ok) { |
| 50 |
const ok_value = new ICU4XZonedDateTimeFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 51 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 52 |
return ok_value; |
| 53 |
} else { |
| 54 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 55 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 56 |
throw new diplomatRuntime.FFIError(throw_value); |
| 57 |
} |
| 58 |
})(); |
| 59 |
} |
| 60 |
|
| 61 |
format_datetime_with_custom_time_zone(arg_datetime, arg_time_zone) { |
| 62 |
return diplomatRuntime.withWriteable(wasm, (writeable) => { |
| 63 |
return (() => { |
| 64 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 65 |
wasm.ICU4XZonedDateTimeFormatter_format_datetime_with_custom_time_zone(diplomat_receive_buffer, this.underlying, arg_datetime.underlying, arg_time_zone.underlying, writeable); |
| 66 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 67 |
if (is_ok) { |
| 68 |
const ok_value = {}; |
| 69 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 70 |
return ok_value; |
| 71 |
} else { |
| 72 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 73 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 74 |
throw new diplomatRuntime.FFIError(throw_value); |
| 75 |
} |
| 76 |
})(); |
| 77 |
}); |
| 78 |
} |
| 79 |
|
| 80 |
format_iso_datetime_with_custom_time_zone(arg_datetime, arg_time_zone) { |
| 81 |
return diplomatRuntime.withWriteable(wasm, (writeable) => { |
| 82 |
return (() => { |
| 83 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 84 |
wasm.ICU4XZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(diplomat_receive_buffer, this.underlying, arg_datetime.underlying, arg_time_zone.underlying, writeable); |
| 85 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 86 |
if (is_ok) { |
| 87 |
const ok_value = {}; |
| 88 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 89 |
return ok_value; |
| 90 |
} else { |
| 91 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 92 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 93 |
throw new diplomatRuntime.FFIError(throw_value); |
| 94 |
} |
| 95 |
})(); |
| 96 |
}); |
| 97 |
} |
| 98 |
} |