blob: 98c1143057057a130e7ae1006344757da8815509 [file] [log] [blame]
// generated by diplomat-tool
import { TimeZoneInvalidOffsetError } from "./TimeZoneInvalidOffsetError.mjs"
import wasm from "./diplomat-wasm.mjs";
import * as diplomatRuntime from "./diplomat-runtime.mjs";
/** See the [Rust documentation for `UtcOffset`](https://docs.rs/icu/latest/icu/time/zone/struct.UtcOffset.html) for more information.
*/
const UtcOffset_box_destroy_registry = new FinalizationRegistry((ptr) => {
wasm.icu4x_UtcOffset_destroy_mv1(ptr);
});
export class UtcOffset {
// 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("UtcOffset 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) {
UtcOffset_box_destroy_registry.register(this, this.#ptr);
}
return this;
}
get ffiValue() {
return this.#ptr;
}
static fromSeconds(seconds) {
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
const result = wasm.icu4x_UtcOffset_from_seconds_mv1(diplomatReceive.buffer, seconds);
try {
if (!diplomatReceive.resultFlag) {
const cause = TimeZoneInvalidOffsetError.fromFields({}, diplomatRuntime.internalConstructor);
throw new globalThis.Error('TimeZoneInvalidOffsetError', { cause });
}
return new UtcOffset(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
}
finally {
diplomatReceive.free();
}
}
static fromEighthsOfHour(eighthsOfHour) {
const result = wasm.icu4x_UtcOffset_from_eighths_of_hour_mv1(eighthsOfHour);
try {
return new UtcOffset(diplomatRuntime.internalConstructor, result, []);
}
finally {}
}
static fromString(offset) {
let functionCleanupArena = new diplomatRuntime.CleanupArena();
const offsetSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, offset));
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
const result = wasm.icu4x_UtcOffset_from_string_mv1(diplomatReceive.buffer, ...offsetSlice.splat());
try {
if (!diplomatReceive.resultFlag) {
const cause = TimeZoneInvalidOffsetError.fromFields({}, diplomatRuntime.internalConstructor);
throw new globalThis.Error('TimeZoneInvalidOffsetError', { cause });
}
return new UtcOffset(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
}
finally {
functionCleanupArena.free();
diplomatReceive.free();
}
}
get eighthsOfHour() {
const result = wasm.icu4x_UtcOffset_eighths_of_hour_mv1(this.ffiValue);
try {
return result;
}
finally {}
}
get seconds() {
const result = wasm.icu4x_UtcOffset_seconds_mv1(this.ffiValue);
try {
return result;
}
finally {}
}
get isNonNegative() {
const result = wasm.icu4x_UtcOffset_is_non_negative_mv1(this.ffiValue);
try {
return result;
}
finally {}
}
get isZero() {
const result = wasm.icu4x_UtcOffset_is_zero_mv1(this.ffiValue);
try {
return result;
}
finally {}
}
get hoursPart() {
const result = wasm.icu4x_UtcOffset_hours_part_mv1(this.ffiValue);
try {
return result;
}
finally {}
}
get minutesPart() {
const result = wasm.icu4x_UtcOffset_minutes_part_mv1(this.ffiValue);
try {
return result;
}
finally {}
}
get secondsPart() {
const result = wasm.icu4x_UtcOffset_seconds_part_mv1(this.ffiValue);
try {
return result;
}
finally {}
}
constructor(symbol, ptr, selfEdge) {
return this.#internalConstructor(...arguments)
}
}