temporal-fmt 0.9.2 → 0.9.4
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/README.md +480 -9
- package/dist/calendarUtils.cjs +259 -4
- package/dist/calendarUtils.cjs.map +1 -1
- package/dist/calendarUtils.js +33 -1
- package/dist/chunk-4N3WCGEY.js +183 -0
- package/dist/{chunk-4JWGUR4O.js.map → chunk-4N3WCGEY.js.map} +1 -1
- package/dist/chunk-5UTV5VP6.js +984 -0
- package/dist/chunk-5UTV5VP6.js.map +1 -0
- package/dist/chunk-ACKKWH5Z.js +578 -0
- package/dist/{chunk-2JHEV7ZF.js.map → chunk-ACKKWH5Z.js.map} +1 -1
- package/dist/chunk-EGUUO6LE.js +439 -0
- package/dist/chunk-EGUUO6LE.js.map +1 -0
- package/dist/chunk-FBPHNRVW.js +2939 -0
- package/dist/chunk-FBPHNRVW.js.map +1 -0
- package/dist/chunk-GPB4JHGI.js +65 -0
- package/dist/chunk-GPB4JHGI.js.map +1 -0
- package/dist/chunk-H7YQX25T.js +170 -0
- package/dist/{chunk-J2AQNXF2.js.map → chunk-H7YQX25T.js.map} +1 -1
- package/dist/chunk-HXY2GUUM.js +182 -0
- package/dist/{chunk-EHLRZULM.js.map → chunk-HXY2GUUM.js.map} +1 -1
- package/dist/chunk-L24NPTAJ.js +328 -0
- package/dist/chunk-L24NPTAJ.js.map +1 -0
- package/dist/chunk-M3GDTHMT.js +169 -0
- package/dist/chunk-M3GDTHMT.js.map +1 -0
- package/dist/chunk-MKPDLQKD.js +51 -0
- package/dist/chunk-MKPDLQKD.js.map +1 -0
- package/dist/chunk-TSLPIURC.js +242 -0
- package/dist/{chunk-VQXUMFB2.js.map → chunk-TSLPIURC.js.map} +1 -1
- package/dist/chunk-UOPAV3WX.js +75 -0
- package/dist/chunk-UOPAV3WX.js.map +1 -0
- package/dist/chunk-VNIUIQA4.js +398 -0
- package/dist/chunk-VNIUIQA4.js.map +1 -0
- package/dist/chunk-YEUASGDK.js +9 -0
- package/dist/chunk-YEUASGDK.js.map +1 -0
- package/dist/chunk-ZQZF5EXW.js +29 -0
- package/dist/chunk-ZQZF5EXW.js.map +1 -0
- package/dist/config.d.cts +4 -2
- package/dist/config.d.ts +4 -2
- package/dist/duration.cjs +638 -26
- package/dist/duration.cjs.map +1 -1
- package/dist/duration.js +28 -1
- package/dist/format.cjs +833 -35
- package/dist/format.cjs.map +1 -1
- package/dist/format.js +20 -1
- package/dist/index.cjs +7698 -163
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +108 -24
- package/dist/index.d.ts +108 -24
- package/dist/index.js +1536 -58
- package/dist/index.js.map +1 -1
- package/dist/interval.cjs +5480 -35
- package/dist/interval.cjs.map +1 -1
- package/dist/interval.js +46 -1
- package/dist/localeRegistry.cjs +375 -32
- package/dist/localeRegistry.cjs.map +1 -1
- package/dist/localeRegistry.js +11 -1
- package/dist/modApi.d.cts +131 -0
- package/dist/modApi.d.ts +131 -0
- package/dist/parse.cjs +1797 -70
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.js +20 -1
- package/dist/pattern.d.cts +1 -0
- package/dist/pattern.d.ts +1 -0
- package/dist/recurrence.cjs +452 -20
- package/dist/recurrence.cjs.map +1 -1
- package/dist/recurrence.js +19 -1
- package/dist/relativeTime.cjs +268 -21
- package/dist/relativeTime.cjs.map +1 -1
- package/dist/relativeTime.js +14 -1
- package/dist/runtime.d.cts +201 -0
- package/dist/runtime.d.ts +201 -0
- package/dist/timezone.cjs +387 -20
- package/dist/timezone.cjs.map +1 -1
- package/dist/timezone.js +26 -1
- package/package.json +4 -6
- package/scripts/cli.mjs +27 -5
- package/dist/chunk-2JHEV7ZF.js +0 -7
- package/dist/chunk-3MZLTVP3.js +0 -2
- package/dist/chunk-3MZLTVP3.js.map +0 -1
- package/dist/chunk-4JWGUR4O.js +0 -11
- package/dist/chunk-5U5WJ465.js +0 -36
- package/dist/chunk-5U5WJ465.js.map +0 -1
- package/dist/chunk-C5YESWFT.js +0 -2
- package/dist/chunk-C5YESWFT.js.map +0 -1
- package/dist/chunk-C6ZZ62ET.js +0 -2
- package/dist/chunk-C6ZZ62ET.js.map +0 -1
- package/dist/chunk-EHLRZULM.js +0 -5
- package/dist/chunk-F4RGUDA3.js +0 -2
- package/dist/chunk-F4RGUDA3.js.map +0 -1
- package/dist/chunk-J2AQNXF2.js +0 -2
- package/dist/chunk-NBXF7V5B.js +0 -2
- package/dist/chunk-NBXF7V5B.js.map +0 -1
- package/dist/chunk-R52YOKI3.js +0 -7
- package/dist/chunk-R52YOKI3.js.map +0 -1
- package/dist/chunk-UJR6DHXY.js +0 -2
- package/dist/chunk-UJR6DHXY.js.map +0 -1
- package/dist/chunk-VQXUMFB2.js +0 -21
- package/dist/chunk-XH46JNPK.js +0 -2
- package/dist/chunk-XH46JNPK.js.map +0 -1
- package/dist/chunk-YB6YAG7E.js +0 -35
- package/dist/chunk-YB6YAG7E.js.map +0 -1
- package/dist/chunk-ZGMTY52O.js +0 -2
- package/dist/chunk-ZGMTY52O.js.map +0 -1
package/dist/timezone.cjs
CHANGED
|
@@ -1,21 +1,388 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/timezone.ts
|
|
21
|
+
var timezone_exports = {};
|
|
22
|
+
__export(timezone_exports, {
|
|
23
|
+
getNextTransition: () => getNextTransition,
|
|
24
|
+
getOffset: () => getOffset,
|
|
25
|
+
getOffsetNanoseconds: () => getOffsetNanoseconds,
|
|
26
|
+
getPreviousTransition: () => getPreviousTransition,
|
|
27
|
+
getTimeZone: () => getTimeZone,
|
|
28
|
+
getTransitions: () => getTransitions,
|
|
29
|
+
isDST: () => isDST,
|
|
30
|
+
possibleInstantsFor: () => possibleInstantsFor,
|
|
31
|
+
resolveZoned: () => resolveZoned
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(timezone_exports);
|
|
34
|
+
|
|
35
|
+
// src/temporalProvider.ts
|
|
36
|
+
var injectedTemporal;
|
|
37
|
+
function resolveTemporal() {
|
|
38
|
+
return injectedTemporal ?? globalThis.Temporal;
|
|
39
|
+
}
|
|
40
|
+
function getTemporal() {
|
|
41
|
+
const temporal = resolveTemporal();
|
|
42
|
+
if (!temporal) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"temporal-fmt: parse() needs a Temporal implementation to construct its result. Call setTemporal(Temporal) once at startup, or assign one to globalThis.Temporal (native on Node 26+, or a polyfill like temporal-polyfill)."
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return temporal;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/isoWeek.ts
|
|
51
|
+
function isGregorianLeapYear(year) {
|
|
52
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/calendarUtils.ts
|
|
56
|
+
function requireFields(view, fields) {
|
|
57
|
+
for (const f of fields) {
|
|
58
|
+
if (typeof view[f] !== "number") {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`temporal-fmt: calendar helper requires "${String(f)}", which this value doesn't have. Pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function daysInMonth(view) {
|
|
66
|
+
requireFields(view, ["year", "month"]);
|
|
67
|
+
const { year, month } = view;
|
|
68
|
+
const LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
69
|
+
if (month === 2 && isGregorianLeapYear(year)) return 29;
|
|
70
|
+
return LENGTHS[month - 1];
|
|
71
|
+
}
|
|
72
|
+
function asDateFieldView(value) {
|
|
73
|
+
if (typeof value !== "object" || value === null) {
|
|
74
|
+
throw new Error(`temporal-fmt: expected a date-carrying Temporal value, got ${String(value)}.`);
|
|
75
|
+
}
|
|
76
|
+
const v = value;
|
|
77
|
+
const out = {};
|
|
78
|
+
if (typeof v.year === "number") out.year = v.year;
|
|
79
|
+
if (typeof v.month === "number") out.month = v.month;
|
|
80
|
+
if (typeof v.day === "number") out.day = v.day;
|
|
81
|
+
if (typeof v.hour === "number") out.hour = v.hour;
|
|
82
|
+
if (typeof v.minute === "number") out.minute = v.minute;
|
|
83
|
+
if (typeof v.second === "number") out.second = v.second;
|
|
84
|
+
if (typeof v.millisecond === "number") out.millisecond = v.millisecond;
|
|
85
|
+
if (typeof v.dayOfWeek === "number") out.dayOfWeek = v.dayOfWeek;
|
|
86
|
+
if (typeof v.calendarId === "string") out.calendarId = v.calendarId;
|
|
87
|
+
if (out.year === void 0 || out.month === void 0 || out.day === void 0) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`temporal-fmt: value is missing year/month/day fields \u2014 pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/arithmetic.ts
|
|
96
|
+
function asDateTime(value) {
|
|
97
|
+
return asDateFieldView(value);
|
|
98
|
+
}
|
|
99
|
+
function recomputeDayOfWeek(view) {
|
|
100
|
+
if (typeof view.dayOfWeek !== "number") return;
|
|
101
|
+
/* c8 ignore start @preserve -- unreachable: every call site (add()'s
|
|
102
|
+
'years'/'months' cases, shiftDays()) passes a `result` whose
|
|
103
|
+
year/month/day were just explicitly set, and the value originally
|
|
104
|
+
came from asDateTime()/asDateFieldView(), which throws unless
|
|
105
|
+
year/month/day are all present as numbers. So by the time this guard
|
|
106
|
+
runs, all three are guaranteed valid. Kept in case a future caller
|
|
107
|
+
constructs a DateTimeFieldView bypassing that validation. */
|
|
108
|
+
if (typeof view.year !== "number" || typeof view.month !== "number" || typeof view.day !== "number") return;
|
|
109
|
+
/* c8 ignore stop @preserve */
|
|
110
|
+
const jsDow = new Date(Date.UTC(view.year, view.month - 1, view.day)).getUTCDay();
|
|
111
|
+
view.dayOfWeek = jsDow === 0 ? 7 : jsDow;
|
|
112
|
+
}
|
|
113
|
+
function add(value, amount, unit) {
|
|
114
|
+
const v = asDateTime(value);
|
|
115
|
+
let result = { ...v };
|
|
116
|
+
switch (unit) {
|
|
117
|
+
case "years": {
|
|
118
|
+
/* c8 ignore start @preserve -- the `?? 0` fallback is unreachable:
|
|
119
|
+
asDateTime()/asDateFieldView() (called at the top of add()) throws
|
|
120
|
+
unless year is present as a number, so result.year is never
|
|
121
|
+
undefined here. Kept as a guard against a future change that
|
|
122
|
+
relaxes that validation. */
|
|
123
|
+
result.year = (result.year ?? 0) + amount;
|
|
124
|
+
/* c8 ignore stop @preserve */
|
|
125
|
+
const maxDay = daysInMonth({ year: result.year, month: result.month });
|
|
126
|
+
if (result.day > maxDay) result.day = maxDay;
|
|
127
|
+
recomputeDayOfWeek(result);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case "months": {
|
|
131
|
+
/* c8 ignore start @preserve -- both `??` fallbacks are unreachable
|
|
132
|
+
for the same reason as the 'years' case above: asDateFieldView()
|
|
133
|
+
guarantees year and month are present numbers before add() ever
|
|
134
|
+
reaches here. */
|
|
135
|
+
const total = (result.year ?? 0) * 12 + (result.month ?? 1) - 1 + amount;
|
|
136
|
+
/* c8 ignore stop @preserve */
|
|
137
|
+
result.year = Math.floor(total / 12);
|
|
138
|
+
result.month = total % 12 + 1;
|
|
139
|
+
if (result.month < 1) {
|
|
140
|
+
result.month += 12;
|
|
141
|
+
result.year -= 1;
|
|
142
|
+
}
|
|
143
|
+
/* c8 ignore start @preserve -- unreachable: (total % 12) + 1 can never
|
|
144
|
+
exceed 12 for any integer total in JS (its range is [-10, 12] since
|
|
145
|
+
JS's % can return a negative remainder but never one with
|
|
146
|
+
magnitude >= 12, so adding 1 tops out at 12). Only the < 1 branch
|
|
147
|
+
above is reachable; this was written symmetrically with it but the
|
|
148
|
+
overflow direction it guards against can't occur. Kept rather than
|
|
149
|
+
removed since it costs nothing and documents the intent. */
|
|
150
|
+
if (result.month > 12) {
|
|
151
|
+
result.month -= 12;
|
|
152
|
+
result.year += 1;
|
|
153
|
+
}
|
|
154
|
+
/* c8 ignore stop @preserve */
|
|
155
|
+
const maxDay = daysInMonth({ year: result.year, month: result.month });
|
|
156
|
+
if (result.day > maxDay) result.day = maxDay;
|
|
157
|
+
recomputeDayOfWeek(result);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case "weeks":
|
|
161
|
+
result = shiftDays(result, amount * 7);
|
|
162
|
+
break;
|
|
163
|
+
case "days":
|
|
164
|
+
result = shiftDays(result, amount);
|
|
165
|
+
break;
|
|
166
|
+
case "hours":
|
|
167
|
+
result = shiftTime(result, amount * 36e5);
|
|
168
|
+
break;
|
|
169
|
+
case "minutes":
|
|
170
|
+
result = shiftTime(result, amount * 6e4);
|
|
171
|
+
break;
|
|
172
|
+
case "seconds":
|
|
173
|
+
result = shiftTime(result, amount * 1e3);
|
|
174
|
+
break;
|
|
175
|
+
case "milliseconds":
|
|
176
|
+
result = shiftTime(result, amount);
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
function shiftDays(v, days) {
|
|
182
|
+
const y = v.year, m = v.month, d = v.day;
|
|
183
|
+
const y2 = m <= 2 ? y - 1 : y;
|
|
184
|
+
const era = Math.floor((y2 >= 0 ? y2 : y2 - 399) / 400);
|
|
185
|
+
const yoe = y2 - era * 400;
|
|
186
|
+
const m2 = m > 2 ? m - 3 : m + 9;
|
|
187
|
+
const doy = Math.floor((153 * m2 + 2) / 5) + d - 1;
|
|
188
|
+
const doe = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + doy;
|
|
189
|
+
const totalDays = era * 146097 + doe - 719468 + days;
|
|
190
|
+
const z = totalDays + 719468;
|
|
191
|
+
const era2 = Math.floor((z >= 0 ? z : z - 146096) / 146097);
|
|
192
|
+
const doe2 = z - era2 * 146097;
|
|
193
|
+
const yoe2 = Math.floor((doe2 - Math.floor(doe2 / 1460) + Math.floor(doe2 / 36524) - Math.floor(doe2 / 146096)) / 365);
|
|
194
|
+
const y2out = yoe2 + era2 * 400;
|
|
195
|
+
const doy2 = doe2 - (365 * yoe2 + Math.floor(yoe2 / 4) - Math.floor(yoe2 / 100));
|
|
196
|
+
const mp = Math.floor((5 * doy2 + 2) / 153);
|
|
197
|
+
const d2 = doy2 - Math.floor((153 * mp + 2) / 5) + 1;
|
|
198
|
+
const m2out = mp < 10 ? mp + 3 : mp - 9;
|
|
199
|
+
const yOut = m2out <= 2 ? y2out + 1 : y2out;
|
|
200
|
+
const result = { ...v, year: yOut, month: m2out, day: d2 };
|
|
201
|
+
recomputeDayOfWeek(result);
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
function shiftTime(v, msDelta) {
|
|
205
|
+
const MS_PER_DAY = 864e5;
|
|
206
|
+
const MS_PER_HOUR = 36e5;
|
|
207
|
+
const MS_PER_MINUTE = 6e4;
|
|
208
|
+
const MS_PER_SECOND = 1e3;
|
|
209
|
+
const totalMs = (v.hour ?? 0) * MS_PER_HOUR + (v.minute ?? 0) * MS_PER_MINUTE + (v.second ?? 0) * MS_PER_SECOND + (v.millisecond ?? 0) + msDelta;
|
|
210
|
+
const dayOverflow = Math.floor(totalMs / MS_PER_DAY);
|
|
211
|
+
let withinDay = totalMs % MS_PER_DAY;
|
|
212
|
+
if (withinDay < 0) {
|
|
213
|
+
withinDay += MS_PER_DAY;
|
|
214
|
+
}
|
|
215
|
+
const hour = Math.floor(withinDay / MS_PER_HOUR);
|
|
216
|
+
const minute = Math.floor(withinDay % MS_PER_HOUR / MS_PER_MINUTE);
|
|
217
|
+
const second = Math.floor(withinDay % MS_PER_MINUTE / MS_PER_SECOND);
|
|
218
|
+
const millisecond = withinDay % MS_PER_SECOND;
|
|
219
|
+
const result = { ...v, hour, minute, second, millisecond };
|
|
220
|
+
if (dayOverflow !== 0) {
|
|
221
|
+
return shiftDays(result, dayOverflow);
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/timezone.ts
|
|
227
|
+
function resolveZoned(fields, timeZone, options = {}) {
|
|
228
|
+
const temporal = getTemporal();
|
|
229
|
+
const disambiguation = options.disambiguation ?? "compatible";
|
|
230
|
+
const overflow = options.overflow ?? "constrain";
|
|
231
|
+
const fromOptions = {
|
|
232
|
+
overflow,
|
|
233
|
+
disambiguation,
|
|
234
|
+
offset: options.offset ?? "prefer"
|
|
235
|
+
};
|
|
236
|
+
try {
|
|
237
|
+
return temporal.ZonedDateTime.from(
|
|
238
|
+
{
|
|
239
|
+
year: fields.year,
|
|
240
|
+
month: fields.month,
|
|
241
|
+
day: fields.day,
|
|
242
|
+
hour: fields.hour ?? 0,
|
|
243
|
+
minute: fields.minute ?? 0,
|
|
244
|
+
second: fields.second ?? 0,
|
|
245
|
+
millisecond: fields.millisecond ?? 0,
|
|
246
|
+
microsecond: fields.microsecond ?? 0,
|
|
247
|
+
nanosecond: fields.nanosecond ?? 0,
|
|
248
|
+
timeZone
|
|
249
|
+
},
|
|
250
|
+
fromOptions
|
|
251
|
+
);
|
|
252
|
+
} catch (err) {
|
|
253
|
+
const msg = err.message;
|
|
254
|
+
if (/no such (wall-clock )?time/i.test(msg) && disambiguation === "reject") {
|
|
255
|
+
throw new Error(
|
|
256
|
+
`temporal-fmt: "${timeZone}" has no such wall-clock time on ${fields.year}-${fields.month}-${fields.day}T${fields.hour ?? 0}:${fields.minute ?? 0} \u2014 it falls in a DST gap. Pass { disambiguation: 'compatible' | 'earlier' | 'later' } to pick an instant.`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
throw err;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function getTimeZone(value) {
|
|
263
|
+
const v = value;
|
|
264
|
+
if (typeof v?.timeZoneId !== "string") {
|
|
265
|
+
throw new Error(`temporal-fmt: getTimeZone() expected a ZonedDateTime, got ${typeof value}.`);
|
|
266
|
+
}
|
|
267
|
+
return v.timeZoneId;
|
|
268
|
+
}
|
|
269
|
+
function getOffset(value) {
|
|
270
|
+
const v = value;
|
|
271
|
+
if (typeof v?.offset !== "string") {
|
|
272
|
+
throw new Error(`temporal-fmt: getOffset() expected a ZonedDateTime, got ${typeof value}.`);
|
|
273
|
+
}
|
|
274
|
+
return v.offset;
|
|
275
|
+
}
|
|
276
|
+
function getOffsetNanoseconds(value) {
|
|
277
|
+
const v = value;
|
|
278
|
+
if (typeof v?.offsetNanoseconds === "number") return v.offsetNanoseconds;
|
|
279
|
+
if (typeof v?.offset === "string") {
|
|
280
|
+
const m = v.offset.match(/^([+-])(\d{2}):(\d{2})$/);
|
|
281
|
+
if (!m) throw new Error(`temporal-fmt: getOffsetNanoseconds() couldn't parse offset "${v.offset}".`);
|
|
282
|
+
const sign = m[1] === "-" ? -1 : 1;
|
|
283
|
+
return sign * (Number(m[2]) * 3600 + Number(m[3]) * 60) * 1e9;
|
|
284
|
+
}
|
|
285
|
+
throw new Error(`temporal-fmt: getOffsetNanoseconds() expected a ZonedDateTime, got ${typeof value}.`);
|
|
286
|
+
}
|
|
287
|
+
function isDST(value) {
|
|
288
|
+
const v = value;
|
|
289
|
+
if (typeof v?.timeZoneId !== "string" || typeof v?.offset !== "string" || typeof v?.year !== "number") {
|
|
290
|
+
throw new Error(`temporal-fmt: isDST() expected a ZonedDateTime, got ${typeof value}.`);
|
|
291
|
+
}
|
|
292
|
+
const temporal = getTemporal();
|
|
293
|
+
try {
|
|
294
|
+
const jan = temporal.ZonedDateTime.from(
|
|
295
|
+
{ year: v.year, month: 1, day: 1, hour: 12, timeZone: v.timeZoneId },
|
|
296
|
+
{ disambiguation: "compatible" }
|
|
297
|
+
);
|
|
298
|
+
return jan.offset !== v.offset;
|
|
299
|
+
} catch {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function getNextTransition(value) {
|
|
304
|
+
return findTransition(value, 1);
|
|
305
|
+
}
|
|
306
|
+
function getPreviousTransition(value) {
|
|
307
|
+
return findTransition(value, -1);
|
|
308
|
+
}
|
|
309
|
+
function findTransition(value, direction) {
|
|
310
|
+
const v = value;
|
|
311
|
+
if (typeof v?.timeZoneId !== "string") {
|
|
312
|
+
throw new Error(`temporal-fmt: ${direction > 0 ? "getNextTransition" : "getPreviousTransition"}() expected a ZonedDateTime, got ${typeof value}.`);
|
|
313
|
+
}
|
|
314
|
+
const temporal = getTemporal();
|
|
315
|
+
const timeZone = v.timeZoneId;
|
|
316
|
+
let candidateFields = add(value, direction, "days");
|
|
317
|
+
const startOffset = v.offset;
|
|
318
|
+
for (let i = 0; i < 365 * 2; i++) {
|
|
319
|
+
const cf = candidateFields;
|
|
320
|
+
const candidateZdt = temporal.ZonedDateTime.from(
|
|
321
|
+
{ ...cf, timeZone },
|
|
322
|
+
{ disambiguation: "compatible" }
|
|
323
|
+
);
|
|
324
|
+
if (candidateZdt.offset !== startOffset) {
|
|
325
|
+
return candidateZdt;
|
|
326
|
+
}
|
|
327
|
+
candidateFields = add(candidateFields, direction, "days");
|
|
328
|
+
}
|
|
329
|
+
return void 0;
|
|
330
|
+
}
|
|
331
|
+
function getTransitions(start, end) {
|
|
332
|
+
const result = [];
|
|
333
|
+
const startV = start;
|
|
334
|
+
if (typeof startV?.timeZoneId !== "string") {
|
|
335
|
+
throw new Error(`temporal-fmt: getTransitions() expected a ZonedDateTime for start, got ${typeof start}.`);
|
|
336
|
+
}
|
|
337
|
+
const endV = end;
|
|
338
|
+
const temporal = getTemporal();
|
|
339
|
+
const timeZone = startV.timeZoneId;
|
|
340
|
+
let cursorFields = add(start, 1, "days");
|
|
341
|
+
let lastOffset = startV.offset;
|
|
342
|
+
for (let i = 0; i < 365 * 5; i++) {
|
|
343
|
+
const cf = cursorFields;
|
|
344
|
+
const cursorZdt = temporal.ZonedDateTime.from(
|
|
345
|
+
{ ...cf, timeZone },
|
|
346
|
+
{ disambiguation: "compatible" }
|
|
347
|
+
);
|
|
348
|
+
if (cursorZdt.offset !== lastOffset) {
|
|
349
|
+
if (cursorZdt.year > endV.year || cursorZdt.year === endV.year && (cursorZdt.month > endV.month || cursorZdt.month === endV.month && cursorZdt.day > endV.day)) break;
|
|
350
|
+
result.push(cursorZdt);
|
|
351
|
+
lastOffset = cursorZdt.offset;
|
|
352
|
+
}
|
|
353
|
+
cursorFields = add(cursorFields, 1, "days");
|
|
354
|
+
}
|
|
355
|
+
return result;
|
|
356
|
+
}
|
|
357
|
+
function possibleInstantsFor(fields, timeZone) {
|
|
358
|
+
const temporal = getTemporal();
|
|
359
|
+
const earlier = temporal.ZonedDateTime.from(
|
|
360
|
+
{ ...fields, timeZone },
|
|
361
|
+
{ disambiguation: "earlier", offset: "ignore" }
|
|
362
|
+
);
|
|
363
|
+
const later = temporal.ZonedDateTime.from(
|
|
364
|
+
{ ...fields, timeZone },
|
|
365
|
+
{ disambiguation: "later", offset: "ignore" }
|
|
366
|
+
);
|
|
367
|
+
const matchesRequestedWallClock = (z) => z.year === fields.year && z.month === fields.month && z.day === fields.day && z.hour === fields.hour && z.minute === fields.minute && z.second === fields.second && z.millisecond === fields.millisecond;
|
|
368
|
+
if (!matchesRequestedWallClock(earlier) || !matchesRequestedWallClock(later)) {
|
|
369
|
+
return [];
|
|
370
|
+
}
|
|
371
|
+
if (earlier.toInstant().epochNanoseconds === later.toInstant().epochNanoseconds) {
|
|
372
|
+
return [earlier];
|
|
373
|
+
}
|
|
374
|
+
return [earlier, later];
|
|
375
|
+
}
|
|
376
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
377
|
+
0 && (module.exports = {
|
|
378
|
+
getNextTransition,
|
|
379
|
+
getOffset,
|
|
380
|
+
getOffsetNanoseconds,
|
|
381
|
+
getPreviousTransition,
|
|
382
|
+
getTimeZone,
|
|
383
|
+
getTransitions,
|
|
384
|
+
isDST,
|
|
385
|
+
possibleInstantsFor,
|
|
386
|
+
resolveZoned
|
|
387
|
+
});
|
|
21
388
|
//# sourceMappingURL=timezone.cjs.map
|