1// generated by diplomat-tool 2import { TimeZoneInvalidOffsetError } from "./TimeZoneInvalidOffsetError.mjs" 3import wasm from "./diplomat-wasm.mjs"; 4import * as diplomatRuntime from "./diplomat-runtime.mjs"; 5 6 7/** See the [Rust documentation for `UtcOffset`](https://docs.rs/icu/latest/icu/time/zone/struct.UtcOffset.html) for more information. 8*/ 9const UtcOffset_box_destroy_registry = new FinalizationRegistry((ptr) => { 10 wasm.icu4x_UtcOffset_destroy_mv1(ptr); 11}); 12 13export class UtcOffset { 14 15 // Internal ptr reference: 16 #ptr = null; 17 18 // Lifetimes are only to keep dependencies alive. 19 // Since JS won't garbage collect until there are no incoming edges. 20 #selfEdge = []; 21 22 #internalConstructor(symbol, ptr, selfEdge) { 23 if (symbol !== diplomatRuntime.internalConstructor) { 24 console.error("UtcOffset is an Opaque type. You cannot call its constructor."); 25 return; 26 } 27 28 this.#ptr = ptr; 29 this.#selfEdge = selfEdge; 30 31 // Are we being borrowed? If not, we can register. 32 if (this.#selfEdge.length === 0) { 33 UtcOffset_box_destroy_registry.register(this, this.#ptr); 34 } 35 36 return this; 37 } 38 get ffiValue() { 39 return this.#ptr; 40 } 41 42 static fromSeconds(seconds) { 43 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 44 45 const result = wasm.icu4x_UtcOffset_from_seconds_mv1(diplomatReceive.buffer, seconds); 46 47 try { 48 if (!diplomatReceive.resultFlag) { 49 const cause = TimeZoneInvalidOffsetError.fromFields({}, diplomatRuntime.internalConstructor); 50 throw new globalThis.Error('TimeZoneInvalidOffsetError', { cause }); 51 } 52 return new UtcOffset(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 53 } 54 55 finally { 56 diplomatReceive.free(); 57 } 58 } 59 60 static fromEighthsOfHour(eighthsOfHour) { 61 const result = wasm.icu4x_UtcOffset_from_eighths_of_hour_mv1(eighthsOfHour); 62 63 try { 64 return new UtcOffset(diplomatRuntime.internalConstructor, result, []); 65 } 66 67 finally {} 68 } 69 70 static fromString(offset) { 71 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 72 73 const offsetSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, offset)); 74 75 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 76 77 const result = wasm.icu4x_UtcOffset_from_string_mv1(diplomatReceive.buffer, ...offsetSlice.splat()); 78 79 try { 80 if (!diplomatReceive.resultFlag) { 81 const cause = TimeZoneInvalidOffsetError.fromFields({}, diplomatRuntime.internalConstructor); 82 throw new globalThis.Error('TimeZoneInvalidOffsetError', { cause }); 83 } 84 return new UtcOffset(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 85 } 86 87 finally { 88 functionCleanupArena.free(); 89 90 diplomatReceive.free(); 91 } 92 } 93 94 get eighthsOfHour() { 95 const result = wasm.icu4x_UtcOffset_eighths_of_hour_mv1(this.ffiValue); 96 97 try { 98 return result; 99 } 100 101 finally {} 102 } 103 104 get seconds() { 105 const result = wasm.icu4x_UtcOffset_seconds_mv1(this.ffiValue); 106 107 try { 108 return result; 109 } 110 111 finally {} 112 } 113 114 get isNonNegative() { 115 const result = wasm.icu4x_UtcOffset_is_non_negative_mv1(this.ffiValue); 116 117 try { 118 return result; 119 } 120 121 finally {} 122 } 123 124 get isZero() { 125 const result = wasm.icu4x_UtcOffset_is_zero_mv1(this.ffiValue); 126 127 try { 128 return result; 129 } 130 131 finally {} 132 } 133 134 get hoursPart() { 135 const result = wasm.icu4x_UtcOffset_hours_part_mv1(this.ffiValue); 136 137 try { 138 return result; 139 } 140 141 finally {} 142 } 143 144 get minutesPart() { 145 const result = wasm.icu4x_UtcOffset_minutes_part_mv1(this.ffiValue); 146 147 try { 148 return result; 149 } 150 151 finally {} 152 } 153 154 get secondsPart() { 155 const result = wasm.icu4x_UtcOffset_seconds_part_mv1(this.ffiValue); 156 157 try { 158 return result; 159 } 160 161 finally {} 162 } 163 164 constructor(symbol, ptr, selfEdge) { 165 return this.#internalConstructor(...arguments) 166 } 167}