• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { IsoDate } from "./IsoDate.mjs"
3import { IsoDateTime } from "./IsoDateTime.mjs"
4import { Time } from "./Time.mjs"
5import { TimeZone } from "./TimeZone.mjs"
6import { TimeZoneVariant } from "./TimeZoneVariant.mjs"
7import { UtcOffset } from "./UtcOffset.mjs"
8import { UtcOffsetCalculator } from "./UtcOffsetCalculator.mjs"
9import wasm from "./diplomat-wasm.mjs";
10import * as diplomatRuntime from "./diplomat-runtime.mjs";
11
12
13/** See the [Rust documentation for `TimeZoneInfo`](https://docs.rs/icu/latest/icu/time/struct.TimeZoneInfo.html) for more information.
14*/
15const TimeZoneInfo_box_destroy_registry = new FinalizationRegistry((ptr) => {
16    wasm.icu4x_TimeZoneInfo_destroy_mv1(ptr);
17});
18
19export class TimeZoneInfo {
20
21    // Internal ptr reference:
22    #ptr = null;
23
24    // Lifetimes are only to keep dependencies alive.
25    // Since JS won't garbage collect until there are no incoming edges.
26    #selfEdge = [];
27
28    #internalConstructor(symbol, ptr, selfEdge) {
29        if (symbol !== diplomatRuntime.internalConstructor) {
30            console.error("TimeZoneInfo is an Opaque type. You cannot call its constructor.");
31            return;
32        }
33
34        this.#ptr = ptr;
35        this.#selfEdge = selfEdge;
36
37        // Are we being borrowed? If not, we can register.
38        if (this.#selfEdge.length === 0) {
39            TimeZoneInfo_box_destroy_registry.register(this, this.#ptr);
40        }
41
42        return this;
43    }
44    get ffiValue() {
45        return this.#ptr;
46    }
47
48    static utc() {
49        const result = wasm.icu4x_TimeZoneInfo_utc_mv1();
50
51        try {
52            return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []);
53        }
54
55        finally {}
56    }
57
58    #defaultConstructor(timeZoneId, offset, zoneVariant) {
59        const result = wasm.icu4x_TimeZoneInfo_from_parts_mv1(timeZoneId.ffiValue, offset.ffiValue ?? 0, ...diplomatRuntime.optionToArgsForCalling(zoneVariant, 4, 4, false, (arrayBuffer, offset, jsValue) => [diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)]));
60
61        try {
62            return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []);
63        }
64
65        finally {}
66    }
67
68    timeZoneId() {
69        const result = wasm.icu4x_TimeZoneInfo_time_zone_id_mv1(this.ffiValue);
70
71        try {
72            return new TimeZone(diplomatRuntime.internalConstructor, result, []);
73        }
74
75        finally {}
76    }
77
78    atTime(date, time) {
79        const result = wasm.icu4x_TimeZoneInfo_at_time_mv1(this.ffiValue, date.ffiValue, time.ffiValue);
80
81        try {
82            return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []);
83        }
84
85        finally {}
86    }
87
88    localTime() {
89        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);
90
91        const result = wasm.icu4x_TimeZoneInfo_local_time_mv1(diplomatReceive.buffer, this.ffiValue);
92
93        try {
94            if (!diplomatReceive.resultFlag) {
95                return null;
96            }
97            return IsoDateTime._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer);
98        }
99
100        finally {
101            diplomatReceive.free();
102        }
103    }
104
105    withZoneVariant(timeZoneVariant) {
106        const result = wasm.icu4x_TimeZoneInfo_with_zone_variant_mv1(this.ffiValue, timeZoneVariant.ffiValue);
107
108        try {
109            return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []);
110        }
111
112        finally {}
113    }
114
115    inferZoneVariant(offsetCalculator) {
116        const result = wasm.icu4x_TimeZoneInfo_infer_zone_variant_mv1(this.ffiValue, offsetCalculator.ffiValue);
117
118        try {
119            return result === 1;
120        }
121
122        finally {}
123    }
124
125    zoneVariant() {
126        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
127
128        const result = wasm.icu4x_TimeZoneInfo_zone_variant_mv1(diplomatReceive.buffer, this.ffiValue);
129
130        try {
131            if (!diplomatReceive.resultFlag) {
132                return null;
133            }
134            return new TimeZoneVariant(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
135        }
136
137        finally {
138            diplomatReceive.free();
139        }
140    }
141
142    constructor(timeZoneId, offset, zoneVariant) {
143        if (arguments[0] === diplomatRuntime.exposeConstructor) {
144            return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1));
145        } else if (arguments[0] === diplomatRuntime.internalConstructor) {
146            return this.#internalConstructor(...arguments);
147        } else {
148            return this.#defaultConstructor(...arguments);
149        }
150    }
151}