// generated by diplomat-tool import { CalendarError } from "./CalendarError.mjs" import { CalendarParseError } from "./CalendarParseError.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; /** An ICU4X Time object representing a time in terms of hour, minute, second, nanosecond * *See the [Rust documentation for `Time`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html) for more information. */ const Time_box_destroy_registry = new FinalizationRegistry((ptr) => { wasm.icu4x_Time_destroy_mv1(ptr); }); export class Time { // 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 = []; constructor(symbol, ptr, selfEdge) { if (symbol !== diplomatRuntime.internalConstructor) { console.error("Time 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) { Time_box_destroy_registry.register(this, this.#ptr); } } get ffiValue() { return this.#ptr; } static create(hour, minute, second, nanosecond) { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.icu4x_Time_create_mv1(diplomatReceive.buffer, hour, minute, second, nanosecond); try { if (!diplomatReceive.resultFlag) { const cause = new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarError: ' + cause.value, { cause }); } return new Time(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } finally { diplomatReceive.free(); } } static fromString(v) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); const vSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.icu4x_Time_from_string_mv1(diplomatReceive.buffer, ...vSlice.splat()); try { if (!diplomatReceive.resultFlag) { const cause = new CalendarParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarParseError: ' + cause.value, { cause }); } return new Time(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } finally { functionCleanupArena.free(); diplomatReceive.free(); } } static midnight() { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.icu4x_Time_midnight_mv1(diplomatReceive.buffer); try { if (!diplomatReceive.resultFlag) { const cause = new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarError: ' + cause.value, { cause }); } return new Time(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } finally { diplomatReceive.free(); } } get hour() { const result = wasm.icu4x_Time_hour_mv1(this.ffiValue); try { return result; } finally {} } get minute() { const result = wasm.icu4x_Time_minute_mv1(this.ffiValue); try { return result; } finally {} } get second() { const result = wasm.icu4x_Time_second_mv1(this.ffiValue); try { return result; } finally {} } get nanosecond() { const result = wasm.icu4x_Time_nanosecond_mv1(this.ffiValue); try { return result; } finally {} } }