TimeZone.mjs (3750B)
1 // generated by diplomat-tool 2 import { TimeZoneInfo } from "./TimeZoneInfo.mjs" 3 import { UtcOffset } from "./UtcOffset.mjs" 4 import wasm from "./diplomat-wasm.mjs"; 5 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 6 7 8 /** 9 * See the [Rust documentation for `TimeZone`](https://docs.rs/icu/latest/icu/time/struct.TimeZone.html) for more information. 10 */ 11 const TimeZone_box_destroy_registry = new FinalizationRegistry((ptr) => { 12 wasm.icu4x_TimeZone_destroy_mv1(ptr); 13 }); 14 15 export class TimeZone { 16 // Internal ptr reference: 17 #ptr = null; 18 19 // Lifetimes are only to keep dependencies alive. 20 // Since JS won't garbage collect until there are no incoming edges. 21 #selfEdge = []; 22 23 #internalConstructor(symbol, ptr, selfEdge) { 24 if (symbol !== diplomatRuntime.internalConstructor) { 25 console.error("TimeZone is an Opaque type. You cannot call its constructor."); 26 return; 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 TimeZone_box_destroy_registry.register(this, this.#ptr); 34 } 35 36 return this; 37 } 38 get ffiValue() { 39 return this.#ptr; 40 } 41 42 43 /** 44 * The unknown time zone. 45 * 46 * See the [Rust documentation for `unknown`](https://docs.rs/icu/latest/icu/time/struct.TimeZoneInfo.html#method.unknown) for more information. 47 */ 48 static unknown() { 49 50 const result = wasm.icu4x_TimeZone_unknown_mv1(); 51 52 try { 53 return new TimeZone(diplomatRuntime.internalConstructor, result, []); 54 } 55 56 finally { 57 } 58 } 59 60 /** 61 * Whether the time zone is the unknown zone. 62 * 63 * See the [Rust documentation for `is_unknown`](https://docs.rs/icu/latest/icu/time/struct.TimeZone.html#method.is_unknown) for more information. 64 */ 65 isUnknown() { 66 67 const result = wasm.icu4x_TimeZone_is_unknown_mv1(this.ffiValue); 68 69 try { 70 return result; 71 } 72 73 finally { 74 } 75 } 76 77 /** 78 * Creates a time zone from a BCP-47 string. 79 * 80 * Returns the unknown time zone if the string is not a valid BCP-47 subtag. 81 * 82 * Additional information: [1](https://docs.rs/icu/latest/icu/time/struct.TimeZone.html) 83 */ 84 static createFromBcp47(id) { 85 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 86 87 const idSlice = diplomatRuntime.DiplomatBuf.str8(wasm, id); 88 89 const result = wasm.icu4x_TimeZone_create_from_bcp47_mv1(...idSlice.splat()); 90 91 try { 92 return new TimeZone(diplomatRuntime.internalConstructor, result, []); 93 } 94 95 finally { 96 functionCleanupArena.free(); 97 98 } 99 } 100 101 /** 102 * See the [Rust documentation for `with_offset`](https://docs.rs/icu/latest/icu/time/struct.TimeZone.html#method.with_offset) for more information. 103 */ 104 withOffset(offset) { 105 106 const result = wasm.icu4x_TimeZone_with_offset_mv1(this.ffiValue, offset.ffiValue); 107 108 try { 109 return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []); 110 } 111 112 finally { 113 } 114 } 115 116 /** 117 * See the [Rust documentation for `without_offset`](https://docs.rs/icu/latest/icu/time/struct.TimeZone.html#method.without_offset) for more information. 118 */ 119 withoutOffset() { 120 121 const result = wasm.icu4x_TimeZone_without_offset_mv1(this.ffiValue); 122 123 try { 124 return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []); 125 } 126 127 finally { 128 } 129 } 130 131 constructor(symbol, ptr, selfEdge) { 132 return this.#internalConstructor(...arguments) 133 } 134 }