@tempo-kit/plugin-holidays 0.0.0-stage → 2.0.0-rc.0

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/index.js ADDED
@@ -0,0 +1,1058 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+
19
+ // auto-inject-version:tempo-kit/plugin/sdk
20
+ var sdk_exports = {};
21
+ __export(sdk_exports, {
22
+ definePlugin: () => definePlugin,
23
+ defineTerm: () => defineTerm
24
+ });
25
+ __reExport(sdk_exports, sdk_star);
26
+ import * as sdk_star from "tempo-kit/plugin/sdk";
27
+ import { definePlugin as originalPlugin, defineTerm as originalTerm } from "tempo-kit/plugin/sdk";
28
+ var definePlugin = (config) => originalPlugin({ ...config, version: "2.0.0-rc.0" });
29
+ var defineTerm = (config) => originalTerm({ ...config, version: "2.0.0-rc.0" });
30
+
31
+ // src/engine.ts
32
+ import { isString as isString2, getCountryFromTimeZone, getLC } from "tempo-kit/library";
33
+
34
+ // src/registry.ts
35
+ import { isString } from "tempo-kit/library";
36
+
37
+ // src/cache.ts
38
+ var memoryStore = /* @__PURE__ */ new Map();
39
+ function getStorage(key) {
40
+ const entry = memoryStore.get(key);
41
+ if (!entry) return void 0;
42
+ if (Date.now() > entry.expiresAt) {
43
+ memoryStore.delete(key);
44
+ return void 0;
45
+ }
46
+ return entry.value;
47
+ }
48
+ function setStorage(key, value, options) {
49
+ const ttl = options?.ttl ?? 24 * 60 * 60 * 1e3;
50
+ memoryStore.set(key, {
51
+ value,
52
+ expiresAt: Date.now() + ttl
53
+ });
54
+ }
55
+
56
+ // src/computus.ts
57
+ import { WeakCache } from "tempo-kit/library";
58
+ import { getDaysInMonth, civilToDays, isoWeekdayFromDays, epochMsFromParts, partsFromEpochMs } from "tempo-kit/library";
59
+ var EASTER_CACHE = new WeakCache();
60
+ function formatDate(year, month, day) {
61
+ const mm = String(month).padStart(2, "0");
62
+ const dd = String(day).padStart(2, "0");
63
+ return `${year}-${mm}-${dd}`;
64
+ }
65
+ function getIsoDayOfWeek(year, month, day) {
66
+ const days = civilToDays(year, month, day);
67
+ return isoWeekdayFromDays(days);
68
+ }
69
+ function offsetDate(year, month, day, daysOffset) {
70
+ const baseMs = epochMsFromParts(year, month, day);
71
+ const targetMs = baseMs + daysOffset * 864e5;
72
+ const { year: y, month: m, day: d } = partsFromEpochMs(targetMs);
73
+ return formatDate(y, m, d);
74
+ }
75
+ function getEasterSunday(year) {
76
+ const cached = EASTER_CACHE.get(year);
77
+ if (cached) return cached;
78
+ const a = year % 19;
79
+ const b = Math.floor(year / 100);
80
+ const c = year % 100;
81
+ const d = Math.floor(b / 4);
82
+ const e = b % 4;
83
+ const f = Math.floor((b + 8) / 25);
84
+ const g = Math.floor((b - f + 1) / 3);
85
+ const h = (19 * a + b - d - g + 15) % 30;
86
+ const i = Math.floor(c / 4);
87
+ const k = c % 4;
88
+ const l = (32 + 2 * e + 2 * i - h - k) % 7;
89
+ const m = Math.floor((a + 11 * h + 22 * l) / 451);
90
+ const month = Math.floor((h + l - 7 * m + 114) / 31);
91
+ const day = (h + l - 7 * m + 114) % 31 + 1;
92
+ const result = { year, month, day, dateStr: formatDate(year, month, day) };
93
+ EASTER_CACHE.set(year, result);
94
+ return result;
95
+ }
96
+ function getGoodFriday(year) {
97
+ const { month, day } = getEasterSunday(year);
98
+ return offsetDate(year, month, day, -2);
99
+ }
100
+ function getEasterSaturday(year) {
101
+ const { month, day } = getEasterSunday(year);
102
+ return offsetDate(year, month, day, -1);
103
+ }
104
+ function getEasterMonday(year) {
105
+ const { month, day } = getEasterSunday(year);
106
+ return offsetDate(year, month, day, 1);
107
+ }
108
+ function getAscensionDay(year) {
109
+ const { month, day } = getEasterSunday(year);
110
+ return offsetDate(year, month, day, 39);
111
+ }
112
+ function getWhitMonday(year) {
113
+ const { month, day } = getEasterSunday(year);
114
+ return offsetDate(year, month, day, 50);
115
+ }
116
+ function getCorpusChristi(year) {
117
+ const { month, day } = getEasterSunday(year);
118
+ return offsetDate(year, month, day, 60);
119
+ }
120
+ function getNthWeekdayOfMonth(year, month, weekday, n) {
121
+ const daysInMonth2 = getDaysInMonth(year, month);
122
+ if (n === -1) {
123
+ for (let d = daysInMonth2; d >= 1; d--) {
124
+ if (isoWeekdayFromDays(civilToDays(year, month, d)) === weekday) {
125
+ return formatDate(year, month, d);
126
+ }
127
+ }
128
+ throw new Error(`Unable to find last weekday ${weekday} in ${year}-${month}`);
129
+ }
130
+ let count = 0;
131
+ for (let d = 1; d <= daysInMonth2; d++) {
132
+ if (isoWeekdayFromDays(civilToDays(year, month, d)) === weekday) {
133
+ count++;
134
+ if (count === n) return formatDate(year, month, d);
135
+ }
136
+ }
137
+ throw new Error(`Unable to find ${n}th weekday ${weekday} in ${year}-${month}`);
138
+ }
139
+
140
+ // src/calendars/us.ts
141
+ function getUsObservedDate(year, month, day) {
142
+ const dow = getIsoDayOfWeek(year, month, day);
143
+ if (dow === 6) {
144
+ return offsetDate(year, month, day, -1);
145
+ }
146
+ if (dow === 7) {
147
+ return offsetDate(year, month, day, 1);
148
+ }
149
+ return null;
150
+ }
151
+ var generateUsHolidays = (year, region, includeObserved = true) => {
152
+ const holidays = [];
153
+ const country = "US";
154
+ const reg = region ? region.toUpperCase().replace(/^US-/, "") : void 0;
155
+ const addHoliday = (date, name, isObserved = false, holidayRegion) => {
156
+ holidays.push({ date, name, country, region: holidayRegion, isObserved });
157
+ };
158
+ const addFixedWithObservation = (month, day, name, holidayRegion) => {
159
+ const baseDate = formatDate(year, month, day);
160
+ addHoliday(baseDate, name, false, holidayRegion);
161
+ if (includeObserved) {
162
+ const observed = getUsObservedDate(year, month, day);
163
+ if (observed)
164
+ addHoliday(observed, `${name} (Observed)`, true, holidayRegion);
165
+ }
166
+ };
167
+ addHoliday(formatDate(year, 1, 1), "New Year's Day");
168
+ if (includeObserved) {
169
+ const nyObserved = getUsObservedDate(year, 1, 1);
170
+ if (nyObserved && nyObserved.startsWith(`${year}-`))
171
+ addHoliday(nyObserved, "New Year's Day (Observed)", true);
172
+ if (getIsoDayOfWeek(year + 1, 1, 1) === 6)
173
+ addHoliday(formatDate(year, 12, 31), "New Year's Day (Observed)", true);
174
+ }
175
+ addHoliday(getNthWeekdayOfMonth(year, 1, 1, 3), "Martin Luther King Jr. Day");
176
+ addHoliday(getNthWeekdayOfMonth(year, 2, 1, 3), "Washington's Birthday");
177
+ addHoliday(getNthWeekdayOfMonth(year, 5, 1, -1), "Memorial Day");
178
+ if (year >= 2021)
179
+ addFixedWithObservation(6, 19, "Juneteenth National Independence Day");
180
+ addFixedWithObservation(7, 4, "Independence Day");
181
+ addHoliday(getNthWeekdayOfMonth(year, 9, 1, 1), "Labor Day");
182
+ addHoliday(getNthWeekdayOfMonth(year, 10, 1, 2), "Columbus Day");
183
+ addFixedWithObservation(11, 11, "Veterans Day");
184
+ const thanksgiving = getNthWeekdayOfMonth(year, 11, 4, 4);
185
+ addHoliday(thanksgiving, "Thanksgiving Day");
186
+ const tgParts = thanksgiving.split("-").map(Number);
187
+ const dayAfterThanksgiving = offsetDate(tgParts[0], tgParts[1], tgParts[2], 1);
188
+ if (reg && ["CA", "DE", "FL", "IA", "IL", "KS", "KY", "ME", "MI", "MN", "NE", "NV", "NH", "NC", "OK", "PA", "SC", "TN", "TX", "VA", "WV"].includes(reg))
189
+ addHoliday(dayAfterThanksgiving, "Day After Thanksgiving", false, reg);
190
+ addFixedWithObservation(12, 25, "Christmas Day");
191
+ return holidays.sort((a, b) => a.date.localeCompare(b.date));
192
+ };
193
+
194
+ // src/calendars/au.ts
195
+ var generateAuHolidays = (year, region, includeObserved = true) => {
196
+ const holidays = [];
197
+ const country = "AU";
198
+ const reg = region ? region.toUpperCase().replace(/^AU-/, "") : void 0;
199
+ const addHoliday = (date, name, isObserved = false, holidayRegion) => {
200
+ if (!holidayRegion || !reg || holidayRegion === reg) {
201
+ holidays.push({ date, name, country, region: holidayRegion, isObserved });
202
+ }
203
+ };
204
+ const nyDow = getIsoDayOfWeek(year, 1, 1);
205
+ addHoliday(formatDate(year, 1, 1), "New Year's Day");
206
+ if (includeObserved) {
207
+ if (nyDow === 6) addHoliday(formatDate(year, 1, 3), "New Year's Day (Observed)", true);
208
+ if (nyDow === 7) addHoliday(formatDate(year, 1, 2), "New Year's Day (Observed)", true);
209
+ }
210
+ const adDow = getIsoDayOfWeek(year, 1, 26);
211
+ addHoliday(formatDate(year, 1, 26), "Australia Day");
212
+ if (includeObserved) {
213
+ if (adDow === 6) addHoliday(formatDate(year, 1, 28), "Australia Day (Observed)", true);
214
+ if (adDow === 7) addHoliday(formatDate(year, 1, 27), "Australia Day (Observed)", true);
215
+ }
216
+ addHoliday(getGoodFriday(year), "Good Friday");
217
+ addHoliday(getEasterSaturday(year), "Easter Saturday");
218
+ addHoliday(getEasterSunday(year).dateStr, "Easter Sunday");
219
+ addHoliday(getEasterMonday(year), "Easter Monday");
220
+ addHoliday(formatDate(year, 4, 25), "ANZAC Day");
221
+ if (includeObserved && ["WA", "ACT", "NT"].includes(reg ?? "")) {
222
+ const anzacDow = getIsoDayOfWeek(year, 4, 25);
223
+ if (anzacDow === 7) addHoliday(formatDate(year, 4, 26), "ANZAC Day (Observed)", true, reg);
224
+ if (anzacDow === 6 && reg === "WA") addHoliday(formatDate(year, 4, 27), "ANZAC Day (Observed)", true, "WA");
225
+ }
226
+ if (reg === "WA") {
227
+ addHoliday(getNthWeekdayOfMonth(year, 9, 1, -1), "King's Birthday", false, "WA");
228
+ } else if (reg === "QLD") {
229
+ addHoliday(getNthWeekdayOfMonth(year, 10, 1, 1), "King's Birthday", false, "QLD");
230
+ } else {
231
+ addHoliday(getNthWeekdayOfMonth(year, 6, 1, 2), "King's Birthday");
232
+ }
233
+ if (reg === "WA") {
234
+ addHoliday(getNthWeekdayOfMonth(year, 3, 1, 1), "Labour Day", false, "WA");
235
+ } else if (reg === "VIC") {
236
+ addHoliday(getNthWeekdayOfMonth(year, 3, 1, 2), "Labour Day", false, "VIC");
237
+ } else if (reg === "TAS") {
238
+ addHoliday(getNthWeekdayOfMonth(year, 3, 1, 2), "Eight Hours Day", false, "TAS");
239
+ } else if (reg === "QLD") {
240
+ addHoliday(getNthWeekdayOfMonth(year, 5, 1, 1), "Labour Day", false, "QLD");
241
+ } else if (reg === "NT") {
242
+ addHoliday(getNthWeekdayOfMonth(year, 5, 1, 1), "May Day", false, "NT");
243
+ } else if (reg === "ACT" || reg === "NSW" || reg === "SA" || !reg) {
244
+ addHoliday(getNthWeekdayOfMonth(year, 10, 1, 1), "Labour Day", false, reg);
245
+ }
246
+ if (reg === "VIC")
247
+ addHoliday(getNthWeekdayOfMonth(year, 11, 2, 1), "Melbourne Cup Day", false, "VIC");
248
+ const cDow = getIsoDayOfWeek(year, 12, 25);
249
+ addHoliday(formatDate(year, 12, 25), "Christmas Day");
250
+ const boxingName = reg === "SA" ? "Proclamation Day" : "Boxing Day";
251
+ addHoliday(formatDate(year, 12, 26), boxingName);
252
+ if (includeObserved) {
253
+ if (cDow === 6) {
254
+ addHoliday(formatDate(year, 12, 27), "Christmas Day (Observed)", true);
255
+ addHoliday(formatDate(year, 12, 28), `${boxingName} (Observed)`, true);
256
+ } else if (cDow === 7) {
257
+ addHoliday(formatDate(year, 12, 27), "Christmas Day (Observed)", true);
258
+ } else if (cDow === 5) {
259
+ addHoliday(formatDate(year, 12, 28), `${boxingName} (Observed)`, true);
260
+ }
261
+ }
262
+ return holidays.sort((a, b) => a.date.localeCompare(b.date));
263
+ };
264
+
265
+ // src/calendars/gb.ts
266
+ var generateGbHolidays = (year, region, includeObserved = true) => {
267
+ const holidays = [];
268
+ const country = "GB";
269
+ const reg = region ? region.toUpperCase().replace(/^GB-/, "") : void 0;
270
+ const isScotland = reg === "SCT" || reg === "SCOTLAND";
271
+ const isNorthernIreland = reg === "NIR" || reg === "NORTHERN-IRELAND";
272
+ const addHoliday = (date, name, isObserved = false, holidayRegion) => {
273
+ holidays.push({ date, name, country, region: holidayRegion, isObserved });
274
+ };
275
+ const nyDow = getIsoDayOfWeek(year, 1, 1);
276
+ addHoliday(formatDate(year, 1, 1), "New Year's Day");
277
+ if (includeObserved) {
278
+ if (nyDow === 6) addHoliday(formatDate(year, 1, 3), "New Year's Day (Observed)", true);
279
+ if (nyDow === 7) addHoliday(formatDate(year, 1, 2), "New Year's Day (Observed)", true);
280
+ }
281
+ if (isScotland)
282
+ addHoliday(formatDate(year, 1, 2), "2nd January", false, "SCT");
283
+ if (isNorthernIreland)
284
+ addHoliday(formatDate(year, 3, 17), "St Patrick's Day", false, "NIR");
285
+ addHoliday(getGoodFriday(year), "Good Friday");
286
+ if (!isScotland)
287
+ addHoliday(getEasterMonday(year), "Easter Monday");
288
+ addHoliday(getNthWeekdayOfMonth(year, 5, 1, 1), "Early May Bank Holiday");
289
+ addHoliday(getNthWeekdayOfMonth(year, 5, 1, -1), "Spring Bank Holiday");
290
+ if (isNorthernIreland)
291
+ addHoliday(formatDate(year, 7, 12), "Battle of the Boyne", false, "NIR");
292
+ if (isScotland) {
293
+ addHoliday(getNthWeekdayOfMonth(year, 8, 1, 1), "Summer Bank Holiday", false, "SCT");
294
+ } else {
295
+ addHoliday(getNthWeekdayOfMonth(year, 8, 1, -1), "Summer Bank Holiday");
296
+ }
297
+ if (isScotland)
298
+ addHoliday(formatDate(year, 11, 30), "St Andrew's Day", false, "SCT");
299
+ const cDow = getIsoDayOfWeek(year, 12, 25);
300
+ addHoliday(formatDate(year, 12, 25), "Christmas Day");
301
+ addHoliday(formatDate(year, 12, 26), "Boxing Day");
302
+ if (includeObserved) {
303
+ if (cDow === 6) {
304
+ addHoliday(formatDate(year, 12, 27), "Christmas Day (Observed)", true);
305
+ addHoliday(formatDate(year, 12, 28), "Boxing Day (Observed)", true);
306
+ } else if (cDow === 7) {
307
+ addHoliday(formatDate(year, 12, 27), "Christmas Day (Observed)", true);
308
+ } else if (cDow === 5) {
309
+ addHoliday(formatDate(year, 12, 28), "Boxing Day (Observed)", true);
310
+ }
311
+ }
312
+ return holidays.sort((a, b) => a.date.localeCompare(b.date));
313
+ };
314
+
315
+ // src/calendars/ca.ts
316
+ var generateCaHolidays = (year, region, includeObserved = true) => {
317
+ const holidays = [];
318
+ const country = "CA";
319
+ const reg = region ? region.toUpperCase().replace(/^CA-/, "") : void 0;
320
+ const addHoliday = (date, name, isObserved = false, holidayRegion) => {
321
+ if (!holidayRegion || !reg || holidayRegion === reg) {
322
+ holidays.push({ date, name, country, region: holidayRegion, isObserved });
323
+ }
324
+ };
325
+ const nyDow = getIsoDayOfWeek(year, 1, 1);
326
+ addHoliday(formatDate(year, 1, 1), "New Year's Day");
327
+ if (includeObserved) {
328
+ if (nyDow === 6) addHoliday(formatDate(year, 1, 3), "New Year's Day (Observed)", true);
329
+ if (nyDow === 7) addHoliday(formatDate(year, 1, 2), "New Year's Day (Observed)", true);
330
+ }
331
+ const familyDay = getNthWeekdayOfMonth(year, 2, 1, 3);
332
+ if (reg === "MB") addHoliday(familyDay, "Louis Riel Day", false, "MB");
333
+ else if (reg === "PE") addHoliday(familyDay, "Islander Day", false, "PE");
334
+ else if (reg === "NS") addHoliday(familyDay, "Heritage Day", false, "NS");
335
+ else addHoliday(familyDay, "Family Day", false, reg);
336
+ addHoliday(getGoodFriday(year), "Good Friday");
337
+ if (reg === "QC" || !reg) {
338
+ addHoliday(getEasterMonday(year), "Easter Monday", false, reg);
339
+ }
340
+ const may24Dow = getIsoDayOfWeek(year, 5, 24);
341
+ const victoriaDayOffset = may24Dow === 1 ? 0 : -(may24Dow - 1);
342
+ const victoriaDay = offsetDate(year, 5, 24, victoriaDayOffset);
343
+ const vicName = reg === "QC" ? "National Patriots\u2019 Day" : "Victoria Day";
344
+ addHoliday(victoriaDay, vicName, false, reg);
345
+ const cdDow = getIsoDayOfWeek(year, 7, 1);
346
+ addHoliday(formatDate(year, 7, 1), "Canada Day");
347
+ if (includeObserved && cdDow === 7)
348
+ addHoliday(formatDate(year, 7, 2), "Canada Day (Observed)", true);
349
+ addHoliday(getNthWeekdayOfMonth(year, 8, 1, 1), "Civic Holiday", false, reg);
350
+ addHoliday(getNthWeekdayOfMonth(year, 9, 1, 1), "Labour Day");
351
+ if (year >= 2021)
352
+ addHoliday(formatDate(year, 9, 30), "National Day for Truth and Reconciliation");
353
+ addHoliday(getNthWeekdayOfMonth(year, 10, 1, 2), "Thanksgiving");
354
+ addHoliday(formatDate(year, 11, 11), "Remembrance Day");
355
+ addHoliday(formatDate(year, 12, 25), "Christmas Day");
356
+ addHoliday(formatDate(year, 12, 26), "Boxing Day");
357
+ return holidays.sort((a, b) => a.date.localeCompare(b.date));
358
+ };
359
+
360
+ // src/calendars/de.ts
361
+ var generateDeHolidays = (year, region) => {
362
+ const holidays = [];
363
+ const country = "DE";
364
+ const reg = region ? region.toUpperCase().replace(/^DE-/, "") : void 0;
365
+ const addHoliday = (date, name, localName, holidayRegion) => {
366
+ if (!holidayRegion || !reg || holidayRegion === reg)
367
+ holidays.push({ date, name, localName, country, region: holidayRegion });
368
+ };
369
+ addHoliday(formatDate(year, 1, 1), "New Year's Day", "Neujahr");
370
+ if (["BW", "BY", "ST"].includes(reg ?? ""))
371
+ addHoliday(formatDate(year, 1, 6), "Epiphany", "Heilige Drei K\xF6nige", reg);
372
+ if (year >= 2019 && reg === "BE" || year >= 2023 && reg === "MV")
373
+ addHoliday(formatDate(year, 3, 8), "International Women's Day", "Internationaler Frauentag", reg);
374
+ addHoliday(getGoodFriday(year), "Good Friday", "Karfreitag");
375
+ addHoliday(getEasterMonday(year), "Easter Monday", "Ostermontag");
376
+ addHoliday(formatDate(year, 5, 1), "Labour Day", "Tag der Arbeit");
377
+ addHoliday(getAscensionDay(year), "Ascension Day", "Christi Himmelfahrt");
378
+ addHoliday(getWhitMonday(year), "Whit Monday", "Pfingstmontag");
379
+ if (["BW", "BY", "HE", "NW", "RP", "SL"].includes(reg ?? ""))
380
+ addHoliday(getCorpusChristi(year), "Corpus Christi", "Fronleichnam", reg);
381
+ if (["BY", "SL"].includes(reg ?? ""))
382
+ addHoliday(formatDate(year, 8, 15), "Assumption Day", "Mari\xE4 Himmelfahrt", reg);
383
+ if (year >= 2019 && reg === "TH")
384
+ addHoliday(formatDate(year, 9, 20), "World Children's Day", "Weltkindertag", "TH");
385
+ addHoliday(formatDate(year, 10, 3), "German Unity Day", "Tag der Deutschen Einheit");
386
+ if (["BB", "HB", "HH", "MV", "NI", "SN", "ST", "SH", "TH"].includes(reg ?? ""))
387
+ addHoliday(formatDate(year, 10, 31), "Reformation Day", "Reformationstag", reg);
388
+ if (["BW", "BY", "NW", "RP", "SL"].includes(reg ?? ""))
389
+ addHoliday(formatDate(year, 11, 1), "All Saints' Day", "Allerheiligen", reg);
390
+ if (reg === "SN") {
391
+ const dow23 = getIsoDayOfWeek(year, 11, 23);
392
+ const daysBack = (dow23 - 3 + 7) % 7 || 7;
393
+ addHoliday(offsetDate(year, 11, 23, -daysBack), "Repentance and Prayer Day", "Bu\xDF- und Bettag", "SN");
394
+ }
395
+ addHoliday(formatDate(year, 12, 25), "Christmas Day", "1. Weihnachtstag");
396
+ addHoliday(formatDate(year, 12, 26), "St. Stephen's Day", "2. Weihnachtstag");
397
+ return holidays.sort((a, b) => a.date.localeCompare(b.date));
398
+ };
399
+
400
+ // src/calendars/fr.ts
401
+ var generateFrHolidays = (year, region) => {
402
+ const holidays = [];
403
+ const country = "FR";
404
+ const reg = region ? region.toUpperCase().replace(/^FR-/, "") : void 0;
405
+ const isAlsaceMoselle = ["57", "67", "68", "ALSACE", "MOSELLE"].includes(reg ?? "");
406
+ const addHoliday = (date, name, localName, holidayRegion) => {
407
+ if (!holidayRegion || !reg || holidayRegion === reg)
408
+ holidays.push({ date, name, localName, country, region: holidayRegion });
409
+ };
410
+ addHoliday(formatDate(year, 1, 1), "New Year's Day", "Jour de l'An");
411
+ if (isAlsaceMoselle)
412
+ addHoliday(getGoodFriday(year), "Good Friday", "Vendredi Saint", reg);
413
+ addHoliday(getEasterMonday(year), "Easter Monday", "Lundi de P\xE2ques");
414
+ addHoliday(formatDate(year, 5, 1), "Labour Day", "F\xEAte du Travail");
415
+ addHoliday(formatDate(year, 5, 8), "Victory in Europe Day", "Victoire 1945");
416
+ addHoliday(getAscensionDay(year), "Ascension Day", "Ascension");
417
+ addHoliday(getWhitMonday(year), "Whit Monday", "Lundi de Pentec\xF4te");
418
+ addHoliday(formatDate(year, 7, 14), "Bastille Day", "F\xEAte Nationale");
419
+ addHoliday(formatDate(year, 8, 15), "Assumption of Mary", "Assomption");
420
+ addHoliday(formatDate(year, 11, 1), "All Saints' Day", "Toussaint");
421
+ addHoliday(formatDate(year, 11, 11), "Armistice Day", "Armistice 1918");
422
+ addHoliday(formatDate(year, 12, 25), "Christmas Day", "No\xEBl");
423
+ if (isAlsaceMoselle)
424
+ addHoliday(formatDate(year, 12, 26), "St. Stephen's Day", "Saint-\xC9tienne", reg);
425
+ return holidays.sort((a, b) => a.date.localeCompare(b.date));
426
+ };
427
+
428
+ // src/calendars/jp.ts
429
+ function getJpVernalEquinoxDay(year) {
430
+ if (year >= 1980 && year <= 2099) {
431
+ return Math.floor(20.8431 + 0.242194 * (year - 1980) - Math.floor((year - 1980) / 4));
432
+ }
433
+ return 20;
434
+ }
435
+ function getJpAutumnalEquinoxDay(year) {
436
+ if (year >= 1980 && year <= 2099)
437
+ return Math.floor(23.2488 + 0.242194 * (year - 1980) - Math.floor((year - 1980) / 4));
438
+ return 23;
439
+ }
440
+ var generateJpHolidays = (year, _region, includeObserved = true) => {
441
+ const holidays = [];
442
+ const country = "JP";
443
+ const addHoliday = (date, name, localName, isObserved = false) => {
444
+ holidays.push({ date, name, localName, country, isObserved });
445
+ };
446
+ addHoliday(formatDate(year, 1, 1), "New Year's Day", "\u5143\u65E5");
447
+ addHoliday(getNthWeekdayOfMonth(year, 1, 1, 2), "Coming of Age Day", "\u6210\u4EBA\u306E\u65E5");
448
+ addHoliday(formatDate(year, 2, 11), "National Foundation Day", "\u5EFA\u56FD\u8A18\u5FF5\u306E\u65E5");
449
+ if (year >= 2020) {
450
+ addHoliday(formatDate(year, 2, 23), "Emperor's Birthday", "\u5929\u7687\u8A95\u751F\u65E5");
451
+ }
452
+ const vernalDay = getJpVernalEquinoxDay(year);
453
+ addHoliday(formatDate(year, 3, vernalDay), "Vernal Equinox Day", "\u6625\u5206\u306E\u65E5");
454
+ addHoliday(formatDate(year, 4, 29), "Sh\u014Dwa Day", "\u662D\u548C\u306E\u65E5");
455
+ addHoliday(formatDate(year, 5, 3), "Constitution Memorial Day", "\u61B2\u6CD5\u8A18\u5FF5\u65E5");
456
+ addHoliday(formatDate(year, 5, 4), "Greenery Day", "\u307F\u3069\u308A\u306E\u65E5");
457
+ addHoliday(formatDate(year, 5, 5), "Children's Day", "\u3053\u3069\u3082\u306E\u65E5");
458
+ addHoliday(getNthWeekdayOfMonth(year, 7, 1, 3), "Marine Day", "\u6D77\u306E\u65E5");
459
+ if (year >= 2016) {
460
+ addHoliday(formatDate(year, 8, 11), "Mountain Day", "\u5C71\u306E\u65E5");
461
+ }
462
+ const respectDay = getNthWeekdayOfMonth(year, 9, 1, 3);
463
+ addHoliday(respectDay, "Respect for the Aged Day", "\u656C\u8001\u306E\u65E5");
464
+ const autumnalDay = getJpAutumnalEquinoxDay(year);
465
+ const autumnalDate = formatDate(year, 9, autumnalDay);
466
+ addHoliday(autumnalDate, "Autumnal Equinox Day", "\u79CB\u5206\u306E\u65E5");
467
+ const rDay = Number(respectDay.split("-")[2]);
468
+ if (autumnalDay - rDay === 2) {
469
+ addHoliday(formatDate(year, 9, rDay + 1), "Citizen's Holiday", "\u56FD\u6C11\u306E\u4F11\u65E5");
470
+ }
471
+ addHoliday(getNthWeekdayOfMonth(year, 10, 1, 2), "Sports Day", "\u30B9\u30DD\u30FC\u30C4\u306E\u65E5");
472
+ addHoliday(formatDate(year, 11, 3), "Culture Day", "\u6587\u5316\u306E\u65E5");
473
+ addHoliday(formatDate(year, 11, 23), "Labor Thanksgiving Day", "\u52E4\u52B4\u611F\u8B1D\u306E\u65E5");
474
+ if (includeObserved) {
475
+ const existingDates = new Set(holidays.map((h) => h.date));
476
+ const toAdd = [];
477
+ for (const h of holidays) {
478
+ const parts = h.date.split("-").map(Number);
479
+ const dow = getIsoDayOfWeek(parts[0], parts[1], parts[2]);
480
+ if (dow === 7) {
481
+ let testOffset = 1;
482
+ let subDate = offsetDate(parts[0], parts[1], parts[2], testOffset);
483
+ while (existingDates.has(subDate)) {
484
+ testOffset++;
485
+ subDate = offsetDate(parts[0], parts[1], parts[2], testOffset);
486
+ }
487
+ toAdd.push({
488
+ date: subDate,
489
+ name: `${h.name} (Observed)`,
490
+ localName: "\u632F\u66FF\u4F11\u65E5",
491
+ country,
492
+ isObserved: true
493
+ });
494
+ existingDates.add(subDate);
495
+ }
496
+ }
497
+ holidays.push(...toAdd);
498
+ }
499
+ return holidays.sort((a, b) => a.date.localeCompare(b.date));
500
+ };
501
+
502
+ // src/calendars/nz.ts
503
+ var MATARIKI_DATES = {
504
+ 2022: "2022-06-24",
505
+ 2023: "2023-07-14",
506
+ 2024: "2024-06-28",
507
+ 2025: "2025-06-20",
508
+ 2026: "2026-07-10",
509
+ 2027: "2027-06-25",
510
+ 2028: "2028-07-14",
511
+ 2029: "2029-07-06",
512
+ 2030: "2030-06-21",
513
+ 2031: "2031-07-11",
514
+ 2032: "2032-07-02",
515
+ 2033: "2033-06-24",
516
+ 2034: "2034-07-07",
517
+ 2035: "2035-06-29"
518
+ };
519
+ var generateNzHolidays = (year, region, includeObserved = true) => {
520
+ const holidays = [];
521
+ const country = "NZ";
522
+ const reg = region ? region.toUpperCase().replace(/^NZ-/, "") : void 0;
523
+ const addHoliday = (date, name, isObserved = false, holidayRegion) => {
524
+ if (!holidayRegion || !reg || holidayRegion === reg)
525
+ holidays.push({ date, name, country, region: holidayRegion, isObserved });
526
+ };
527
+ const nyDow = getIsoDayOfWeek(year, 1, 1);
528
+ addHoliday(formatDate(year, 1, 1), "New Year's Day");
529
+ addHoliday(formatDate(year, 1, 2), "Day after New Year's Day");
530
+ if (includeObserved) {
531
+ if (nyDow === 6) {
532
+ addHoliday(formatDate(year, 1, 3), "New Year's Day (Observed)", true);
533
+ addHoliday(formatDate(year, 1, 4), "Day after New Year's Day (Observed)", true);
534
+ } else if (nyDow === 7) {
535
+ addHoliday(formatDate(year, 1, 3), "New Year's Day (Observed)", true);
536
+ } else if (nyDow === 5) {
537
+ addHoliday(formatDate(year, 1, 4), "Day after New Year's Day (Observed)", true);
538
+ }
539
+ }
540
+ const wDow = getIsoDayOfWeek(year, 2, 6);
541
+ addHoliday(formatDate(year, 2, 6), "Waitangi Day");
542
+ if (includeObserved) {
543
+ if (wDow === 6) addHoliday(formatDate(year, 2, 8), "Waitangi Day (Observed)", true);
544
+ if (wDow === 7) addHoliday(formatDate(year, 2, 7), "Waitangi Day (Observed)", true);
545
+ }
546
+ addHoliday(getGoodFriday(year), "Good Friday");
547
+ addHoliday(getEasterMonday(year), "Easter Monday");
548
+ const anzacDow = getIsoDayOfWeek(year, 4, 25);
549
+ addHoliday(formatDate(year, 4, 25), "ANZAC Day");
550
+ if (includeObserved) {
551
+ if (anzacDow === 6) addHoliday(formatDate(year, 4, 27), "ANZAC Day (Observed)", true);
552
+ if (anzacDow === 7) addHoliday(formatDate(year, 4, 26), "ANZAC Day (Observed)", true);
553
+ }
554
+ addHoliday(getNthWeekdayOfMonth(year, 6, 1, 1), "King's Birthday");
555
+ if (MATARIKI_DATES[year]) {
556
+ addHoliday(MATARIKI_DATES[year], "Matariki");
557
+ }
558
+ addHoliday(getNthWeekdayOfMonth(year, 10, 1, 4), "Labour Day");
559
+ const cDow = getIsoDayOfWeek(year, 12, 25);
560
+ addHoliday(formatDate(year, 12, 25), "Christmas Day");
561
+ addHoliday(formatDate(year, 12, 26), "Boxing Day");
562
+ if (includeObserved) {
563
+ if (cDow === 6) {
564
+ addHoliday(formatDate(year, 12, 27), "Christmas Day (Observed)", true);
565
+ addHoliday(formatDate(year, 12, 28), "Boxing Day (Observed)", true);
566
+ } else if (cDow === 7) {
567
+ addHoliday(formatDate(year, 12, 27), "Christmas Day (Observed)", true);
568
+ } else if (cDow === 5) {
569
+ addHoliday(formatDate(year, 12, 28), "Boxing Day (Observed)", true);
570
+ }
571
+ }
572
+ return holidays.sort((a, b) => a.date.localeCompare(b.date));
573
+ };
574
+
575
+ // src/registry.ts
576
+ var BUILTIN_CALENDARS = {
577
+ "US": generateUsHolidays,
578
+ "USA": generateUsHolidays,
579
+ "AU": generateAuHolidays,
580
+ "AUS": generateAuHolidays,
581
+ "GB": generateGbHolidays,
582
+ "UK": generateGbHolidays,
583
+ "CA": generateCaHolidays,
584
+ "CAN": generateCaHolidays,
585
+ "DE": generateDeHolidays,
586
+ "DEU": generateDeHolidays,
587
+ "FR": generateFrHolidays,
588
+ "FRA": generateFrHolidays,
589
+ "JP": generateJpHolidays,
590
+ "JPN": generateJpHolidays,
591
+ "NZ": generateNzHolidays,
592
+ "NZL": generateNzHolidays
593
+ };
594
+ var cache = /* @__PURE__ */ new Map();
595
+ var dynamicHolidays = /* @__PURE__ */ new Map();
596
+ function hasBuiltinCalendar(countryCode) {
597
+ const code = normalizeCountryCode(countryCode);
598
+ return code in BUILTIN_CALENDARS;
599
+ }
600
+ function registerHolidayItems(year, countryCode, items) {
601
+ const country = normalizeCountryCode(countryCode);
602
+ const dynKey = `${year}_${country}`;
603
+ dynamicHolidays.set(dynKey, items);
604
+ cache.set(`${year}-${country}-ALL-true`, items);
605
+ cache.set(`${year}-${country}-ALL-false`, items);
606
+ }
607
+ var ALPHA3_TO_ALPHA2 = {
608
+ "USA": "US",
609
+ "AUS": "AU",
610
+ "GBR": "GB",
611
+ "CAN": "CA",
612
+ "DEU": "DE",
613
+ "FRA": "FR",
614
+ "JPN": "JP",
615
+ "NZL": "NZ",
616
+ "IRL": "IE",
617
+ "ITA": "IT",
618
+ "ESP": "ES",
619
+ "NLD": "NL",
620
+ "BEL": "BE",
621
+ "SWE": "SE",
622
+ "NOR": "NO",
623
+ "DNK": "DK",
624
+ "FIN": "FI",
625
+ "CHE": "CH",
626
+ "AUT": "AT",
627
+ "SGP": "SG",
628
+ "ZAF": "ZA",
629
+ "BRA": "BR",
630
+ "MEX": "MX",
631
+ "IND": "IN",
632
+ "CHN": "CN",
633
+ "UK": "GB"
634
+ };
635
+ function normalizeCountryCode(countryCode) {
636
+ if (!isString(countryCode) || !countryCode) return "US";
637
+ const raw = countryCode.trim().toUpperCase();
638
+ if (ALPHA3_TO_ALPHA2[raw]) return ALPHA3_TO_ALPHA2[raw];
639
+ if (raw.includes("-")) {
640
+ const parts = raw.split("-");
641
+ const firstPart = parts[0].toUpperCase();
642
+ if (ALPHA3_TO_ALPHA2[firstPart]) return ALPHA3_TO_ALPHA2[firstPart];
643
+ if (firstPart in BUILTIN_CALENDARS || Object.values(ALPHA3_TO_ALPHA2).includes(firstPart)) {
644
+ return firstPart;
645
+ }
646
+ try {
647
+ const loc = new Intl.Locale(raw);
648
+ if (loc.region) {
649
+ const r = loc.region.toUpperCase();
650
+ return ALPHA3_TO_ALPHA2[r] ?? r;
651
+ }
652
+ } catch {
653
+ }
654
+ return ALPHA3_TO_ALPHA2[firstPart] ?? firstPart.slice(0, 2);
655
+ }
656
+ return raw.slice(0, 2);
657
+ }
658
+ function getCalendarHolidays(year, options = {}) {
659
+ const country = normalizeCountryCode(options.country);
660
+ const region = options.region;
661
+ const includeObserved = options.includeObserved ?? true;
662
+ const cacheKey = `${year}-${country}-${region ?? "ALL"}-${includeObserved}`;
663
+ let list = cache.get(cacheKey);
664
+ if (!list) {
665
+ if (hasBuiltinCalendar(country)) {
666
+ const generator = BUILTIN_CALENDARS[country] ?? generateUsHolidays;
667
+ list = generator(year, region, includeObserved);
668
+ } else {
669
+ const dynKey = `${year}_${country}`;
670
+ let items = dynamicHolidays.get(dynKey);
671
+ if (!items) {
672
+ const storageKey = `_magma_holidays_${year}_${country}`;
673
+ const stored = getStorage(storageKey);
674
+ if (stored && Array.isArray(stored) && stored.length > 0) {
675
+ items = stored;
676
+ dynamicHolidays.set(dynKey, items);
677
+ }
678
+ }
679
+ if (items) {
680
+ const normRegion = region ? region.toUpperCase().replace(/^[A-Z]{2}-/, "") : void 0;
681
+ list = normRegion ? items.filter((item) => !item.region || item.region.toUpperCase().replace(/^[A-Z]{2}-/, "") === normRegion) : items;
682
+ } else {
683
+ const customList = [];
684
+ if (options.customHolidays && options.customHolidays.length > 0) {
685
+ const customItems = options.customHolidays.map((date) => ({
686
+ date,
687
+ name: "Custom Holiday",
688
+ country,
689
+ region
690
+ }));
691
+ return customItems.sort((a, b) => a.date.localeCompare(b.date));
692
+ }
693
+ return customList;
694
+ }
695
+ }
696
+ cache.set(cacheKey, list);
697
+ }
698
+ if (options.customHolidays && options.customHolidays.length > 0) {
699
+ const customItems = options.customHolidays.map((date) => ({
700
+ date,
701
+ name: "Custom Holiday",
702
+ country,
703
+ region
704
+ }));
705
+ return [...list, ...customItems].sort((a, b) => a.date.localeCompare(b.date));
706
+ }
707
+ return list;
708
+ }
709
+
710
+ // src/engine.ts
711
+ function extractRegionFromLocale(locale) {
712
+ if (!isString2(locale) || !locale) return void 0;
713
+ const region = getLC(locale)?.region;
714
+ if (region) return region;
715
+ if (locale.includes("-")) {
716
+ const parts = locale.split("-");
717
+ for (let i = 1; i < parts.length; i++) {
718
+ const part = parts[i];
719
+ if (part.length === 2 && /^[a-zA-Z]{2}$/.test(part))
720
+ return part.toUpperCase();
721
+ }
722
+ }
723
+ return void 0;
724
+ }
725
+ function resolveHolidayOptions(tempo, options = {}) {
726
+ const explicitOpts = tempo?.[sdk_exports.$Internal]?.()?.options ?? {};
727
+ const explicitLocaleRegion = isString2(explicitOpts.locale) ? extractRegionFromLocale(explicitOpts.locale) : void 0;
728
+ const explicitTzCountry = isString2(explicitOpts.timeZone) ? getCountryFromTimeZone(tempo?.timeZone ?? explicitOpts.timeZone) : void 0;
729
+ const localeRegion = tempo && isString2(tempo.locale) ? extractRegionFromLocale(tempo.locale) : void 0;
730
+ const resolvedCountry = options.country ?? tempo?.geo?.country ?? explicitLocaleRegion ?? explicitTzCountry ?? tempo?.intl?.info?.region ?? localeRegion ?? "US";
731
+ const resolvedRegion = options.region ?? tempo?.geo?.region ?? tempo?.geo?.state;
732
+ return {
733
+ country: normalizeCountryCode(resolvedCountry),
734
+ region: resolvedRegion ? String(resolvedRegion).toUpperCase().replace(/^[A-Z]{2}-/, "") : void 0,
735
+ customHolidays: options.customHolidays,
736
+ includeObserved: options.includeObserved ?? true
737
+ };
738
+ }
739
+ function toIsoDate(tempo) {
740
+ const mm = String(tempo.mm).padStart(2, "0");
741
+ const dd = String(tempo.dd).padStart(2, "0");
742
+ return `${tempo.yy}-${mm}-${dd}`;
743
+ }
744
+ function getMatchingHolidays(tempo, options) {
745
+ const opts = resolveHolidayOptions(tempo, options);
746
+ const iso = toIsoDate(tempo);
747
+ const yearHolidays = getCalendarHolidays(tempo.yy, opts);
748
+ return yearHolidays.filter((h) => h.date === iso);
749
+ }
750
+ function isPublicHoliday(tempo, options) {
751
+ return getMatchingHolidays(tempo, options).length > 0;
752
+ }
753
+ function getHolidayName(tempo, options) {
754
+ const matches = getMatchingHolidays(tempo, options);
755
+ if (matches.length === 0) return null;
756
+ return matches[0].name;
757
+ }
758
+ function isBusinessDay(tempo, options) {
759
+ const dow = tempo.toDateTime().dayOfWeek;
760
+ const weekendDays = tempo.intl?.info?.weekend ?? [6, 7];
761
+ if (weekendDays.includes(dow)) return false;
762
+ return !isPublicHoliday(tempo, options);
763
+ }
764
+ function getYearHolidays(year, options = {}) {
765
+ return getCalendarHolidays(year, options);
766
+ }
767
+ function nextBusinessDay(tempo, options) {
768
+ let current = tempo.add({ days: 1 });
769
+ while (!isBusinessDay(current, options)) {
770
+ current = current.add({ days: 1 });
771
+ }
772
+ return current;
773
+ }
774
+ function prevBusinessDay(tempo, options) {
775
+ let current = tempo.subtract({ days: 1 });
776
+ while (!isBusinessDay(current, options)) {
777
+ current = current.subtract({ days: 1 });
778
+ }
779
+ return current;
780
+ }
781
+ function addBusinessDays(tempo, amount, options) {
782
+ if (amount === 0) return tempo;
783
+ const step = amount > 0 ? 1 : -1;
784
+ let remaining = Math.abs(amount);
785
+ let current = tempo;
786
+ while (remaining > 0) {
787
+ current = current.add({ days: step });
788
+ if (isBusinessDay(current, options)) {
789
+ remaining--;
790
+ }
791
+ }
792
+ return current;
793
+ }
794
+ function businessDaysBetween(start, end, options) {
795
+ const startIso = toIsoDate(start);
796
+ const endIso = toIsoDate(end);
797
+ if (startIso === endIso) return 0;
798
+ let current = start;
799
+ let count = 0;
800
+ if (start.epoch.ms < end.epoch.ms) {
801
+ current = current.add({ days: 1 });
802
+ while (toIsoDate(current) <= endIso) {
803
+ if (isBusinessDay(current, options))
804
+ count++;
805
+ current = current.add({ days: 1 });
806
+ }
807
+ return count;
808
+ } else {
809
+ current = current.subtract({ days: 1 });
810
+ while (toIsoDate(current) >= endIso) {
811
+ if (isBusinessDay(current, options))
812
+ count--;
813
+ current = current.subtract({ days: 1 });
814
+ }
815
+ return count;
816
+ }
817
+ }
818
+ function workingHoursBetween(start, end, options) {
819
+ const startWorkHour = options?.startHour ?? 9;
820
+ const endWorkHour = options?.endHour ?? 17;
821
+ if (startWorkHour >= endWorkHour) {
822
+ throw new Error("[holidays] startHour must be strictly less than endHour");
823
+ }
824
+ const startMs = start.epoch.ms;
825
+ const endMs = end.epoch.ms;
826
+ if (startMs === endMs) return 0;
827
+ const isForward = startMs < endMs;
828
+ const currentStart = isForward ? start : end;
829
+ const currentEnd = isForward ? end : start;
830
+ let totalMs = 0;
831
+ let iter = currentStart.set({ hour: 0, minute: 0, second: 0, millisecond: 0 });
832
+ const endIso = toIsoDate(currentEnd);
833
+ while (toIsoDate(iter) <= endIso) {
834
+ if (isBusinessDay(iter, options)) {
835
+ const dayWorkStart = iter.set({ hour: startWorkHour, minute: 0, second: 0, millisecond: 0 });
836
+ const dayWorkEnd = iter.set({ hour: endWorkHour, minute: 0, second: 0, millisecond: 0 });
837
+ const windowStartMs = Math.max(currentStart.epoch.ms, dayWorkStart.epoch.ms);
838
+ const windowEndMs = Math.min(currentEnd.epoch.ms, dayWorkEnd.epoch.ms);
839
+ if (windowStartMs < windowEndMs) {
840
+ totalMs += windowEndMs - windowStartMs;
841
+ }
842
+ }
843
+ iter = iter.add({ days: 1 });
844
+ }
845
+ const hours = totalMs / (1e3 * 60 * 60);
846
+ return isForward ? hours : -hours;
847
+ }
848
+
849
+ // src/preload.ts
850
+ import { isString as isString3 } from "tempo-kit/library";
851
+
852
+ // ../../functions/dist/support/fetch.js
853
+ var fetchWithTimeout = async (url, timeoutMs = 2e3, options = {}) => {
854
+ const controller = new AbortController();
855
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
856
+ const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
857
+ try {
858
+ const response = await fetch(url, { ...options, signal });
859
+ if (!response.ok)
860
+ throw new Error(`API returned ${response.status} for ${url}`);
861
+ return response;
862
+ } finally {
863
+ clearTimeout(timeoutId);
864
+ }
865
+ };
866
+
867
+ // ../../functions/dist/support/intl.js
868
+ var dateTimeFormatCache;
869
+ var getDateTimeFormatOptions = () => {
870
+ if (!dateTimeFormatCache)
871
+ dateTimeFormatCache = Intl.DateTimeFormat().resolvedOptions();
872
+ return dateTimeFormatCache;
873
+ };
874
+ var localeInstanceCache = /* @__PURE__ */ new Map();
875
+ var getLocale = (localeStr) => {
876
+ const key = localeStr || getDateTimeFormatOptions().locale;
877
+ let instance = localeInstanceCache.get(key);
878
+ if (!instance) {
879
+ instance = new Intl.Locale(key);
880
+ localeInstanceCache.set(key, instance);
881
+ }
882
+ return instance;
883
+ };
884
+
885
+ // ../../functions/dist/support/temporal.js
886
+ var getTemporal = () => {
887
+ if (typeof globalThis !== "undefined" && "Temporal" in globalThis)
888
+ return globalThis.Temporal;
889
+ if (typeof Temporal !== "undefined")
890
+ return Temporal;
891
+ throw new Error("[functions] Temporal API is not available in the global scope. Ensure a polyfill is loaded.");
892
+ };
893
+
894
+ // ../../functions/dist/calendar/getPublicHolidays.js
895
+ var holidayURL = "https://date.nager.at/api/v3/PublicHolidays";
896
+ var holidaysCache = /* @__PURE__ */ new Map();
897
+ var getPublicHolidays = async (year = getTemporal().Now.plainDateISO().year, region) => {
898
+ const resolvedRegion = region || getLocale().region || "US";
899
+ const cacheKey = `${year}-${resolvedRegion}`;
900
+ if (holidaysCache.has(cacheKey))
901
+ return holidaysCache.get(cacheKey);
902
+ const countryCode = resolvedRegion.split("-")[0].toUpperCase();
903
+ if (!/^[A-Z]{2}$/.test(countryCode))
904
+ throw new Error(`[functions] Invalid region code: '${resolvedRegion}'. Expected a 2-letter ISO 3166-1 country code.`);
905
+ const response = await fetchWithTimeout(`${holidayURL}/${year}/${countryCode}`, 2e3);
906
+ if (!response.ok)
907
+ throw new Error(`[functions] Failed to fetch holidays: HTTP ${response.status} ${response.statusText}`);
908
+ const data = await response.json();
909
+ holidaysCache.set(cacheKey, data);
910
+ return data;
911
+ };
912
+
913
+ // src/preload.ts
914
+ var STORAGE_PREFIX = "_magma_holidays_";
915
+ var TTL_24_HOURS = 24 * 60 * 60 * 1e3;
916
+ async function preloadHolidayCalendar(year, countryOrOptions) {
917
+ const options = isString3(countryOrOptions) ? { country: countryOrOptions } : countryOrOptions ?? {};
918
+ const country = normalizeCountryCode(options.country);
919
+ const region = options.region;
920
+ const storageKey = `${STORAGE_PREFIX}${year}_${country}`;
921
+ if (hasBuiltinCalendar(country)) {
922
+ const items = getCalendarHolidays(year, options);
923
+ setStorage(storageKey, items, { ttl: TTL_24_HOURS });
924
+ return items;
925
+ }
926
+ const cached = getStorage(storageKey);
927
+ if (cached && Array.isArray(cached) && cached.length > 0) {
928
+ registerHolidayItems(year, country, cached);
929
+ return filterByRegion(cached, region);
930
+ }
931
+ try {
932
+ const rawHolidays = await getPublicHolidays(year, country);
933
+ const items = (rawHolidays || []).flatMap((h) => {
934
+ if (h.counties && h.counties.length > 0) {
935
+ return h.counties.map((c) => ({
936
+ date: h.date,
937
+ name: h.name || h.localName,
938
+ country: h.countryCode,
939
+ region: c
940
+ }));
941
+ }
942
+ return [{
943
+ date: h.date,
944
+ name: h.name || h.localName,
945
+ country: h.countryCode,
946
+ region: void 0
947
+ }];
948
+ });
949
+ setStorage(storageKey, items, { ttl: TTL_24_HOURS });
950
+ registerHolidayItems(year, country, items);
951
+ return filterByRegion(items, region);
952
+ } catch (error) {
953
+ const fallbackItems = getCalendarHolidays(year, options);
954
+ return fallbackItems;
955
+ }
956
+ }
957
+ function filterByRegion(items, region) {
958
+ if (!region) return items;
959
+ const normRegion = region.toUpperCase().replace(/^[A-Z]{2}-/, "");
960
+ return items.filter((item) => !item.region || item.region.toUpperCase().replace(/^[A-Z]{2}-/, "") === normRegion);
961
+ }
962
+
963
+ // src/index.ts
964
+ import { isString as isString4 } from "tempo-kit/library";
965
+ function normalizeOptionsArg(arg) {
966
+ return isString4(arg) ? { country: arg } : arg ?? {};
967
+ }
968
+ var HolidaysPlugin = definePlugin({
969
+ name: "holidays",
970
+ install(TempoClass) {
971
+ const staticNamespace = {
972
+ preload: preloadHolidayCalendar,
973
+ getYearHolidays,
974
+ isPublicHoliday,
975
+ isBusinessDay,
976
+ getHolidayName,
977
+ nextBusinessDay,
978
+ prevBusinessDay,
979
+ addBusinessDays,
980
+ businessDaysBetween,
981
+ workingHoursBetween,
982
+ normalizeCountryCode
983
+ };
984
+ if (!(0, sdk_exports.hasOwn)(TempoClass, "holidays")) {
985
+ Object.defineProperty(TempoClass, "holidays", {
986
+ value: Object.freeze(staticNamespace),
987
+ writable: false,
988
+ configurable: false,
989
+ enumerable: false
990
+ });
991
+ }
992
+ if (!(0, sdk_exports.hasOwn)(TempoClass.prototype, "holidays")) {
993
+ Object.defineProperty(TempoClass.prototype, "holidays", {
994
+ get() {
995
+ const instance = this;
996
+ const opts = resolveHolidayOptions(instance);
997
+ const name = getHolidayName(instance, opts);
998
+ const list = getYearHolidays(instance.yy, opts);
999
+ const country = normalizeCountryCode(opts.country);
1000
+ return Object.freeze({
1001
+ name,
1002
+ list: Object.freeze(list),
1003
+ country,
1004
+ region: opts.region,
1005
+ isHoliday: (countryOrOptions) => {
1006
+ const callOpts = normalizeOptionsArg(countryOrOptions);
1007
+ return isPublicHoliday(instance, callOpts);
1008
+ },
1009
+ isBusinessDay: (countryOrOptions) => {
1010
+ const callOpts = normalizeOptionsArg(countryOrOptions);
1011
+ return isBusinessDay(instance, callOpts);
1012
+ },
1013
+ nextBusinessDay: (countryOrOptions) => {
1014
+ const callOpts = normalizeOptionsArg(countryOrOptions);
1015
+ return nextBusinessDay(instance, callOpts);
1016
+ },
1017
+ prevBusinessDay: (countryOrOptions) => {
1018
+ const callOpts = normalizeOptionsArg(countryOrOptions);
1019
+ return prevBusinessDay(instance, callOpts);
1020
+ },
1021
+ addBusinessDays: (amount, countryOrOptions) => {
1022
+ const callOpts = normalizeOptionsArg(countryOrOptions);
1023
+ return addBusinessDays(instance, amount, callOpts);
1024
+ },
1025
+ businessDaysUntil: (target, countryOrOptions) => {
1026
+ const callOpts = normalizeOptionsArg(countryOrOptions);
1027
+ return businessDaysBetween(instance, target, callOpts);
1028
+ },
1029
+ workingHoursUntil: (target, options) => {
1030
+ return workingHoursBetween(instance, target, options);
1031
+ },
1032
+ preload: (year) => {
1033
+ return preloadHolidayCalendar(year ?? instance.yy, resolveHolidayOptions(instance));
1034
+ }
1035
+ });
1036
+ },
1037
+ enumerable: false,
1038
+ configurable: true
1039
+ });
1040
+ }
1041
+ }
1042
+ });
1043
+ var index_default = HolidaysPlugin;
1044
+ export {
1045
+ HolidaysPlugin,
1046
+ addBusinessDays,
1047
+ businessDaysBetween,
1048
+ index_default as default,
1049
+ getHolidayName,
1050
+ getYearHolidays,
1051
+ isBusinessDay,
1052
+ isPublicHoliday,
1053
+ nextBusinessDay,
1054
+ normalizeCountryCode,
1055
+ preloadHolidayCalendar,
1056
+ prevBusinessDay,
1057
+ workingHoursBetween
1058
+ };