1// generated by diplomat-tool 2import { DataError } from "./DataError.mjs" 3import { DataProvider } from "./DataProvider.mjs" 4import { IsoDate } from "./IsoDate.mjs" 5import { Time } from "./Time.mjs" 6import { TimeZone } from "./TimeZone.mjs" 7import { UtcOffsets } from "./UtcOffsets.mjs" 8import wasm from "./diplomat-wasm.mjs"; 9import * as diplomatRuntime from "./diplomat-runtime.mjs"; 10 11 12/** See the [Rust documentation for `UtcOffsetCalculator`](https://docs.rs/icu/latest/icu/time/zone/struct.UtcOffsetCalculator.html) for more information. 13*/ 14const UtcOffsetCalculator_box_destroy_registry = new FinalizationRegistry((ptr) => { 15 wasm.icu4x_UtcOffsetCalculator_destroy_mv1(ptr); 16}); 17 18export class UtcOffsetCalculator { 19 20 // Internal ptr reference: 21 #ptr = null; 22 23 // Lifetimes are only to keep dependencies alive. 24 // Since JS won't garbage collect until there are no incoming edges. 25 #selfEdge = []; 26 27 #internalConstructor(symbol, ptr, selfEdge) { 28 if (symbol !== diplomatRuntime.internalConstructor) { 29 console.error("UtcOffsetCalculator is an Opaque type. You cannot call its constructor."); 30 return; 31 } 32 33 this.#ptr = ptr; 34 this.#selfEdge = selfEdge; 35 36 // Are we being borrowed? If not, we can register. 37 if (this.#selfEdge.length === 0) { 38 UtcOffsetCalculator_box_destroy_registry.register(this, this.#ptr); 39 } 40 41 return this; 42 } 43 get ffiValue() { 44 return this.#ptr; 45 } 46 47 #defaultConstructor() { 48 const result = wasm.icu4x_UtcOffsetCalculator_create_mv1(); 49 50 try { 51 return new UtcOffsetCalculator(diplomatRuntime.internalConstructor, result, []); 52 } 53 54 finally {} 55 } 56 57 static createWithProvider(provider) { 58 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 59 60 const result = wasm.icu4x_UtcOffsetCalculator_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); 61 62 try { 63 if (!diplomatReceive.resultFlag) { 64 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 65 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 66 } 67 return new UtcOffsetCalculator(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 68 } 69 70 finally { 71 diplomatReceive.free(); 72 } 73 } 74 75 computeOffsetsFromTimeZone(timeZone, localDate, localTime) { 76 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true); 77 78 const result = wasm.icu4x_UtcOffsetCalculator_compute_offsets_from_time_zone_mv1(diplomatReceive.buffer, this.ffiValue, timeZone.ffiValue, localDate.ffiValue, localTime.ffiValue); 79 80 try { 81 if (!diplomatReceive.resultFlag) { 82 return null; 83 } 84 return UtcOffsets._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer); 85 } 86 87 finally { 88 diplomatReceive.free(); 89 } 90 } 91 92 constructor() { 93 if (arguments[0] === diplomatRuntime.exposeConstructor) { 94 return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1)); 95 } else if (arguments[0] === diplomatRuntime.internalConstructor) { 96 return this.#internalConstructor(...arguments); 97 } else { 98 return this.#defaultConstructor(...arguments); 99 } 100 } 101}