Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XIsoDate.mjs

raw
1 import wasm from "./diplomat-wasm.mjs"
2 import * as diplomatRuntime from "./diplomat-runtime.mjs"
3 import { ICU4XDate } from "./ICU4XDate.mjs"
4 import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs"
5 import { ICU4XIsoWeekday_js_to_rust, ICU4XIsoWeekday_rust_to_js } from "./ICU4XIsoWeekday.mjs"
6 import { ICU4XWeekOf } from "./ICU4XWeekOf.mjs"
7 import { ICU4XWeekRelativeUnit_js_to_rust, ICU4XWeekRelativeUnit_rust_to_js } from "./ICU4XWeekRelativeUnit.mjs"
8
9 const ICU4XIsoDate_box_destroy_registry = new FinalizationRegistry(underlying => {
10 wasm.ICU4XIsoDate_destroy(underlying);
11 });
12
13 export class ICU4XIsoDate {
14 #lifetimeEdges = [];
15 constructor(underlying, owned, edges) {
16 this.underlying = underlying;
17 this.#lifetimeEdges.push(...edges);
18 if (owned) {
19 ICU4XIsoDate_box_destroy_registry.register(this, underlying);
20 }
21 }
22
23 static create(arg_year, arg_month, arg_day) {
24 return (() => {
25 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
26 wasm.ICU4XIsoDate_create(diplomat_receive_buffer, arg_year, arg_month, arg_day);
27 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
28 if (is_ok) {
29 const ok_value = new ICU4XIsoDate(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []);
30 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
31 return ok_value;
32 } else {
33 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
34 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
35 throw new diplomatRuntime.FFIError(throw_value);
36 }
37 })();
38 }
39
40 static create_for_unix_epoch() {
41 return new ICU4XIsoDate(wasm.ICU4XIsoDate_create_for_unix_epoch(), true, []);
42 }
43
44 to_calendar(arg_calendar) {
45 return new ICU4XDate(wasm.ICU4XIsoDate_to_calendar(this.underlying, arg_calendar.underlying), true, []);
46 }
47
48 to_any() {
49 return new ICU4XDate(wasm.ICU4XIsoDate_to_any(this.underlying), true, []);
50 }
51
52 day_of_year() {
53 return wasm.ICU4XIsoDate_day_of_year(this.underlying);
54 }
55
56 day_of_month() {
57 return wasm.ICU4XIsoDate_day_of_month(this.underlying);
58 }
59
60 day_of_week() {
61 return ICU4XIsoWeekday_rust_to_js[wasm.ICU4XIsoDate_day_of_week(this.underlying)];
62 }
63
64 week_of_month(arg_first_weekday) {
65 return wasm.ICU4XIsoDate_week_of_month(this.underlying, ICU4XIsoWeekday_js_to_rust[arg_first_weekday]);
66 }
67
68 week_of_year(arg_calculator) {
69 return (() => {
70 const diplomat_receive_buffer = wasm.diplomat_alloc(9, 4);
71 wasm.ICU4XIsoDate_week_of_year(diplomat_receive_buffer, this.underlying, arg_calculator.underlying);
72 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 8);
73 if (is_ok) {
74 const ok_value = new ICU4XWeekOf(diplomat_receive_buffer);
75 wasm.diplomat_free(diplomat_receive_buffer, 9, 4);
76 return ok_value;
77 } else {
78 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
79 wasm.diplomat_free(diplomat_receive_buffer, 9, 4);
80 throw new diplomatRuntime.FFIError(throw_value);
81 }
82 })();
83 }
84
85 month() {
86 return wasm.ICU4XIsoDate_month(this.underlying);
87 }
88
89 year() {
90 return wasm.ICU4XIsoDate_year(this.underlying);
91 }
92
93 is_in_leap_year() {
94 return wasm.ICU4XIsoDate_is_in_leap_year(this.underlying);
95 }
96
97 months_in_year() {
98 return wasm.ICU4XIsoDate_months_in_year(this.underlying);
99 }
100
101 days_in_month() {
102 return wasm.ICU4XIsoDate_days_in_month(this.underlying);
103 }
104
105 days_in_year() {
106 return wasm.ICU4XIsoDate_days_in_year(this.underlying);
107 }
108 }