• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { TimeZoneInfo } from "./TimeZoneInfo.mjs"
3import { UtcOffset } from "./UtcOffset.mjs"
4import wasm from "./diplomat-wasm.mjs";
5import * as diplomatRuntime from "./diplomat-runtime.mjs";
6
7
8/** See the [Rust documentation for `TimeZone`](https://docs.rs/icu/latest/icu/time/struct.TimeZone.html) for more information.
9*/
10const TimeZone_box_destroy_registry = new FinalizationRegistry((ptr) => {
11    wasm.icu4x_TimeZone_destroy_mv1(ptr);
12});
13
14export class TimeZone {
15
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
29        this.#ptr = ptr;
30        this.#selfEdge = selfEdge;
31
32        // Are we being borrowed? If not, we can register.
33        if (this.#selfEdge.length === 0) {
34            TimeZone_box_destroy_registry.register(this, this.#ptr);
35        }
36
37        return this;
38    }
39    get ffiValue() {
40        return this.#ptr;
41    }
42
43    static unknown() {
44        const result = wasm.icu4x_TimeZone_unknown_mv1();
45
46        try {
47            return new TimeZone(diplomatRuntime.internalConstructor, result, []);
48        }
49
50        finally {}
51    }
52
53    static createFromBcp47(id) {
54        let functionCleanupArena = new diplomatRuntime.CleanupArena();
55
56        const idSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, id));
57
58        const result = wasm.icu4x_TimeZone_create_from_bcp47_mv1(...idSlice.splat());
59
60        try {
61            return new TimeZone(diplomatRuntime.internalConstructor, result, []);
62        }
63
64        finally {
65            functionCleanupArena.free();
66        }
67    }
68
69    withOffset(offset) {
70        const result = wasm.icu4x_TimeZone_with_offset_mv1(this.ffiValue, offset.ffiValue);
71
72        try {
73            return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []);
74        }
75
76        finally {}
77    }
78
79    withoutOffset() {
80        const result = wasm.icu4x_TimeZone_without_offset_mv1(this.ffiValue);
81
82        try {
83            return new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []);
84        }
85
86        finally {}
87    }
88
89    constructor(symbol, ptr, selfEdge) {
90        return this.#internalConstructor(...arguments)
91    }
92}