blob: d8d707c48a08dcf4a414f662cf1350d8cd171c2c [file] [log] [blame]
// generated by diplomat-tool
import { TimeZoneInfo } from "./TimeZoneInfo.mjs"
import { UtcOffset } from "./UtcOffset.mjs"
import wasm from "./diplomat-wasm.mjs";
import * as diplomatRuntime from "./diplomat-runtime.mjs";
/** See the [Rust documentation for `TimeZone`](https://docs.rs/icu/latest/icu/time/struct.TimeZone.html) for more information.
*/
const TimeZone_box_destroy_registry = new FinalizationRegistry((ptr) => {
wasm.icu4x_TimeZone_destroy_mv1(ptr);
});
export class TimeZone {
// 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("TimeZone 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) {
TimeZone_box_destroy_registry.register(this, this.#ptr);
}
return this;
}
get ffiValue() {
return this.#ptr;
}
static unknown() {
const result = wasm.icu4x_TimeZone_unknown_mv1();
try {
return new TimeZone(diplomatRuntime.internalConstructor, result, []);
}
finally {}
}
static createFromBcp47(id) {
let functionCleanupArena = new diplomatRuntime.CleanupArena();
const idSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, id));
const result = wasm.icu4x_TimeZone_create_from_bcp47_mv1(...idSlice.splat());
try {
return new TimeZone(diplomatRuntime.internalConstructor, result, []);
}
finally {
functionCleanupArena.free();
}
}
withOffset(offset) {
const result = wasm.icu4x_TimeZone_with_offset_mv1(this.ffiValue, offset.ffiValue);
try {
return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []);
}
finally {}
}
withoutOffset() {
const result = wasm.icu4x_TimeZone_without_offset_mv1(this.ffiValue);
try {
return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []);
}
finally {}
}
constructor(symbol, ptr, selfEdge) {
return this.#internalConstructor(...arguments)
}
}