tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TimeZoneInfo.mjs (6867B)


      1 // generated by diplomat-tool
      2 import { IsoDate } from "./IsoDate.mjs"
      3 import { IsoDateTime } from "./IsoDateTime.mjs"
      4 import { Time } from "./Time.mjs"
      5 import { TimeZone } from "./TimeZone.mjs"
      6 import { TimeZoneVariant } from "./TimeZoneVariant.mjs"
      7 import { UtcOffset } from "./UtcOffset.mjs"
      8 import { VariantOffsetsCalculator } from "./VariantOffsetsCalculator.mjs"
      9 import wasm from "./diplomat-wasm.mjs";
     10 import * as diplomatRuntime from "./diplomat-runtime.mjs";
     11 
     12 
     13 /**
     14 * See the [Rust documentation for `TimeZoneInfo`](https://docs.rs/icu/latest/icu/time/struct.TimeZoneInfo.html) for more information.
     15 */
     16 const TimeZoneInfo_box_destroy_registry = new FinalizationRegistry((ptr) => {
     17    wasm.icu4x_TimeZoneInfo_destroy_mv1(ptr);
     18 });
     19 
     20 export class TimeZoneInfo {
     21    // Internal ptr reference:
     22    #ptr = null;
     23 
     24    // Lifetimes are only to keep dependencies alive.
     25    // Since JS won't garbage collect until there are no incoming edges.
     26    #selfEdge = [];
     27 
     28    #internalConstructor(symbol, ptr, selfEdge) {
     29        if (symbol !== diplomatRuntime.internalConstructor) {
     30            console.error("TimeZoneInfo is an Opaque type. You cannot call its constructor.");
     31            return;
     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            TimeZoneInfo_box_destroy_registry.register(this, this.#ptr);
     39        }
     40 
     41        return this;
     42    }
     43    get ffiValue() {
     44        return this.#ptr;
     45    }
     46 
     47 
     48    /**
     49     * Creates a time zone for UTC (Coordinated Universal Time).
     50     *
     51     * See the [Rust documentation for `utc`](https://docs.rs/icu/latest/icu/time/struct.TimeZoneInfo.html#method.utc) for more information.
     52     */
     53    static utc() {
     54 
     55        const result = wasm.icu4x_TimeZoneInfo_utc_mv1();
     56 
     57        try {
     58            return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []);
     59        }
     60 
     61        finally {
     62        }
     63    }
     64 
     65    /**
     66     * Creates a time zone info from parts.
     67     */
     68    #defaultConstructor(id, offset, variant) {
     69        let functionCleanupArena = new diplomatRuntime.CleanupArena();
     70 
     71 
     72        const result = wasm.icu4x_TimeZoneInfo_from_parts_mv1(id.ffiValue, offset.ffiValue ?? 0, ...diplomatRuntime.optionToArgsForCalling(variant, 4, 4, (arrayBuffer, offset, jsValue) => [diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)]));
     73 
     74        try {
     75            return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []);
     76        }
     77 
     78        finally {
     79            functionCleanupArena.free();
     80 
     81        }
     82    }
     83 
     84    /**
     85     * See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/time/struct.TimeZoneInfo.html#method.id) for more information.
     86     */
     87    id() {
     88 
     89        const result = wasm.icu4x_TimeZoneInfo_id_mv1(this.ffiValue);
     90 
     91        try {
     92            return new TimeZone(diplomatRuntime.internalConstructor, result, []);
     93        }
     94 
     95        finally {
     96        }
     97    }
     98 
     99    /**
    100     * Sets the datetime at which to interpret the time zone
    101     * for display name lookup.
    102     *
    103     * Notes:
    104     *
    105     * - If not set, the formatting datetime is used if possible.
    106     * - The constraints are the same as with `ZoneNameTimestamp` in Rust.
    107     * - Set to year 1000 or 9999 for a reference far in the past or future.
    108     *
    109     * See the [Rust documentation for `at_date_time_iso`](https://docs.rs/icu/latest/icu/time/struct.TimeZoneInfo.html#method.at_date_time_iso) for more information.
    110     *
    111     * Additional information: [1](https://docs.rs/icu/latest/icu/time/zone/struct.ZoneNameTimestamp.html)
    112     */
    113    atDateTimeIso(date, time) {
    114 
    115        const result = wasm.icu4x_TimeZoneInfo_at_date_time_iso_mv1(this.ffiValue, date.ffiValue, time.ffiValue);
    116 
    117        try {
    118            return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []);
    119        }
    120 
    121        finally {
    122        }
    123    }
    124 
    125    /**
    126     * See the [Rust documentation for `zone_name_timestamp`](https://docs.rs/icu/latest/icu/time/struct.TimeZoneInfo.html#method.zone_name_timestamp) for more information.
    127     */
    128    zoneNameDateTime() {
    129        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);
    130 
    131 
    132        const result = wasm.icu4x_TimeZoneInfo_zone_name_date_time_mv1(diplomatReceive.buffer, this.ffiValue);
    133 
    134        try {
    135            if (!diplomatReceive.resultFlag) {
    136                return null;
    137            }
    138            return IsoDateTime._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer);
    139        }
    140 
    141        finally {
    142            diplomatReceive.free();
    143        }
    144    }
    145 
    146    /**
    147     * See the [Rust documentation for `with_variant`](https://docs.rs/icu/latest/icu/time/struct.TimeZoneInfo.html#method.with_variant) for more information.
    148     */
    149    withVariant(timeVariant) {
    150 
    151        const result = wasm.icu4x_TimeZoneInfo_with_variant_mv1(this.ffiValue, timeVariant.ffiValue);
    152 
    153        try {
    154            return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []);
    155        }
    156 
    157        finally {
    158        }
    159    }
    160 
    161    /**
    162     * Infers the zone variant.
    163     *
    164     * Requires the offset and local time to be set.
    165     *
    166     * See the [Rust documentation for `infer_variant`](https://docs.rs/icu/latest/icu/time/struct.TimeZoneInfo.html#method.infer_variant) for more information.
    167     *
    168     * Additional information: [1](https://docs.rs/icu/latest/icu/time/zone/enum.TimeZoneVariant.html)
    169     */
    170    inferVariant(offsetCalculator) {
    171 
    172        const result = wasm.icu4x_TimeZoneInfo_infer_variant_mv1(this.ffiValue, offsetCalculator.ffiValue);
    173 
    174        try {
    175            return result === 1;
    176        }
    177 
    178        finally {
    179        }
    180    }
    181 
    182    /**
    183     * See the [Rust documentation for `variant`](https://docs.rs/icu/latest/icu/time/struct.TimeZoneInfo.html#method.variant) for more information.
    184     */
    185    variant() {
    186        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    187 
    188 
    189        const result = wasm.icu4x_TimeZoneInfo_variant_mv1(diplomatReceive.buffer, this.ffiValue);
    190 
    191        try {
    192            if (!diplomatReceive.resultFlag) {
    193                return null;
    194            }
    195            return new TimeZoneVariant(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    196        }
    197 
    198        finally {
    199            diplomatReceive.free();
    200        }
    201    }
    202 
    203    constructor(id, offset, variant) {
    204        if (arguments[0] === diplomatRuntime.exposeConstructor) {
    205            return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1));
    206        } else if (arguments[0] === diplomatRuntime.internalConstructor) {
    207            return this.#internalConstructor(...arguments);
    208        } else {
    209            return this.#defaultConstructor(...arguments);
    210        }
    211    }
    212 }