| 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 | |
| 6 | const ICU4XDateFormatter_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 7 | wasm.ICU4XDateFormatter_destroy(underlying); |
| 8 | }); |
| 9 | |
| 10 | export class ICU4XDateFormatter { |
| 11 | #lifetimeEdges = []; |
| 12 | constructor(underlying, owned, edges) { |
| 13 | this.underlying = underlying; |
| 14 | this.#lifetimeEdges.push(...edges); |
| 15 | if (owned) { |
| 16 | ICU4XDateFormatter_box_destroy_registry.register(this, underlying); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | static create_with_length(arg_provider, arg_locale, arg_date_length) { |
| 21 | return (() => { |
| 22 | const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 23 | wasm.ICU4XDateFormatter_create_with_length(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ICU4XDateLength_js_to_rust[arg_date_length]); |
| 24 | const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 25 | if (is_ok) { |
| 26 | const ok_value = new ICU4XDateFormatter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 27 | wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 28 | return ok_value; |
| 29 | } else { |
| 30 | const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 31 | wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 32 | throw new diplomatRuntime.FFIError(throw_value); |
| 33 | } |
| 34 | })(); |
| 35 | } |
| 36 | |
| 37 | format_date(arg_value) { |
| 38 | return diplomatRuntime.withWriteable(wasm, (writeable) => { |
| 39 | return (() => { |
| 40 | const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 41 | wasm.ICU4XDateFormatter_format_date(diplomat_receive_buffer, this.underlying, arg_value.underlying, writeable); |
| 42 | const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 43 | if (is_ok) { |
| 44 | const ok_value = {}; |
| 45 | wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 46 | return ok_value; |
| 47 | } else { |
| 48 | const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 49 | wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 50 | throw new diplomatRuntime.FFIError(throw_value); |
| 51 | } |
| 52 | })(); |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | format_iso_date(arg_value) { |
| 57 | return diplomatRuntime.withWriteable(wasm, (writeable) => { |
| 58 | return (() => { |
| 59 | const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 60 | wasm.ICU4XDateFormatter_format_iso_date(diplomat_receive_buffer, this.underlying, arg_value.underlying, writeable); |
| 61 | const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 62 | if (is_ok) { |
| 63 | const ok_value = {}; |
| 64 | wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 65 | return ok_value; |
| 66 | } else { |
| 67 | const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 68 | wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 69 | throw new diplomatRuntime.FFIError(throw_value); |
| 70 | } |
| 71 | })(); |
| 72 | }); |
| 73 | } |
| 74 | |
| 75 | format_datetime(arg_value) { |
| 76 | return diplomatRuntime.withWriteable(wasm, (writeable) => { |
| 77 | return (() => { |
| 78 | const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 79 | wasm.ICU4XDateFormatter_format_datetime(diplomat_receive_buffer, this.underlying, arg_value.underlying, writeable); |
| 80 | const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 81 | if (is_ok) { |
| 82 | const ok_value = {}; |
| 83 | wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 84 | return ok_value; |
| 85 | } else { |
| 86 | const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 87 | wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 88 | throw new diplomatRuntime.FFIError(throw_value); |
| 89 | } |
| 90 | })(); |
| 91 | }); |
| 92 | } |
| 93 | |
| 94 | format_iso_datetime(arg_value) { |
| 95 | return diplomatRuntime.withWriteable(wasm, (writeable) => { |
| 96 | return (() => { |
| 97 | const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 98 | wasm.ICU4XDateFormatter_format_iso_datetime(diplomat_receive_buffer, this.underlying, arg_value.underlying, writeable); |
| 99 | const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 100 | if (is_ok) { |
| 101 | const ok_value = {}; |
| 102 | wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 103 | return ok_value; |
| 104 | } else { |
| 105 | const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 106 | wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 107 | throw new diplomatRuntime.FFIError(throw_value); |
| 108 | } |
| 109 | })(); |
| 110 | }); |
| 111 | } |
| 112 | } |