// 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 { VariantOffsetsCalculator } from "./VariantOffsetsCalculator.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; const TimeZoneInfo_box_destroy_registry = new FinalizationRegistry((ptr) => { wasm.icu4x_TimeZoneInfo_destroy_mv1(ptr); }); /** * See the [Rust documentation for `TimeZoneInfo`](https://docs.rs/icu/2.1.1/icu/time/struct.TimeZoneInfo.html) for more information. */ 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; } /** @internal */ get ffiValue() { return this.#ptr; } /** * Creates a time zone for UTC (Coordinated Universal Time). * * See the [Rust documentation for `utc`](https://docs.rs/icu/2.1.1/icu/time/struct.TimeZoneInfo.html#method.utc) for more information. */ static utc() { const result = wasm.icu4x_TimeZoneInfo_utc_mv1(); try { return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []); } finally { } } /** * Creates a time zone info from parts. * * `variant` is ignored. */ #defaultConstructor(id, offset, variant) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); const result = wasm.icu4x_TimeZoneInfo_from_parts_mv1(id.ffiValue, offset.ffiValue ?? 0, diplomatRuntime.optionToBufferForCalling(wasm, variant, 4, 4, functionCleanupArena, (arrayBuffer, offset, jsValue) => [diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)])); try { return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []); } finally { functionCleanupArena.free(); } } /** * See the [Rust documentation for `id`](https://docs.rs/icu/2.1.1/icu/time/struct.TimeZoneInfo.html#method.id) for more information. */ get id() { const result = wasm.icu4x_TimeZoneInfo_id_mv1(this.ffiValue); try { return new TimeZone(diplomatRuntime.internalConstructor, result, []); } finally { } } /** * Sets the datetime at which to interpret the time zone * for display name lookup. * * Notes: * * - If not set, the formatting datetime is used if possible. * - If the offset is not set, the datetime is interpreted as UTC. * - The constraints are the same as with `ZoneNameTimestamp` in Rust. * - Set to year 1000 or 9999 for a reference far in the past or future. * * See the [Rust documentation for `at_date_time_iso`](https://docs.rs/icu/2.1.1/icu/time/struct.TimeZoneInfo.html#method.at_date_time_iso) for more information. * * Additional information: [1](https://docs.rs/icu/2.1.1/icu/time/zone/struct.ZoneNameTimestamp.html) */ atDateTimeIso(date, time) { const result = wasm.icu4x_TimeZoneInfo_at_date_time_iso_mv1(this.ffiValue, date.ffiValue, time.ffiValue); try { return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []); } finally { } } /** * Sets the timestamp, in milliseconds since Unix epoch, at which to interpret the time zone * for display name lookup. * * Notes: * * - If not set, the formatting datetime is used if possible. * - The constraints are the same as with `ZoneNameTimestamp` in Rust. * * See the [Rust documentation for `with_zone_name_timestamp`](https://docs.rs/icu/2.1.1/icu/time/struct.TimeZoneInfo.html#method.with_zone_name_timestamp) for more information. * * Additional information: [1](https://docs.rs/icu/2.1.1/icu/time/zone/struct.ZoneNameTimestamp.html#method.from_zoned_date_time_iso), [2](https://docs.rs/icu/2.1.1/icu/time/zone/struct.ZoneNameTimestamp.html) */ atTimestamp(timestamp) { const result = wasm.icu4x_TimeZoneInfo_at_timestamp_mv1(this.ffiValue, timestamp); try { return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []); } finally { } } /** * Returns the DateTime for the UTC zone name reference time * * See the [Rust documentation for `zone_name_timestamp`](https://docs.rs/icu/2.1.1/icu/time/struct.TimeZoneInfo.html#method.zone_name_timestamp) for more information. */ get zoneNameDateTime() { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true); const result = wasm.icu4x_TimeZoneInfo_zone_name_date_time_mv1(diplomatReceive.buffer, this.ffiValue); try { if (!diplomatReceive.resultFlag) { return null; } return IsoDateTime._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer); } finally { diplomatReceive.free(); } } /** * See the [Rust documentation for `with_variant`](https://docs.rs/icu/2.1.1/icu/time/struct.TimeZoneInfo.html#method.with_variant) for more information. * * @deprecated returns unmodified copy */ withVariant(timeVariant) { const result = wasm.icu4x_TimeZoneInfo_with_variant_mv1(this.ffiValue, timeVariant.ffiValue); try { return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []); } finally { } } /** * See the [Rust documentation for `offset`](https://docs.rs/icu/2.1.1/icu/time/struct.TimeZoneInfo.html#method.offset) for more information. */ get offset() { const result = wasm.icu4x_TimeZoneInfo_offset_mv1(this.ffiValue); try { return result === 0 ? null : new UtcOffset(diplomatRuntime.internalConstructor, result, []); } finally { } } /** * See the [Rust documentation for `infer_variant`](https://docs.rs/icu/2.1.1/icu/time/struct.TimeZoneInfo.html#method.infer_variant) for more information. * * Additional information: [1](https://docs.rs/icu/2.1.1/icu/time/zone/enum.TimeZoneVariant.html) * * @deprecated does nothing */ inferVariant(offsetCalculator) { const result = wasm.icu4x_TimeZoneInfo_infer_variant_mv1(this.ffiValue, offsetCalculator.ffiValue); try { return result === 1; } finally { } } /** * See the [Rust documentation for `variant`](https://docs.rs/icu/2.1.1/icu/time/struct.TimeZoneInfo.html#method.variant) for more information. * * @deprecated always returns null */ variant() { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.icu4x_TimeZoneInfo_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(); } } /** * Creates a time zone info from parts. * * `variant` is ignored. */ constructor(id, offset, variant) { 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); } } }