TimeZoneVariant.mjs (2791B)
1 // generated by diplomat-tool 2 import wasm from "./diplomat-wasm.mjs"; 3 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 4 5 6 7 export class TimeZoneVariant { 8 #value = undefined; 9 10 static #values = new Map([ 11 ["Standard", 0], 12 ["Daylight", 1] 13 ]); 14 15 static getAllEntries() { 16 return TimeZoneVariant.#values.entries(); 17 } 18 19 #internalConstructor(value) { 20 if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { 21 // We pass in two internalConstructor arguments to create *new* 22 // instances of this type, otherwise the enums are treated as singletons. 23 if (arguments[1] === diplomatRuntime.internalConstructor ) { 24 this.#value = arguments[2]; 25 return this; 26 } 27 return TimeZoneVariant.#objectValues[arguments[1]]; 28 } 29 30 if (value instanceof TimeZoneVariant) { 31 return value; 32 } 33 34 let intVal = TimeZoneVariant.#values.get(value); 35 36 // Nullish check, checks for null or undefined 37 if (intVal != null) { 38 return TimeZoneVariant.#objectValues[intVal]; 39 } 40 41 throw TypeError(value + " is not a TimeZoneVariant and does not correspond to any of its enumerator values."); 42 } 43 44 static fromValue(value) { 45 return new TimeZoneVariant(value); 46 } 47 48 get value(){ 49 return [...TimeZoneVariant.#values.keys()][this.#value]; 50 } 51 52 get ffiValue(){ 53 return this.#value; 54 } 55 static #objectValues = [ 56 new TimeZoneVariant(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), 57 new TimeZoneVariant(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), 58 ]; 59 60 static Standard = TimeZoneVariant.#objectValues[0]; 61 static Daylight = TimeZoneVariant.#objectValues[1]; 62 63 64 /** 65 * Sets the `variant` field to "daylight" time. 66 * 67 * See the [Rust documentation for `from_rearguard_isdst`](https://docs.rs/icu/latest/icu/time/zone/enum.TimeZoneVariant.html#method.from_rearguard_isdst) for more information. 68 * 69 * See the [Rust documentation for `with_variant`](https://docs.rs/icu/latest/icu/time/struct.TimeZoneInfo.html#method.with_variant) for more information. 70 * 71 * Additional information: [1](https://docs.rs/icu/latest/icu/time/zone/enum.TimeZoneVariant.html) 72 */ 73 fromRearguardIsdst(isdst) { 74 75 const result = wasm.icu4x_TimeZoneVariant_from_rearguard_isdst_mv1(this.ffiValue, isdst); 76 77 try { 78 return new TimeZoneVariant(diplomatRuntime.internalConstructor, result); 79 } 80 81 finally { 82 } 83 } 84 85 constructor(value) { 86 return this.#internalConstructor(...arguments) 87 } 88 }