| // generated by diplomat-tool |
| import { IsoDate } from "./IsoDate.mjs" |
| import { IsoDateTime } from "./IsoDateTime.mjs" |
| import { Time } from "./Time.mjs" |
| import { TimeZone } from "./TimeZone.mjs" |
| import { TimeZoneVariant } from "./TimeZoneVariant.mjs" |
| import { UtcOffset } from "./UtcOffset.mjs" |
| import { UtcOffsetCalculator } from "./UtcOffsetCalculator.mjs" |
| import wasm from "./diplomat-wasm.mjs"; |
| import * as diplomatRuntime from "./diplomat-runtime.mjs"; |
| |
| |
| /** See the [Rust documentation for `TimeZoneInfo`](https://docs.rs/icu/latest/icu/time/struct.TimeZoneInfo.html) for more information. |
| */ |
| const TimeZoneInfo_box_destroy_registry = new FinalizationRegistry((ptr) => { |
| wasm.icu4x_TimeZoneInfo_destroy_mv1(ptr); |
| }); |
| |
| export class TimeZoneInfo { |
| |
| // Internal ptr reference: |
| #ptr = null; |
| |
| // Lifetimes are only to keep dependencies alive. |
| // Since JS won't garbage collect until there are no incoming edges. |
| #selfEdge = []; |
| |
| #internalConstructor(symbol, ptr, selfEdge) { |
| if (symbol !== diplomatRuntime.internalConstructor) { |
| console.error("TimeZoneInfo is an Opaque type. You cannot call its constructor."); |
| return; |
| } |
| |
| this.#ptr = ptr; |
| this.#selfEdge = selfEdge; |
| |
| // Are we being borrowed? If not, we can register. |
| if (this.#selfEdge.length === 0) { |
| TimeZoneInfo_box_destroy_registry.register(this, this.#ptr); |
| } |
| |
| return this; |
| } |
| get ffiValue() { |
| return this.#ptr; |
| } |
| |
| static utc() { |
| const result = wasm.icu4x_TimeZoneInfo_utc_mv1(); |
| |
| try { |
| return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []); |
| } |
| |
| finally {} |
| } |
| |
| #defaultConstructor(timeZoneId, offset, zoneVariant) { |
| 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)])); |
| |
| try { |
| return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []); |
| } |
| |
| finally {} |
| } |
| |
| timeZoneId() { |
| const result = wasm.icu4x_TimeZoneInfo_time_zone_id_mv1(this.ffiValue); |
| |
| try { |
| return new TimeZone(diplomatRuntime.internalConstructor, result, []); |
| } |
| |
| finally {} |
| } |
| |
| atTime(date, time) { |
| const result = wasm.icu4x_TimeZoneInfo_at_time_mv1(this.ffiValue, date.ffiValue, time.ffiValue); |
| |
| try { |
| return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []); |
| } |
| |
| finally {} |
| } |
| |
| localTime() { |
| const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true); |
| |
| const result = wasm.icu4x_TimeZoneInfo_local_time_mv1(diplomatReceive.buffer, this.ffiValue); |
| |
| try { |
| if (!diplomatReceive.resultFlag) { |
| return null; |
| } |
| return IsoDateTime._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer); |
| } |
| |
| finally { |
| diplomatReceive.free(); |
| } |
| } |
| |
| withZoneVariant(timeZoneVariant) { |
| const result = wasm.icu4x_TimeZoneInfo_with_zone_variant_mv1(this.ffiValue, timeZoneVariant.ffiValue); |
| |
| try { |
| return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []); |
| } |
| |
| finally {} |
| } |
| |
| inferZoneVariant(offsetCalculator) { |
| const result = wasm.icu4x_TimeZoneInfo_infer_zone_variant_mv1(this.ffiValue, offsetCalculator.ffiValue); |
| |
| try { |
| return result === 1; |
| } |
| |
| finally {} |
| } |
| |
| zoneVariant() { |
| const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); |
| |
| const result = wasm.icu4x_TimeZoneInfo_zone_variant_mv1(diplomatReceive.buffer, this.ffiValue); |
| |
| try { |
| if (!diplomatReceive.resultFlag) { |
| return null; |
| } |
| return new TimeZoneVariant(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); |
| } |
| |
| finally { |
| diplomatReceive.free(); |
| } |
| } |
| |
| constructor(timeZoneId, offset, zoneVariant) { |
| if (arguments[0] === diplomatRuntime.exposeConstructor) { |
| return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1)); |
| } else if (arguments[0] === diplomatRuntime.internalConstructor) { |
| return this.#internalConstructor(...arguments); |
| } else { |
| return this.#defaultConstructor(...arguments); |
| } |
| } |
| } |