Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XDate.mjs

raw
1 import wasm from "./diplomat-wasm.mjs"
2 import * as diplomatRuntime from "./diplomat-runtime.mjs"
3 import { ICU4XCalendar } from "./ICU4XCalendar.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 { ICU4XWeekOf } from "./ICU4XWeekOf.mjs"
8 import { ICU4XWeekRelativeUnit_js_to_rust, ICU4XWeekRelativeUnit_rust_to_js } from "./ICU4XWeekRelativeUnit.mjs"
9
10 const ICU4XDate_box_destroy_registry = new FinalizationRegistry(underlying => {
11 wasm.ICU4XDate_destroy(underlying);
12 });
13
14 export class ICU4XDate {
15 #lifetimeEdges = [];
16 constructor(underlying, owned, edges) {
17 this.underlying = underlying;
18 this.#lifetimeEdges.push(...edges);
19 if (owned) {
20 ICU4XDate_box_destroy_registry.register(this, underlying);
21 }
22 }
23
24 static create_from_iso_in_calendar(arg_year, arg_month, arg_day, arg_calendar) {
25 return (() => {
26 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
27 wasm.ICU4XDate_create_from_iso_in_calendar(diplomat_receive_buffer, arg_year, arg_month, arg_day, arg_calendar.underlying);
28 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
29 if (is_ok) {
30 const ok_value = new ICU4XDate(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_from_codes_in_calendar(arg_era_code, arg_year, arg_month_code, arg_day, arg_calendar) {
42 const buf_arg_era_code = diplomatRuntime.DiplomatBuf.str8(wasm, arg_era_code);
43 const buf_arg_month_code = diplomatRuntime.DiplomatBuf.str8(wasm, arg_month_code);
44 const diplomat_out = (() => {
45 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
46 wasm.ICU4XDate_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_calendar.underlying);
47 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
48 if (is_ok) {
49 const ok_value = new ICU4XDate(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []);
50 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
51 return ok_value;
52 } else {
53 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
54 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
55 throw new diplomatRuntime.FFIError(throw_value);
56 }
57 })();
58 buf_arg_era_code.free();
59 buf_arg_month_code.free();
60 return diplomat_out;
61 }
62
63 to_calendar(arg_calendar) {
64 return new ICU4XDate(wasm.ICU4XDate_to_calendar(this.underlying, arg_calendar.underlying), true, []);
65 }
66
67 to_iso() {
68 return new ICU4XIsoDate(wasm.ICU4XDate_to_iso(this.underlying), true, []);
69 }
70
71 day_of_year() {
72 return wasm.ICU4XDate_day_of_year(this.underlying);
73 }
74
75 day_of_month() {
76 return wasm.ICU4XDate_day_of_month(this.underlying);
77 }
78
79 day_of_week() {
80 return ICU4XIsoWeekday_rust_to_js[wasm.ICU4XDate_day_of_week(this.underlying)];
81 }
82
83 week_of_month(arg_first_weekday) {
84 return wasm.ICU4XDate_week_of_month(this.underlying, ICU4XIsoWeekday_js_to_rust[arg_first_weekday]);
85 }
86
87 week_of_year(arg_calculator) {
88 return (() => {
89 const diplomat_receive_buffer = wasm.diplomat_alloc(9, 4);
90 wasm.ICU4XDate_week_of_year(diplomat_receive_buffer, this.underlying, arg_calculator.underlying);
91 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 8);
92 if (is_ok) {
93 const ok_value = new ICU4XWeekOf(diplomat_receive_buffer);
94 wasm.diplomat_free(diplomat_receive_buffer, 9, 4);
95 return ok_value;
96 } else {
97 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
98 wasm.diplomat_free(diplomat_receive_buffer, 9, 4);
99 throw new diplomatRuntime.FFIError(throw_value);
100 }
101 })();
102 }
103
104 ordinal_month() {
105 return wasm.ICU4XDate_ordinal_month(this.underlying);
106 }
107
108 month_code() {
109 return diplomatRuntime.withWriteable(wasm, (writeable) => {
110 return (() => {
111 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
112 wasm.ICU4XDate_month_code(diplomat_receive_buffer, this.underlying, writeable);
113 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
114 if (is_ok) {
115 const ok_value = {};
116 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
117 return ok_value;
118 } else {
119 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
120 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
121 throw new diplomatRuntime.FFIError(throw_value);
122 }
123 })();
124 });
125 }
126
127 year_in_era() {
128 return wasm.ICU4XDate_year_in_era(this.underlying);
129 }
130
131 era() {
132 return diplomatRuntime.withWriteable(wasm, (writeable) => {
133 return (() => {
134 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
135 wasm.ICU4XDate_era(diplomat_receive_buffer, this.underlying, writeable);
136 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
137 if (is_ok) {
138 const ok_value = {};
139 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
140 return ok_value;
141 } else {
142 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
143 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
144 throw new diplomatRuntime.FFIError(throw_value);
145 }
146 })();
147 });
148 }
149
150 months_in_year() {
151 return wasm.ICU4XDate_months_in_year(this.underlying);
152 }
153
154 days_in_month() {
155 return wasm.ICU4XDate_days_in_month(this.underlying);
156 }
157
158 days_in_year() {
159 return wasm.ICU4XDate_days_in_year(this.underlying);
160 }
161
162 calendar() {
163 return new ICU4XCalendar(wasm.ICU4XDate_calendar(this.underlying), true, []);
164 }
165 }