mmntjs-timezone 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/logic.cjs ADDED
@@ -0,0 +1,958 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/logic.ts
31
+ var logic_exports = {};
32
+ __export(logic_exports, {
33
+ default: () => logic_default,
34
+ tz: () => tz
35
+ });
36
+ module.exports = __toCommonJS(logic_exports);
37
+ var mmntjs = __toESM(require("mmntjs"), 1);
38
+
39
+ // src/install.ts
40
+ var offsetCache = /* @__PURE__ */ new Map();
41
+ var MAX_DOMAIN_CACHE_SIZE = 1e3;
42
+ var ABBR_LOCALES = [
43
+ "en-US",
44
+ "en-GB",
45
+ "ja-JP",
46
+ "en-AU",
47
+ "en-SG",
48
+ "en-HK",
49
+ "af-ZA",
50
+ "es-AR",
51
+ "pt-BR",
52
+ "ko-KR",
53
+ "en-IN",
54
+ "zh-CN"
55
+ ];
56
+ var ZONE_ALIAS = {
57
+ "Asia/Calcutta": "Asia/Kolkata"
58
+ };
59
+ function normalizeName(name) {
60
+ return name.toLowerCase().replace(/\//g, "_");
61
+ }
62
+ function normalizeTz(tz2) {
63
+ const u = tz2.toUpperCase();
64
+ if (u === "UTC" || u === "GMT") {
65
+ return u;
66
+ }
67
+ return ZONE_ALIAS[tz2] ?? tz2;
68
+ }
69
+ function charCodeToInt(charCode) {
70
+ if (charCode > 96) {
71
+ return charCode - 87;
72
+ }
73
+ if (charCode > 64) {
74
+ return charCode - 29;
75
+ }
76
+ return charCode - 48;
77
+ }
78
+ function unpackBase60(input) {
79
+ let i = 0;
80
+ const parts = input.split(".");
81
+ const whole = parts[0] ?? "";
82
+ const fractional = parts[1] ?? "";
83
+ let multiplier = 1;
84
+ let out = 0;
85
+ let sign = 1;
86
+ if (input.charCodeAt(0) === 45) {
87
+ i = 1;
88
+ sign = -1;
89
+ }
90
+ for (; i < whole.length; i++) {
91
+ out = 60 * out + charCodeToInt(whole.charCodeAt(i));
92
+ }
93
+ for (i = 0; i < fractional.length; i++) {
94
+ multiplier /= 60;
95
+ out += charCodeToInt(fractional.charCodeAt(i)) * multiplier;
96
+ }
97
+ return out * sign;
98
+ }
99
+ function arrayToInt(values) {
100
+ return values.map((value) => unpackBase60(value));
101
+ }
102
+ function mapIndices(source, indices) {
103
+ const out = new Array(indices.length);
104
+ for (let i = 0; i < indices.length; i++) {
105
+ out[i] = source[indices[i]];
106
+ }
107
+ return out;
108
+ }
109
+ function decodeIndicesCodec(encoded) {
110
+ if (encoded[0] !== "!") {
111
+ return arrayToInt(encoded.split(""));
112
+ }
113
+ const indices = [];
114
+ let pos = 1;
115
+ const len = encoded.length;
116
+ while (pos < len) {
117
+ const ch = encoded[pos];
118
+ if (ch === "^" && pos + 4 <= len) {
119
+ const a = charCodeToInt(encoded.charCodeAt(pos + 1));
120
+ const b = charCodeToInt(encoded.charCodeAt(pos + 2));
121
+ const count = charCodeToInt(encoded.charCodeAt(pos + 3)) + 1;
122
+ for (let i = 0; i < count; i++) {
123
+ indices.push(a, b);
124
+ }
125
+ pos += 4;
126
+ } else if (ch === "~" && pos + 3 <= len) {
127
+ const a = charCodeToInt(encoded.charCodeAt(pos + 1));
128
+ const count = charCodeToInt(encoded.charCodeAt(pos + 2)) + 1;
129
+ for (let i = 0; i < count; i++) {
130
+ indices.push(a);
131
+ }
132
+ pos += 3;
133
+ } else if (ch === "@" && pos + 3 <= len) {
134
+ const start = charCodeToInt(encoded.charCodeAt(pos + 1));
135
+ const count = charCodeToInt(encoded.charCodeAt(pos + 2)) + 1;
136
+ const abbrCount = 62;
137
+ for (let i = 0; i < count; i++) {
138
+ indices.push((start + i) % abbrCount);
139
+ }
140
+ pos += 3;
141
+ } else {
142
+ indices.push(charCodeToInt(encoded.charCodeAt(pos)));
143
+ pos++;
144
+ }
145
+ }
146
+ return indices;
147
+ }
148
+ function parseDeltas(raw) {
149
+ const tokens = raw.split(" ");
150
+ if (_deltaDict.length > 0 && tokens.length > 0) {
151
+ return tokens.map((t) => {
152
+ if (t === "") return 0;
153
+ return _deltaDict[unpackBase60(t)] ?? 0;
154
+ });
155
+ }
156
+ return arrayToInt(tokens);
157
+ }
158
+ function unpack(packed) {
159
+ const data = packed.split("|");
160
+ const offsets = arrayToInt((data[2] ?? "").split(" "));
161
+ const indices = decodeIndicesCodec(data[3] ?? "");
162
+ const untils = parseDeltas(data[4] ?? "");
163
+ for (let i = 0; i < indices.length; i++) {
164
+ untils[i] = Math.round((untils[i - 1] || 0) + untils[i] * 6e4);
165
+ }
166
+ untils[indices.length - 1] = Number.POSITIVE_INFINITY;
167
+ return {
168
+ name: data[0] ?? "",
169
+ abbrs: mapIndices((data[1] ?? "").split(" "), indices),
170
+ offsets: mapIndices(offsets, indices),
171
+ untils,
172
+ population: Number(data[5] ?? 0) | 0
173
+ };
174
+ }
175
+ function closest(num, arr) {
176
+ const len = arr.length;
177
+ if (len === 0) {
178
+ return -1;
179
+ }
180
+ if (num < arr[0]) {
181
+ return 0;
182
+ }
183
+ if (len > 1 && arr[len - 1] === Number.POSITIVE_INFINITY && num >= (arr[len - 2] ?? 0)) {
184
+ return len - 1;
185
+ }
186
+ if (num >= (arr[len - 1] ?? 0)) {
187
+ return -1;
188
+ }
189
+ let lo = 0;
190
+ let hi = len - 1;
191
+ while (hi - lo > 1) {
192
+ const mid = Math.floor((lo + hi) / 2);
193
+ if ((arr[mid] ?? 0) <= num) {
194
+ lo = mid;
195
+ } else {
196
+ hi = mid;
197
+ }
198
+ }
199
+ return hi;
200
+ }
201
+ var InternalZone = class {
202
+ constructor(name, canonicalKey) {
203
+ this.lastIndex = -1;
204
+ this.lastStart = Number.NEGATIVE_INFINITY;
205
+ this.lastEnd = Number.POSITIVE_INFINITY;
206
+ this.name = name;
207
+ this.canonicalKey = canonicalKey;
208
+ }
209
+ _index(timestamp) {
210
+ const target = +timestamp;
211
+ if (this.lastIndex >= 0 && target >= this.lastStart && target < this.lastEnd) {
212
+ return this.lastIndex;
213
+ }
214
+ const untils = getDecodedZonePayload(this.canonicalKey).untils;
215
+ const idx = closest(target, untils);
216
+ if (idx >= 0) {
217
+ this.lastIndex = idx;
218
+ this.lastStart = idx > 0 ? untils[idx - 1] ?? Number.NEGATIVE_INFINITY : Number.NEGATIVE_INFINITY;
219
+ this.lastEnd = untils[idx] ?? Number.POSITIVE_INFINITY;
220
+ }
221
+ return idx;
222
+ }
223
+ countries() {
224
+ const out = [];
225
+ for (const [code, country] of Object.entries(countryStore)) {
226
+ if (country.zones.includes(this.name)) {
227
+ out.push(code);
228
+ }
229
+ }
230
+ return out;
231
+ }
232
+ parse(timestamp) {
233
+ const payload = getDecodedZonePayload(this.canonicalKey);
234
+ const target = +timestamp;
235
+ const max = payload.untils.length - 1;
236
+ for (let i = 0; i < max; i++) {
237
+ let offset = payload.offsets[i] ?? 0;
238
+ const offsetNext = payload.offsets[i + 1] ?? offset;
239
+ const offsetPrev = payload.offsets[i ? i - 1 : i] ?? offset;
240
+ if (offset < offsetNext && timezoneFlags.moveAmbiguousForward) {
241
+ offset = offsetNext;
242
+ } else if (offset > offsetPrev && timezoneFlags.moveInvalidForward) {
243
+ offset = offsetPrev;
244
+ }
245
+ if (target < (payload.untils[i] ?? Number.POSITIVE_INFINITY) - offset * 6e4) {
246
+ return payload.offsets[i] ?? 0;
247
+ }
248
+ }
249
+ return payload.offsets[max] ?? 0;
250
+ }
251
+ abbr(ts) {
252
+ const idx = this._index(ts);
253
+ const payload = getDecodedZonePayload(this.canonicalKey);
254
+ return idx >= 0 ? payload.abbrs[idx] ?? "" : "";
255
+ }
256
+ offset(ts) {
257
+ return this.utcOffset(ts);
258
+ }
259
+ utcOffset(ts) {
260
+ const idx = this._index(ts);
261
+ const payload = getDecodedZonePayload(this.canonicalKey);
262
+ return idx >= 0 ? payload.offsets[idx] ?? 0 : 0;
263
+ }
264
+ };
265
+ var CompatZone = class {
266
+ constructor(packedString) {
267
+ this.li = -1;
268
+ this.ls = Number.NEGATIVE_INFINITY;
269
+ this.le = Number.POSITIVE_INFINITY;
270
+ const u = unpack(packedString ?? "||0|0||0");
271
+ this.name = u.name;
272
+ this.p = createDecodedZonePayload(u);
273
+ }
274
+ _i(ts) {
275
+ const t = +ts;
276
+ if (this.li >= 0 && t >= this.ls && t < this.le) {
277
+ return this.li;
278
+ }
279
+ const idx = closest(t, this.p.untils);
280
+ if (idx >= 0) {
281
+ this.li = idx;
282
+ this.ls = idx > 0 ? this.p.untils[idx - 1] : Number.NEGATIVE_INFINITY;
283
+ this.le = this.p.untils[idx];
284
+ }
285
+ return idx;
286
+ }
287
+ countries() {
288
+ return [];
289
+ }
290
+ abbr(ts) {
291
+ const i = this._i(ts);
292
+ return i >= 0 ? this.p.abbrs[i] : "";
293
+ }
294
+ offset(ts) {
295
+ return this.utcOffset(ts);
296
+ }
297
+ utcOffset(ts) {
298
+ const i = this._i(ts);
299
+ return i >= 0 ? this.p.offsets[i] : 0;
300
+ }
301
+ parse(ts) {
302
+ const target = +ts;
303
+ const max = this.p.untils.length - 1;
304
+ for (let i = 0; i < max; i++) {
305
+ let off = this.p.offsets[i];
306
+ const nxt = this.p.offsets[i + 1] ?? off;
307
+ const prv = this.p.offsets[i ? i - 1 : i] ?? off;
308
+ if (off < nxt && timezoneFlags.moveAmbiguousForward) {
309
+ off = nxt;
310
+ } else if (off > prv && timezoneFlags.moveInvalidForward) {
311
+ off = prv;
312
+ }
313
+ if (target < this.p.untils[i] - off * 6e4) {
314
+ return this.p.offsets[i];
315
+ }
316
+ }
317
+ return this.p.offsets[max];
318
+ }
319
+ };
320
+ var _deltaDict = [];
321
+ var zoneStore = /* @__PURE__ */ Object.create(
322
+ null
323
+ );
324
+ var linkStore = /* @__PURE__ */ Object.create(null);
325
+ var nameStore = /* @__PURE__ */ Object.create(null);
326
+ var countryStore = /* @__PURE__ */ Object.create(
327
+ null
328
+ );
329
+ var zoneWrapperCache = /* @__PURE__ */ new Map();
330
+ var decodedZonePayloadCache = /* @__PURE__ */ new Map();
331
+ var abbrInternPool = /* @__PURE__ */ new Map();
332
+ var timezoneFlags = {
333
+ moveInvalidForward: true,
334
+ moveAmbiguousForward: false
335
+ };
336
+ var builtinZoneDataLoaded = false;
337
+ var indexBuilt = false;
338
+ var sortedZoneNamesCache = null;
339
+ var _zonesBlob = "";
340
+ var _linksBlob = "";
341
+ var _countriesBlob = "";
342
+ var _nameTable = [];
343
+ var _zoneIdx = /* @__PURE__ */ new Map();
344
+ var _linkIdx = /* @__PURE__ */ new Map();
345
+ var _linkNameIdx = /* @__PURE__ */ new Map();
346
+ var _countryIdx = /* @__PURE__ */ new Map();
347
+ function internString(value) {
348
+ const cached = abbrInternPool.get(value);
349
+ if (cached) {
350
+ return cached;
351
+ }
352
+ abbrInternPool.set(value, value);
353
+ return value;
354
+ }
355
+ function createDecodedZonePayload(unpacked) {
356
+ const offsets = unpacked.offsets.some((value) => value > 32767 || value < -32768) ? Int32Array.from(unpacked.offsets) : Int16Array.from(unpacked.offsets);
357
+ return {
358
+ abbrs: unpacked.abbrs.map((abbr) => internString(abbr)),
359
+ offsets,
360
+ untils: Float64Array.from(unpacked.untils),
361
+ population: unpacked.population
362
+ };
363
+ }
364
+ function getDecodedZonePayload(canonicalKey) {
365
+ const cached = decodedZonePayloadCache.get(canonicalKey);
366
+ if (cached) {
367
+ return cached;
368
+ }
369
+ const source = zoneStore[canonicalKey];
370
+ if (!source) {
371
+ throw new Error(`Missing timezone payload for ${canonicalKey}`);
372
+ }
373
+ let payload;
374
+ if (typeof source === "string") {
375
+ payload = createDecodedZonePayload(unpack(source));
376
+ } else if ("ut" in source) {
377
+ const prebuilt = source;
378
+ const untils = [prebuilt.ut];
379
+ for (let i = 0; i < prebuilt.ud.length; i++) {
380
+ untils.push(untils[i] + prebuilt.ud[i]);
381
+ }
382
+ untils[untils.length - 1] = Number.POSITIVE_INFINITY;
383
+ payload = createDecodedZonePayload({
384
+ name: "",
385
+ abbrs: prebuilt.abbrs,
386
+ offsets: prebuilt.offsets,
387
+ untils,
388
+ population: prebuilt.pop
389
+ });
390
+ } else {
391
+ payload = source;
392
+ }
393
+ zoneStore[canonicalKey] = payload;
394
+ decodedZonePayloadCache.set(canonicalKey, payload);
395
+ return payload;
396
+ }
397
+ function addPackedZoneEntry(name, value) {
398
+ const normalized = normalizeName(name);
399
+ zoneStore[normalized] = value;
400
+ nameStore[normalized] = name;
401
+ zoneWrapperCache.delete(name);
402
+ decodedZonePayloadCache.delete(normalized);
403
+ sortedZoneNamesCache = null;
404
+ }
405
+ function addZone(packed) {
406
+ if (typeof packed === "string") {
407
+ const split = packed.split("|");
408
+ addPackedZoneEntry(split[0] ?? "", packed);
409
+ return;
410
+ }
411
+ if (Array.isArray(packed)) {
412
+ for (const item of packed) {
413
+ addZone(item);
414
+ }
415
+ return;
416
+ }
417
+ if (packed && typeof packed === "object") {
418
+ for (const [name, value] of Object.entries(packed)) {
419
+ if (typeof value === "string") {
420
+ addZone(value);
421
+ continue;
422
+ }
423
+ if (value && typeof value === "object") {
424
+ if ("ut" in value) {
425
+ addPackedZoneEntry(name, value);
426
+ } else {
427
+ const entry = value;
428
+ addPackedZoneEntry(
429
+ name,
430
+ createDecodedZonePayload({
431
+ name,
432
+ abbrs: [...entry.abbrs ?? []],
433
+ offsets: [...entry.offsets ?? []],
434
+ untils: [...entry.untils ?? []],
435
+ population: entry.population ?? 0
436
+ })
437
+ );
438
+ }
439
+ }
440
+ }
441
+ }
442
+ }
443
+ function addLink(links) {
444
+ const linkList = [];
445
+ if (typeof links === "string") {
446
+ linkList.push(links);
447
+ } else if (Array.isArray(links)) {
448
+ for (const entry of links) {
449
+ if (typeof entry === "string") {
450
+ linkList.push(entry);
451
+ }
452
+ }
453
+ } else if (links && typeof links === "object") {
454
+ for (const [alias, target] of Object.entries(links)) {
455
+ if (typeof target === "string") {
456
+ linkList.push(`${alias}|${target}`);
457
+ }
458
+ }
459
+ }
460
+ for (const aliasEntry of linkList) {
461
+ const alias = aliasEntry.split("|");
462
+ const name0 = alias[0];
463
+ const name1 = alias[1];
464
+ if (!name0 || !name1) {
465
+ continue;
466
+ }
467
+ const normal0 = normalizeName(name0);
468
+ const normal1 = normalizeName(name1);
469
+ linkStore[normal0] = normal1;
470
+ nameStore[normal0] = name0;
471
+ linkStore[normal1] = normal0;
472
+ nameStore[normal1] = name1;
473
+ sortedZoneNamesCache = null;
474
+ }
475
+ }
476
+ function addCountries(data) {
477
+ if (Array.isArray(data)) {
478
+ for (const item of data) {
479
+ if (typeof item !== "string") {
480
+ continue;
481
+ }
482
+ const split = item.split("|");
483
+ const code = (split[0] ?? "").toUpperCase();
484
+ const zones = (split[1] ?? "").split(" ").filter(Boolean);
485
+ if (code) {
486
+ countryStore[code] = { name: code, zones };
487
+ }
488
+ }
489
+ return;
490
+ }
491
+ if (data && typeof data === "object") {
492
+ for (const [codeKey, value] of Object.entries(data)) {
493
+ const code = codeKey.toUpperCase();
494
+ if (Array.isArray(value)) {
495
+ countryStore[code] = {
496
+ name: code,
497
+ zones: value.filter((v) => typeof v === "string")
498
+ };
499
+ continue;
500
+ }
501
+ if (value && typeof value === "object") {
502
+ const zones = value.zones;
503
+ if (Array.isArray(zones)) {
504
+ countryStore[code] = {
505
+ name: code,
506
+ zones: zones.filter((v) => typeof v === "string")
507
+ };
508
+ }
509
+ }
510
+ }
511
+ }
512
+ }
513
+ function getZoneRecord(name, caller) {
514
+ ensureIndexBuilt();
515
+ const normalized = normalizeName(normalizeTz(name));
516
+ const cached = zoneWrapperCache.get(name);
517
+ if (cached instanceof InternalZone) return cached;
518
+ if (normalized in zoneStore || materializeZone(normalized)) {
519
+ const r = new InternalZone(nameStore[normalized] ?? name, normalized);
520
+ zoneWrapperCache.set(name, r);
521
+ return r;
522
+ }
523
+ const linkTarget = resolveLink(normalized);
524
+ if (linkTarget && caller !== getZoneRecord) {
525
+ const target = getZoneRecord(linkTarget, getZoneRecord);
526
+ if (target) {
527
+ const alias = new InternalZone(nameStore[normalized] ?? name, normalizeName(target.name));
528
+ zoneWrapperCache.set(name, alias);
529
+ return alias;
530
+ }
531
+ }
532
+ return null;
533
+ }
534
+ function getZone(name) {
535
+ return getZoneRecord(name);
536
+ }
537
+ function getAbbr(tz2, ts) {
538
+ if (tz2 === "UTC") {
539
+ return "UTC";
540
+ }
541
+ if (tz2 === "GMT") {
542
+ return "GMT";
543
+ }
544
+ const d = new Date(ts);
545
+ for (const loc of ABBR_LOCALES) {
546
+ try {
547
+ const full = d.toLocaleString(loc, { timeZone: tz2, timeZoneName: "short" });
548
+ const m = full.match(/\s(\S+)$/);
549
+ if (m) {
550
+ const abbr = m[1] ?? "";
551
+ if (/^[A-Z]{2,5}$/.test(abbr) && abbr !== "Time") {
552
+ return abbr;
553
+ }
554
+ }
555
+ } catch {
556
+ }
557
+ }
558
+ const offset = getOffset(tz2, ts);
559
+ const abs = Math.abs(offset);
560
+ const hrs = Math.floor(abs / 60);
561
+ const min = abs % 60;
562
+ const sign = offset >= 0 ? "+" : "-";
563
+ return `${sign}${String(hrs).padStart(2, "0")}${min ? String(min).padStart(2, "0") : "00"}`;
564
+ }
565
+ function getOffset(tz2, timestamp) {
566
+ tz2 = normalizeTz(tz2);
567
+ let domain = offsetCache.get(tz2);
568
+ if (!domain) {
569
+ domain = /* @__PURE__ */ new Map();
570
+ offsetCache.set(tz2, domain);
571
+ }
572
+ const cached = domain.get(timestamp);
573
+ if (cached !== void 0) {
574
+ return cached;
575
+ }
576
+ if (domain.size >= MAX_DOMAIN_CACHE_SIZE) {
577
+ const first = domain.keys().next().value;
578
+ if (first !== void 0) {
579
+ domain.delete(first);
580
+ }
581
+ }
582
+ const d = new Date(timestamp);
583
+ const parts = d.toLocaleString("en-US", {
584
+ timeZone: tz2,
585
+ timeZoneName: "longOffset"
586
+ });
587
+ const m = parts.match(/GMT([+-]\d{1,2})(?::(\d{2}))?/);
588
+ let offset = 0;
589
+ if (m) {
590
+ const hrs = parseInt(m[1] ?? "0", 10);
591
+ const min = m[2] ? parseInt(m[2], 10) : 0;
592
+ const s = hrs >= 0 ? 1 : -1;
593
+ offset = hrs * 60 + s * min;
594
+ }
595
+ domain.set(timestamp, offset);
596
+ return offset;
597
+ }
598
+ function hasExplicitOffset(input) {
599
+ return /(Z|[+-]\d{2}:?\d{2})\s*$/.test(input.trim());
600
+ }
601
+ function getNames() {
602
+ ensureIndexBuilt();
603
+ if (sortedZoneNamesCache) return [...sortedZoneNamesCache];
604
+ const out = /* @__PURE__ */ new Set();
605
+ for (const [, entry] of _zoneIdx) out.add(entry.name);
606
+ for (const [, name] of _linkNameIdx) out.add(name);
607
+ for (const key of Object.keys(nameStore)) {
608
+ if (nameStore[key] && (zoneStore[key] || resolveLink(key))) out.add(nameStore[key]);
609
+ }
610
+ for (const name of Object.keys(ZONE_ALIAS)) {
611
+ out.add(name);
612
+ out.add(ZONE_ALIAS[name]);
613
+ }
614
+ sortedZoneNamesCache = [...out].sort();
615
+ return [...sortedZoneNamesCache];
616
+ }
617
+ function getCountryNames() {
618
+ ensureIndexBuilt();
619
+ const out = /* @__PURE__ */ new Set([..._countryIdx.keys()]);
620
+ for (const key of Object.keys(countryStore)) out.add(key);
621
+ return [...out].sort();
622
+ }
623
+ function zonesForCountry(code, withOffset) {
624
+ var _a;
625
+ ensureIndexBuilt();
626
+ const upper = code.toUpperCase();
627
+ let zones = ((_a = countryStore[upper]) == null ? void 0 : _a.zones) ?? _countryIdx.get(upper);
628
+ if (!zones) return null;
629
+ const sorted = [...zones].sort();
630
+ if (withOffset) {
631
+ const now = Date.now();
632
+ return sorted.map((name) => {
633
+ const z = getZone(name);
634
+ return z ? { name, offset: z.utcOffset(now) } : null;
635
+ }).filter((e) => e !== null);
636
+ }
637
+ return sorted;
638
+ }
639
+ function isZoneName(s) {
640
+ const u = s.toUpperCase();
641
+ if (u === "UTC" || u === "GMT") return true;
642
+ ensureIndexBuilt();
643
+ const n = normalizeName(normalizeTz(s));
644
+ return n in zoneStore || _zoneIdx.has(n) || !!resolveLink(n);
645
+ }
646
+ function ensureIndexBuilt() {
647
+ if (indexBuilt || !builtinZoneDataLoaded) return;
648
+ indexBuilt = true;
649
+ const nt = _nameTable;
650
+ let pos = 0;
651
+ if (_zonesBlob.charCodeAt(0) === 33 && _zonesBlob.charCodeAt(1) === 68 && _zonesBlob.charCodeAt(2) === 124) {
652
+ const nl = _zonesBlob.indexOf("\n", 0);
653
+ if (nl >= 0) {
654
+ const header = _zonesBlob.slice(0, nl);
655
+ const dp = header.split("|");
656
+ if (dp[0] === "!D") {
657
+ _deltaDict = (dp[1] ?? "").split(" ").filter(Boolean).map(unpackBase60);
658
+ }
659
+ pos = nl + 1;
660
+ }
661
+ }
662
+ while (pos < _zonesBlob.length) {
663
+ const start = pos;
664
+ const nl = _zonesBlob.indexOf("\n", pos);
665
+ const end = nl >= 0 ? nl : _zonesBlob.length;
666
+ pos = nl >= 0 ? nl + 1 : _zonesBlob.length;
667
+ if (start === end) continue;
668
+ const pipe = _zonesBlob.indexOf("|", start);
669
+ if (pipe < 0 || pipe >= end) continue;
670
+ const idStr = _zonesBlob.slice(start, pipe);
671
+ const id = charCodeToInt(idStr.charCodeAt(0)) * 60 + charCodeToInt(idStr.charCodeAt(1));
672
+ const name = nt[id] ?? "";
673
+ if (name) _zoneIdx.set(normalizeName(name), { name, start, end });
674
+ }
675
+ pos = 0;
676
+ while (pos < _linksBlob.length) {
677
+ const nl = _linksBlob.indexOf("\n", pos);
678
+ const line = nl >= 0 ? _linksBlob.slice(pos, nl) : _linksBlob.slice(pos);
679
+ pos = nl >= 0 ? nl + 1 : _linksBlob.length;
680
+ if (!line) continue;
681
+ const pipe = line.indexOf("|");
682
+ if (pipe < 0) continue;
683
+ const fromId = line.slice(0, pipe), toId = line.slice(pipe + 1);
684
+ if (fromId && toId) {
685
+ const fi = charCodeToInt(fromId.charCodeAt(0)) * 60 + charCodeToInt(fromId.charCodeAt(1));
686
+ const ti = charCodeToInt(toId.charCodeAt(0)) * 60 + charCodeToInt(toId.charCodeAt(1));
687
+ const from = nt[fi] ?? "", to = nt[ti] ?? "";
688
+ if (from && to) {
689
+ const nf = normalizeName(from), ntNorm = normalizeName(to);
690
+ _linkIdx.set(nf, ntNorm);
691
+ _linkIdx.set(ntNorm, nf);
692
+ _linkNameIdx.set(nf, from);
693
+ _linkNameIdx.set(ntNorm, to);
694
+ }
695
+ }
696
+ }
697
+ pos = 0;
698
+ while (pos < _countriesBlob.length) {
699
+ const nl = _countriesBlob.indexOf("\n", pos);
700
+ const line = nl >= 0 ? _countriesBlob.slice(pos, nl) : _countriesBlob.slice(pos);
701
+ pos = nl >= 0 ? nl + 1 : _countriesBlob.length;
702
+ if (!line) continue;
703
+ const pipe = line.indexOf("|");
704
+ if (pipe < 0) continue;
705
+ const code = line.slice(0, pipe).toUpperCase();
706
+ const zones = line.slice(pipe + 1).split(" ").filter(Boolean).map((idStr) => nt[parseInt(idStr, 10)] ?? "").filter(Boolean);
707
+ if (code && zones.length > 0) _countryIdx.set(code, zones);
708
+ }
709
+ }
710
+ function materializeZone(normalized) {
711
+ const entry = _zoneIdx.get(normalized);
712
+ if (!entry) return false;
713
+ if (normalized in zoneStore) return true;
714
+ const line = _zonesBlob.slice(entry.start, entry.end);
715
+ const pipe = line.indexOf("|");
716
+ addPackedZoneEntry(entry.name, entry.name + line.slice(pipe));
717
+ getDecodedZonePayload(normalized);
718
+ return true;
719
+ }
720
+ function resolveLink(normalized) {
721
+ return linkStore[normalized] ?? _linkIdx.get(normalized);
722
+ }
723
+ function loadData(data) {
724
+ addZone(data.zones);
725
+ addLink(data.links);
726
+ addCountries(data.countries);
727
+ }
728
+ function ensureBuiltinZoneData(moment2, data) {
729
+ if (builtinZoneDataLoaded || !data) {
730
+ return;
731
+ }
732
+ _zonesBlob = data.zonesBlob;
733
+ _linksBlob = data.linksBlob;
734
+ _countriesBlob = data.countriesBlob;
735
+ if (data.namesBlob) _nameTable = data.namesBlob.split("\n");
736
+ if (moment2 == null ? void 0 : moment2.tz) {
737
+ moment2.tz.dataVersion = data.version;
738
+ if (data.tzVersion) {
739
+ moment2.tz.version = data.tzVersion;
740
+ }
741
+ }
742
+ builtinZoneDataLoaded = true;
743
+ }
744
+ function installTimezone(moment2, data) {
745
+ if (moment2.tz) {
746
+ return moment2;
747
+ }
748
+ ensureBuiltinZoneData(moment2, data);
749
+ moment2.momentProperties.push("_z");
750
+ function parseInZone(input, zone, format) {
751
+ const parsed = format ? moment2.utc(input, format) : moment2.utc(input);
752
+ if (!parsed.isValid()) {
753
+ return parsed;
754
+ }
755
+ const y = parsed.year(), M = parsed.month(), d = parsed.date();
756
+ const h = parsed.hour(), min = parsed.minute(), s = parsed.second(), ms = parsed.millisecond();
757
+ const zoneInfo = getZone(zone);
758
+ if (zoneInfo instanceof InternalZone) {
759
+ const base = Date.UTC(y, M, d, h, min, s, ms);
760
+ const offset = zoneInfo.parse(base);
761
+ const result2 = moment2(base + offset * 6e4);
762
+ const ro = zoneInfo.utcOffset(result2.valueOf());
763
+ result2.utcOffset(ro ? -ro : 0, false);
764
+ result2._z = zoneInfo;
765
+ return result2;
766
+ }
767
+ const guess = Date.UTC(y, M, d, h, min, s, ms);
768
+ const offsets = new Set(
769
+ [guess, Date.UTC(y, M, d), Date.UTC(y, M, d, 12), Date.UTC(y, M, d - 1, 12)].map(
770
+ (r) => getOffset(zone, r)
771
+ )
772
+ );
773
+ for (const o of [...offsets]) {
774
+ offsets.add(o + 30);
775
+ offsets.add(o - 30);
776
+ }
777
+ const sorted = [...offsets].sort((a, b) => b - a);
778
+ let bestTs = guess, bestOff = sorted[0] ?? 0, found = false;
779
+ for (const off of sorted) {
780
+ const ct = guess - off * 6e4;
781
+ if (getOffset(zone, ct) !== off) {
782
+ continue;
783
+ }
784
+ try {
785
+ const wp = new Date(ct).toLocaleString("en-US", {
786
+ timeZone: zone,
787
+ hour12: false,
788
+ hour: "2-digit",
789
+ minute: "2-digit",
790
+ second: "2-digit"
791
+ });
792
+ const p = wp.match(/^(\d{2}):(\d{2}):(\d{2})$/);
793
+ if (p && +p[1] === h && +p[2] === min && +p[3] === s) {
794
+ bestTs = ct;
795
+ bestOff = off;
796
+ found = true;
797
+ break;
798
+ }
799
+ } catch {
800
+ }
801
+ }
802
+ if (!found) {
803
+ const offA = getOffset(zone, guess);
804
+ const offB = getOffset(zone, guess - offA * 6e4);
805
+ bestOff = Math.max(offA, offB);
806
+ bestTs = guess + Math.abs(offB - offA) * 6e4 - bestOff * 6e4;
807
+ }
808
+ const result = moment2(bestTs);
809
+ result.utcOffset(bestOff, false);
810
+ result._z = zoneInfo ?? {
811
+ name: zone,
812
+ abbr: (t) => getAbbr(zone, t),
813
+ offset: () => -bestOff,
814
+ utcOffset: () => -bestOff,
815
+ parse: () => -bestOff
816
+ };
817
+ return result;
818
+ }
819
+ function momentTz(input, foz, zos, fourth) {
820
+ if (typeof foz === "string") {
821
+ if (isZoneName(foz)) {
822
+ const tz2 = normalizeTz(foz);
823
+ if (input == null) {
824
+ return moment2().tz(tz2);
825
+ }
826
+ if (typeof input === "string" && !hasExplicitOffset(input)) {
827
+ return parseInZone(input, tz2);
828
+ }
829
+ return moment2(input).tz(tz2);
830
+ }
831
+ if (typeof input === "string") {
832
+ if (typeof zos === "string" && isZoneName(zos)) {
833
+ return parseInZone(input, normalizeTz(zos), foz);
834
+ }
835
+ if (typeof zos === "boolean" && typeof fourth === "string" && isZoneName(fourth)) {
836
+ return parseInZone(input, normalizeTz(fourth), foz);
837
+ }
838
+ return moment2(input, foz);
839
+ }
840
+ }
841
+ if (typeof input === "string") {
842
+ return moment2().tz(input);
843
+ }
844
+ return input != null ? moment2(input) : moment2();
845
+ }
846
+ function fnTz(tz2, keepTime) {
847
+ if (tz2 === void 0) {
848
+ return this._z ? this._z.name : Intl.DateTimeFormat().resolvedOptions().timeZone;
849
+ }
850
+ const zi = getZone(normalizeTz(tz2));
851
+ if (!zi) {
852
+ return this.clone();
853
+ }
854
+ const m = this.clone();
855
+ m._z = zi;
856
+ const to = -zi.utcOffset(m.valueOf());
857
+ m.utcOffset(to ? to : 0, keepTime);
858
+ return m;
859
+ }
860
+ moment2.tz = momentTz;
861
+ moment2.fn.tz = fnTz;
862
+ moment2.defaultZone = null;
863
+ moment2.tz.version = (data == null ? void 0 : data.tzVersion) || "0.6.2";
864
+ moment2.tz.dataVersion = (data == null ? void 0 : data.version) || "";
865
+ moment2.tz.Zone = CompatZone;
866
+ moment2.tz._zones = zoneStore;
867
+ moment2.tz._links = linkStore;
868
+ moment2.tz._names = nameStore;
869
+ moment2.tz._countries = countryStore;
870
+ moment2.tz.unpack = unpack;
871
+ moment2.tz.unpackBase60 = unpackBase60;
872
+ moment2.tz.load = function(bundle) {
873
+ loadData(bundle);
874
+ moment2.tz.dataVersion = bundle.version ?? "";
875
+ };
876
+ moment2.tz.add = function(zoneData) {
877
+ addZone(zoneData);
878
+ };
879
+ moment2.tz.link = function(links) {
880
+ addLink(links);
881
+ };
882
+ moment2.tz.zone = function(name) {
883
+ return getZone(name);
884
+ };
885
+ moment2.tz.zoneExists = function(name) {
886
+ return !!getZone(name);
887
+ };
888
+ moment2.tz.guess = function(_preferCache) {
889
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
890
+ };
891
+ moment2.tz.names = function() {
892
+ return getNames();
893
+ };
894
+ moment2.tz.countries = function() {
895
+ return getCountryNames();
896
+ };
897
+ moment2.tz.zonesForCountry = function(code, withOffset) {
898
+ return zonesForCountry(code, withOffset);
899
+ };
900
+ moment2.tz.setDefault = function(tz2) {
901
+ moment2.defaultZone = tz2 ? normalizeTz(tz2) : void 0;
902
+ return moment2;
903
+ };
904
+ Object.defineProperty(moment2.tz, "moveInvalidForward", {
905
+ get() {
906
+ return timezoneFlags.moveInvalidForward;
907
+ },
908
+ set(value) {
909
+ timezoneFlags.moveInvalidForward = !!value;
910
+ },
911
+ enumerable: true,
912
+ configurable: true
913
+ });
914
+ Object.defineProperty(moment2.tz, "moveAmbiguousForward", {
915
+ get() {
916
+ return timezoneFlags.moveAmbiguousForward;
917
+ },
918
+ set(value) {
919
+ timezoneFlags.moveAmbiguousForward = !!value;
920
+ },
921
+ enumerable: true,
922
+ configurable: true
923
+ });
924
+ const _zn = moment2.fn.zoneName;
925
+ const _za = moment2.fn.zoneAbbr;
926
+ moment2.fn.isDST = function() {
927
+ const z = this._z;
928
+ if (!z) {
929
+ return false;
930
+ }
931
+ const ts = this.valueOf();
932
+ const y = new Date(ts).getUTCFullYear();
933
+ const jan = Date.UTC(y, 0, 1);
934
+ const jul = Date.UTC(y, 6, 1);
935
+ if (z instanceof InternalZone) {
936
+ return z.utcOffset(ts) !== Math.max(z.utcOffset(jan), z.utcOffset(jul));
937
+ }
938
+ return getOffset(z.name, ts) !== Math.min(getOffset(z.name, jan), getOffset(z.name, jul));
939
+ };
940
+ moment2.fn.zoneName = function() {
941
+ return this._z ? this._z.abbr(this.valueOf()) : _zn ? _zn.call(this) : "";
942
+ };
943
+ moment2.fn.zoneAbbr = function() {
944
+ return this._z ? this._z.abbr(this.valueOf()) : _za ? _za.call(this) : "";
945
+ };
946
+ return moment2;
947
+ }
948
+
949
+ // src/logic.ts
950
+ var momentFactory = mmntjs.moment ?? mmntjs.default ?? mmntjs;
951
+ installTimezone(momentFactory);
952
+ var logic_default = momentFactory;
953
+ var tz = momentFactory.tz;
954
+ // Annotate the CommonJS export names for ESM import in node:
955
+ 0 && (module.exports = {
956
+ tz
957
+ });
958
+ //# sourceMappingURL=logic.cjs.map