temporal-fmt 0.9.0 → 0.9.2
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/calendarUtils.cjs +4 -259
- package/dist/calendarUtils.cjs.map +1 -1
- package/dist/calendarUtils.js +1 -33
- package/dist/chunk-2JHEV7ZF.js +7 -0
- package/dist/chunk-2JHEV7ZF.js.map +1 -0
- package/dist/chunk-3MZLTVP3.js +2 -0
- package/dist/{chunk-MXXYIMFJ.js.map → chunk-3MZLTVP3.js.map} +1 -1
- package/dist/chunk-4JWGUR4O.js +11 -0
- package/dist/{chunk-AXQLUIDY.js.map → chunk-4JWGUR4O.js.map} +1 -1
- package/dist/chunk-5U5WJ465.js +36 -0
- package/dist/chunk-5U5WJ465.js.map +1 -0
- package/dist/chunk-C5YESWFT.js +2 -0
- package/dist/chunk-C5YESWFT.js.map +1 -0
- package/dist/chunk-C6ZZ62ET.js +2 -0
- package/dist/{chunk-YS52LOMJ.js.map → chunk-C6ZZ62ET.js.map} +1 -1
- package/dist/chunk-EHLRZULM.js +5 -0
- package/dist/{chunk-4ZBGVYLR.js.map → chunk-EHLRZULM.js.map} +1 -1
- package/dist/chunk-F4RGUDA3.js +2 -0
- package/dist/chunk-F4RGUDA3.js.map +1 -0
- package/dist/chunk-J2AQNXF2.js +2 -0
- package/dist/{chunk-GRJQHQLW.js.map → chunk-J2AQNXF2.js.map} +1 -1
- package/dist/chunk-NBXF7V5B.js +2 -0
- package/dist/chunk-NBXF7V5B.js.map +1 -0
- package/dist/chunk-R52YOKI3.js +7 -0
- package/dist/{chunk-M33NSC4E.js.map → chunk-R52YOKI3.js.map} +1 -1
- package/dist/chunk-UJR6DHXY.js +2 -0
- package/dist/chunk-UJR6DHXY.js.map +1 -0
- package/dist/chunk-VQXUMFB2.js +21 -0
- package/dist/{chunk-VHSZL3P3.js.map → chunk-VQXUMFB2.js.map} +1 -1
- package/dist/chunk-XH46JNPK.js +2 -0
- package/dist/chunk-XH46JNPK.js.map +1 -0
- package/dist/chunk-YB6YAG7E.js +35 -0
- package/dist/chunk-YB6YAG7E.js.map +1 -0
- package/dist/chunk-ZGMTY52O.js +2 -0
- package/dist/chunk-ZGMTY52O.js.map +1 -0
- package/dist/duration.cjs +9 -624
- package/dist/duration.cjs.map +1 -1
- package/dist/duration.js +1 -29
- package/dist/format.cjs +18 -769
- package/dist/format.cjs.map +1 -1
- package/dist/format.js +1 -20
- package/dist/formatDuration.d.cts +6 -0
- package/dist/formatDuration.d.ts +6 -0
- package/dist/index.cjs +146 -6672
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -3004
- package/dist/index.js.map +1 -1
- package/dist/interval.cjs +18 -952
- package/dist/interval.cjs.map +1 -1
- package/dist/interval.js +1 -41
- package/dist/localeRegistry.cjs +15 -328
- package/dist/localeRegistry.cjs.map +1 -1
- package/dist/localeRegistry.js +1 -11
- package/dist/localeVocab.d.cts +3 -0
- package/dist/localeVocab.d.ts +3 -0
- package/dist/parse.cjs +53 -1637
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.js +1 -20
- package/dist/parsePattern.d.cts +1 -0
- package/dist/parsePattern.d.ts +1 -0
- package/dist/pattern.d.cts +1 -0
- package/dist/pattern.d.ts +1 -0
- package/dist/recurrence.cjs +20 -450
- package/dist/recurrence.cjs.map +1 -1
- package/dist/recurrence.js +1 -20
- package/dist/relativeTime.cjs +24 -177
- package/dist/relativeTime.cjs.map +1 -1
- package/dist/relativeTime.js +1 -14
- package/dist/rounding.d.cts +1 -0
- package/dist/rounding.d.ts +1 -0
- package/dist/serialization.d.cts +1 -1
- package/dist/serialization.d.ts +1 -1
- package/dist/timezone.cjs +20 -387
- package/dist/timezone.cjs.map +1 -1
- package/dist/timezone.js +1 -26
- package/dist/typeGuards.d.cts +9 -9
- package/dist/typeGuards.d.ts +9 -9
- package/package.json +4 -2
- package/dist/chunk-4ZBGVYLR.js +0 -182
- package/dist/chunk-AXQLUIDY.js +0 -183
- package/dist/chunk-CKVHXFX7.js +0 -902
- package/dist/chunk-CKVHXFX7.js.map +0 -1
- package/dist/chunk-CSUIKL73.js +0 -215
- package/dist/chunk-CSUIKL73.js.map +0 -1
- package/dist/chunk-EDUFSRWJ.js +0 -9
- package/dist/chunk-EDUFSRWJ.js.map +0 -1
- package/dist/chunk-FQA4XJME.js +0 -57
- package/dist/chunk-FQA4XJME.js.map +0 -1
- package/dist/chunk-FTMLZ4EN.js +0 -196
- package/dist/chunk-FTMLZ4EN.js.map +0 -1
- package/dist/chunk-GRJQHQLW.js +0 -170
- package/dist/chunk-JCIMP43G.js +0 -602
- package/dist/chunk-JCIMP43G.js.map +0 -1
- package/dist/chunk-KDYK72Z2.js +0 -75
- package/dist/chunk-KDYK72Z2.js.map +0 -1
- package/dist/chunk-M33NSC4E.js +0 -169
- package/dist/chunk-MXXYIMFJ.js +0 -29
- package/dist/chunk-NFKQ3EXC.js +0 -188
- package/dist/chunk-NFKQ3EXC.js.map +0 -1
- package/dist/chunk-O6GVMBLW.js +0 -403
- package/dist/chunk-O6GVMBLW.js.map +0 -1
- package/dist/chunk-VHSZL3P3.js +0 -242
- package/dist/chunk-VSUCBUTC.js +0 -295
- package/dist/chunk-VSUCBUTC.js.map +0 -1
- package/dist/chunk-YS52LOMJ.js +0 -51
package/dist/index.js
CHANGED
|
@@ -1,3005 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
parseISODuration,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
registerLocale
|
|
59
|
-
} from "./chunk-KDYK72Z2.js";
|
|
60
|
-
import {
|
|
61
|
-
FORMAT_ONLY_TOKENS,
|
|
62
|
-
UNPADDED_NUMERIC_TOKENS,
|
|
63
|
-
compileParser,
|
|
64
|
-
parse,
|
|
65
|
-
parseToParts,
|
|
66
|
-
safeParse,
|
|
67
|
-
tryParse
|
|
68
|
-
} from "./chunk-CKVHXFX7.js";
|
|
69
|
-
import {
|
|
70
|
-
SUPPORTED_NUMBERING_SYSTEMS,
|
|
71
|
-
applyNumbering,
|
|
72
|
-
applyParseNumbering,
|
|
73
|
-
convertDigits,
|
|
74
|
-
convertDigitsToAscii,
|
|
75
|
-
tokenize
|
|
76
|
-
} from "./chunk-M33NSC4E.js";
|
|
77
|
-
import {
|
|
78
|
-
DEFAULT_LOCALE,
|
|
79
|
-
TOKENS
|
|
80
|
-
} from "./chunk-VSUCBUTC.js";
|
|
81
|
-
import {
|
|
82
|
-
MAX_FORMAT_LENGTH
|
|
83
|
-
} from "./chunk-EDUFSRWJ.js";
|
|
84
|
-
import {
|
|
85
|
-
getTemporal,
|
|
86
|
-
setTemporal
|
|
87
|
-
} from "./chunk-MXXYIMFJ.js";
|
|
88
|
-
import {
|
|
89
|
-
AmbiguousInputError,
|
|
90
|
-
FormatSyntaxError,
|
|
91
|
-
InvalidCalendarError,
|
|
92
|
-
InvalidDateError,
|
|
93
|
-
InvalidDurationError,
|
|
94
|
-
InvalidLocaleError,
|
|
95
|
-
InvalidOffsetError,
|
|
96
|
-
InvalidTimeError,
|
|
97
|
-
InvalidTimeZoneError,
|
|
98
|
-
ParseMismatchError,
|
|
99
|
-
TemporalFmtError,
|
|
100
|
-
UnknownTokenError,
|
|
101
|
-
registerLocaleVocab
|
|
102
|
-
} from "./chunk-O6GVMBLW.js";
|
|
103
|
-
import {
|
|
104
|
-
between,
|
|
105
|
-
formatRRule,
|
|
106
|
-
parseRRule,
|
|
107
|
-
recurrence,
|
|
108
|
-
skip,
|
|
109
|
-
take
|
|
110
|
-
} from "./chunk-CSUIKL73.js";
|
|
111
|
-
import {
|
|
112
|
-
add,
|
|
113
|
-
addDays,
|
|
114
|
-
addHours,
|
|
115
|
-
addMilliseconds,
|
|
116
|
-
addMinutes,
|
|
117
|
-
addMonths,
|
|
118
|
-
addSeconds,
|
|
119
|
-
addWeeks,
|
|
120
|
-
addYears,
|
|
121
|
-
difference,
|
|
122
|
-
differenceInDays,
|
|
123
|
-
differenceInHours,
|
|
124
|
-
differenceInMilliseconds,
|
|
125
|
-
differenceInMinutes,
|
|
126
|
-
differenceInMonths,
|
|
127
|
-
differenceInSeconds,
|
|
128
|
-
differenceInWeeks,
|
|
129
|
-
differenceInYears,
|
|
130
|
-
subtract,
|
|
131
|
-
subtractDays,
|
|
132
|
-
subtractHours,
|
|
133
|
-
subtractMilliseconds,
|
|
134
|
-
subtractMinutes,
|
|
135
|
-
subtractMonths,
|
|
136
|
-
subtractSeconds,
|
|
137
|
-
subtractWeeks,
|
|
138
|
-
subtractYears
|
|
139
|
-
} from "./chunk-VHSZL3P3.js";
|
|
140
|
-
import {
|
|
141
|
-
clamp,
|
|
142
|
-
compare,
|
|
143
|
-
isAfter,
|
|
144
|
-
isBefore,
|
|
145
|
-
isBetween,
|
|
146
|
-
isEqual,
|
|
147
|
-
isSameDay,
|
|
148
|
-
isSameMonth,
|
|
149
|
-
isSameQuarter,
|
|
150
|
-
isSameWeek,
|
|
151
|
-
isSameYear,
|
|
152
|
-
isToday,
|
|
153
|
-
isTomorrow,
|
|
154
|
-
isWeekday,
|
|
155
|
-
isWeekend,
|
|
156
|
-
isYesterday,
|
|
157
|
-
max,
|
|
158
|
-
min
|
|
159
|
-
} from "./chunk-NFKQ3EXC.js";
|
|
160
|
-
import {
|
|
161
|
-
asDateFieldView,
|
|
162
|
-
dayOfYearHelper,
|
|
163
|
-
daysInMonth,
|
|
164
|
-
daysInYear,
|
|
165
|
-
endOf,
|
|
166
|
-
getMonth,
|
|
167
|
-
getQuarter,
|
|
168
|
-
getWeekday,
|
|
169
|
-
isLeapMonth,
|
|
170
|
-
isLeapYear,
|
|
171
|
-
monthsInYear,
|
|
172
|
-
startOf,
|
|
173
|
-
weekOfYear,
|
|
174
|
-
weekYear
|
|
175
|
-
} from "./chunk-4ZBGVYLR.js";
|
|
176
|
-
import {
|
|
177
|
-
dayOfYear,
|
|
178
|
-
isGregorianLeapYear
|
|
179
|
-
} from "./chunk-YS52LOMJ.js";
|
|
180
|
-
|
|
181
|
-
// src/formatDistance.ts
|
|
182
|
-
function readFields(value, label) {
|
|
183
|
-
if (value === null || typeof value !== "object") {
|
|
184
|
-
throw new Error(
|
|
185
|
-
`temporal-fmt: formatDistance expects Temporal values, got ${label} = ${String(value)}.`
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
const obj = value;
|
|
189
|
-
const hasYear = typeof obj.year === "number";
|
|
190
|
-
const hasMonth = typeof obj.month === "number";
|
|
191
|
-
const hasDay = typeof obj.day === "number";
|
|
192
|
-
if (hasYear !== hasMonth || hasMonth !== hasDay) {
|
|
193
|
-
throw new Error(
|
|
194
|
-
`temporal-fmt: formatDistance got a ${label} with a partial date (some of year/month/day missing). Pass a full Temporal.PlainDate / PlainDateTime / ZonedDateTime.`
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
return {
|
|
198
|
-
year: hasYear ? obj.year : void 0,
|
|
199
|
-
month: hasMonth ? obj.month : void 0,
|
|
200
|
-
day: hasDay ? obj.day : void 0,
|
|
201
|
-
hour: typeof obj.hour === "number" ? obj.hour : void 0,
|
|
202
|
-
minute: typeof obj.minute === "number" ? obj.minute : void 0,
|
|
203
|
-
second: typeof obj.second === "number" ? obj.second : void 0,
|
|
204
|
-
millisecond: typeof obj.millisecond === "number" ? obj.millisecond : void 0
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
var REFERENCE_YEAR = 2e3;
|
|
208
|
-
var MS_PER_SECOND = 1e3;
|
|
209
|
-
var MS_PER_MINUTE = 60 * MS_PER_SECOND;
|
|
210
|
-
var MS_PER_HOUR = 60 * MS_PER_MINUTE;
|
|
211
|
-
var MS_PER_DAY = 24 * MS_PER_HOUR;
|
|
212
|
-
function daysSinceReference(year, month, day) {
|
|
213
|
-
let days = 0;
|
|
214
|
-
if (year >= REFERENCE_YEAR) {
|
|
215
|
-
for (let y = REFERENCE_YEAR; y < year; y++) {
|
|
216
|
-
days += isGregorianLeapYear(y) ? 366 : 365;
|
|
217
|
-
}
|
|
218
|
-
} else {
|
|
219
|
-
for (let y = year; y < REFERENCE_YEAR; y++) {
|
|
220
|
-
days -= isGregorianLeapYear(y) ? 366 : 365;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
days += dayOfYear(year, month, day) - 1;
|
|
224
|
-
return days;
|
|
225
|
-
}
|
|
226
|
-
function toEpochMs(fields) {
|
|
227
|
-
if (fields.year === void 0 || fields.month === void 0 || fields.day === void 0) {
|
|
228
|
-
throw new Error(
|
|
229
|
-
`temporal-fmt: formatDistance needs a Temporal value with year/month/day fields (PlainDate, PlainDateTime, or ZonedDateTime). A PlainTime or other shape has no anchor date to diff against.`
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
const days = daysSinceReference(fields.year, fields.month, fields.day);
|
|
233
|
-
const hour = fields.hour ?? 0;
|
|
234
|
-
const minute = fields.minute ?? 0;
|
|
235
|
-
const second = fields.second ?? 0;
|
|
236
|
-
const millisecond = fields.millisecond ?? 0;
|
|
237
|
-
return days * MS_PER_DAY + hour * MS_PER_HOUR + minute * MS_PER_MINUTE + second * MS_PER_SECOND + millisecond;
|
|
238
|
-
}
|
|
239
|
-
var DEFAULT_CUTOFFS = {
|
|
240
|
-
seconds: 60,
|
|
241
|
-
// 60 s
|
|
242
|
-
minutes: 60,
|
|
243
|
-
// 60 min
|
|
244
|
-
hours: 24,
|
|
245
|
-
// 24 h
|
|
246
|
-
days: 30,
|
|
247
|
-
// 30 d
|
|
248
|
-
months: 365
|
|
249
|
-
// 365 d (in days, since the months→years boundary is day-resolution)
|
|
250
|
-
};
|
|
251
|
-
function resolveCutoffs(user) {
|
|
252
|
-
const merged = { ...DEFAULT_CUTOFFS, ...user };
|
|
253
|
-
for (const key of Object.keys(merged)) {
|
|
254
|
-
const value = merged[key];
|
|
255
|
-
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
256
|
-
throw new Error(
|
|
257
|
-
`temporal-fmt: formatDistance cutoff "${key}" must be a positive finite number (got ${String(value)}).`
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
const secondsMs = merged.seconds * MS_PER_SECOND;
|
|
262
|
-
const minutesMs = merged.minutes * MS_PER_MINUTE;
|
|
263
|
-
const hoursMs = merged.hours * MS_PER_HOUR;
|
|
264
|
-
const daysMs = merged.days * MS_PER_DAY;
|
|
265
|
-
const monthsMs = merged.months * MS_PER_DAY;
|
|
266
|
-
if (!(secondsMs <= minutesMs && minutesMs <= hoursMs && hoursMs <= daysMs && daysMs <= monthsMs)) {
|
|
267
|
-
throw new Error(
|
|
268
|
-
`temporal-fmt: formatDistance cutoffs must be monotonically non-decreasing in equivalent ms (seconds \u2264 minutes \u2264 hours \u2264 days \u2264 months). Got: seconds=${merged.seconds}s, minutes=${merged.minutes}min, hours=${merged.hours}h, days=${merged.days}d, months=${merged.months}d \u2014 pick a sequence where each boundary is at least as large as the one before it.`
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
return [
|
|
272
|
-
{ maxMs: secondsMs, unit: "second" },
|
|
273
|
-
{ maxMs: minutesMs, unit: "minute" },
|
|
274
|
-
{ maxMs: hoursMs, unit: "hour" },
|
|
275
|
-
{ maxMs: daysMs, unit: "day" },
|
|
276
|
-
{ maxMs: monthsMs, unit: "month" }
|
|
277
|
-
];
|
|
278
|
-
}
|
|
279
|
-
var rtfCache = /* @__PURE__ */ new Map();
|
|
280
|
-
var MAX_RTF_CACHE_SIZE = 100;
|
|
281
|
-
function getRtf(locale, numeric) {
|
|
282
|
-
const key = `${canonicalLocaleKey(locale)}|${numeric}`;
|
|
283
|
-
let rtf = rtfCache.get(key);
|
|
284
|
-
if (rtf) return rtf;
|
|
285
|
-
if (rtfCache.size >= MAX_RTF_CACHE_SIZE) {
|
|
286
|
-
const oldestKey = rtfCache.keys().next().value;
|
|
287
|
-
if (oldestKey !== void 0) rtfCache.delete(oldestKey);
|
|
288
|
-
}
|
|
289
|
-
rtf = new Intl.RelativeTimeFormat(locale, { numeric });
|
|
290
|
-
rtfCache.set(key, rtf);
|
|
291
|
-
return rtf;
|
|
292
|
-
}
|
|
293
|
-
function canonicalLocaleKey(locale) {
|
|
294
|
-
try {
|
|
295
|
-
return new Intl.Locale(locale.replace(/_/g, "-")).toString().toLowerCase();
|
|
296
|
-
} catch {
|
|
297
|
-
return locale;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
function formatDistance(date1, date2, options = {}) {
|
|
301
|
-
const fields1 = readFields(date1, "date1");
|
|
302
|
-
const fields2 = readFields(date2, "date2");
|
|
303
|
-
const diffMs = toEpochMs(fields1) - toEpochMs(fields2);
|
|
304
|
-
const absMs = Math.abs(diffMs);
|
|
305
|
-
const unitCutoffs = resolveCutoffs(options.cutoffs);
|
|
306
|
-
let unit = "year";
|
|
307
|
-
for (const { maxMs, unit: candidateUnit } of unitCutoffs) {
|
|
308
|
-
if (absMs < maxMs) {
|
|
309
|
-
unit = candidateUnit;
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
const divisor = unitToMs(unit);
|
|
314
|
-
const rounded = Math.round(diffMs / divisor);
|
|
315
|
-
const numeric = options.numeric ?? "auto";
|
|
316
|
-
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
317
|
-
const rtf = getRtf(locale, numeric);
|
|
318
|
-
return rtf.format(rounded, unit);
|
|
319
|
-
}
|
|
320
|
-
function formatDistanceToNow(date, options = {}) {
|
|
321
|
-
const now = /* @__PURE__ */ new Date();
|
|
322
|
-
const nowFields = {
|
|
323
|
-
year: now.getFullYear(),
|
|
324
|
-
month: now.getMonth() + 1,
|
|
325
|
-
day: now.getDate(),
|
|
326
|
-
hour: now.getHours(),
|
|
327
|
-
minute: now.getMinutes(),
|
|
328
|
-
second: now.getSeconds(),
|
|
329
|
-
millisecond: now.getMilliseconds()
|
|
330
|
-
};
|
|
331
|
-
return formatDistance(date, nowFields, options);
|
|
332
|
-
}
|
|
333
|
-
function unitToMs(unit) {
|
|
334
|
-
switch (unit) {
|
|
335
|
-
case "second":
|
|
336
|
-
return MS_PER_SECOND;
|
|
337
|
-
case "minute":
|
|
338
|
-
return MS_PER_MINUTE;
|
|
339
|
-
case "hour":
|
|
340
|
-
return MS_PER_HOUR;
|
|
341
|
-
case "day":
|
|
342
|
-
return MS_PER_DAY;
|
|
343
|
-
/* c8 ignore start @preserve -- unreachable: unitToMs is only called
|
|
344
|
-
with `unit` values produced by formatDistance's cutoff loop above,
|
|
345
|
-
which only ever yields 'second'/'minute'/'hour'/'day'/'month'
|
|
346
|
-
(from resolveCutoffs' fixed array) or 'year' (the loop's fallback
|
|
347
|
-
default). 'week' and 'quarter' were never wired into
|
|
348
|
-
resolveCutoffs — formatDistance intentionally skips week-
|
|
349
|
-
resolution output (see the comment above DEFAULT_CUTOFFS) — so
|
|
350
|
-
neither can reach this switch. */
|
|
351
|
-
case "week":
|
|
352
|
-
return 7 * MS_PER_DAY;
|
|
353
|
-
/* c8 ignore stop @preserve */
|
|
354
|
-
case "month":
|
|
355
|
-
return 30 * MS_PER_DAY;
|
|
356
|
-
/* c8 ignore start @preserve -- unreachable, same reason as 'week'
|
|
357
|
-
above: resolveCutoffs never produces 'quarter'. */
|
|
358
|
-
case "quarter":
|
|
359
|
-
return 91 * MS_PER_DAY;
|
|
360
|
-
/* c8 ignore stop @preserve */
|
|
361
|
-
case "year":
|
|
362
|
-
return 365 * MS_PER_DAY;
|
|
363
|
-
/* c8 ignore start @preserve -- unreachable: every unit
|
|
364
|
-
resolveCutoffs can actually produce ('second' through 'month', or
|
|
365
|
-
'year' as the loop's fallback default) has an explicit case
|
|
366
|
-
above, so this exhaustive-switch default can't fire at runtime.
|
|
367
|
-
It exists so TS accepts the function as total — the compiler
|
|
368
|
-
can't see through the cutoff-array iteration in formatDistance()
|
|
369
|
-
to know the input is already narrowed. */
|
|
370
|
-
default:
|
|
371
|
-
throw new Error(`temporal-fmt: formatDistance hit unhandled unit "${String(unit)}".`);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// src/parseRelative.ts
|
|
376
|
-
function normalizeForMatch(s) {
|
|
377
|
-
return s.toLowerCase().replace(/ä/g, "ae").replace(/ö/g, "oe").replace(/ü/g, "ue").replace(/ß/g, "ss").normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
378
|
-
}
|
|
379
|
-
function levenshtein(a, b) {
|
|
380
|
-
/* c8 ignore start @preserve -- unreachable through the only call
|
|
381
|
-
* site (fuzzyCorrectEnglish): `a` is always a word that already
|
|
382
|
-
* failed the `vocabulary.includes(word)` exact-match check, so
|
|
383
|
-
* a === b never holds against any `b` drawn from that same
|
|
384
|
-
* vocabulary; and neither `a` (split from a non-empty normalized
|
|
385
|
-
* string) nor `b` (a vocabulary entry) is ever empty. Kept as
|
|
386
|
-
* general-purpose guards in case levenshtein() gets a second caller
|
|
387
|
-
* later. */
|
|
388
|
-
if (a === b) return 0;
|
|
389
|
-
if (a.length === 0) return b.length;
|
|
390
|
-
if (b.length === 0) return a.length;
|
|
391
|
-
/* c8 ignore stop @preserve */
|
|
392
|
-
let prev = new Array(b.length + 1);
|
|
393
|
-
let curr = new Array(b.length + 1);
|
|
394
|
-
for (let j = 0; j <= b.length; j++) prev[j] = j;
|
|
395
|
-
for (let i = 1; i <= a.length; i++) {
|
|
396
|
-
curr[0] = i;
|
|
397
|
-
for (let j = 1; j <= b.length; j++) {
|
|
398
|
-
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
399
|
-
curr[j] = Math.min(
|
|
400
|
-
prev[j] + 1,
|
|
401
|
-
// deletion
|
|
402
|
-
curr[j - 1] + 1,
|
|
403
|
-
// insertion
|
|
404
|
-
prev[j - 1] + cost
|
|
405
|
-
// substitution
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
[prev, curr] = [curr, prev];
|
|
409
|
-
}
|
|
410
|
-
return prev[b.length];
|
|
411
|
-
}
|
|
412
|
-
var FUZZY_MAX_DISTANCE = 2;
|
|
413
|
-
var MAX_RELATIVE_INPUT_LENGTH = 4096;
|
|
414
|
-
var MAX_RELATIVE_WORDS = 32;
|
|
415
|
-
function buildEnglishFuzzyVocabulary() {
|
|
416
|
-
return [
|
|
417
|
-
...ENGLISH_WEEKDAYS,
|
|
418
|
-
...ENGLISH_MONTHS,
|
|
419
|
-
...ENGLISH_MONTH_SHORT,
|
|
420
|
-
"today",
|
|
421
|
-
"tomorrow",
|
|
422
|
-
"yesterday",
|
|
423
|
-
"next",
|
|
424
|
-
"last",
|
|
425
|
-
"this",
|
|
426
|
-
"in",
|
|
427
|
-
"ago",
|
|
428
|
-
"day",
|
|
429
|
-
"days",
|
|
430
|
-
"week",
|
|
431
|
-
"weeks",
|
|
432
|
-
"month",
|
|
433
|
-
"months",
|
|
434
|
-
"year",
|
|
435
|
-
"years"
|
|
436
|
-
].map(normalizeForMatch);
|
|
437
|
-
}
|
|
438
|
-
var englishFuzzyVocabulary;
|
|
439
|
-
function getEnglishFuzzyVocabulary() {
|
|
440
|
-
if (!englishFuzzyVocabulary) englishFuzzyVocabulary = Object.freeze(buildEnglishFuzzyVocabulary());
|
|
441
|
-
return englishFuzzyVocabulary;
|
|
442
|
-
}
|
|
443
|
-
function fuzzyCorrectEnglish(normalized) {
|
|
444
|
-
const vocabulary = getEnglishFuzzyVocabulary();
|
|
445
|
-
const words = normalized.split(" ");
|
|
446
|
-
if (normalized.length > MAX_RELATIVE_INPUT_LENGTH || words.length > MAX_RELATIVE_WORDS) {
|
|
447
|
-
throw new RangeError(
|
|
448
|
-
`temporal-fmt: parseRelative fuzzy input is too large (maximum ${MAX_RELATIVE_INPUT_LENGTH} characters and ${MAX_RELATIVE_WORDS} words).`
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
let changed = false;
|
|
452
|
-
const corrected = words.map((word) => {
|
|
453
|
-
if (/^\d+(?:st|nd|rd|th)?$/.test(word)) return word;
|
|
454
|
-
if (vocabulary.includes(word)) return word;
|
|
455
|
-
let best;
|
|
456
|
-
let bestDist = FUZZY_MAX_DISTANCE + 1;
|
|
457
|
-
for (const candidate of vocabulary) {
|
|
458
|
-
const dist = levenshtein(word, candidate);
|
|
459
|
-
if (dist < bestDist) {
|
|
460
|
-
bestDist = dist;
|
|
461
|
-
best = candidate;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
if (best !== void 0 && bestDist <= FUZZY_MAX_DISTANCE) {
|
|
465
|
-
changed = true;
|
|
466
|
-
return best;
|
|
467
|
-
}
|
|
468
|
-
return word;
|
|
469
|
-
});
|
|
470
|
-
return changed ? corrected.join(" ") : void 0;
|
|
471
|
-
}
|
|
472
|
-
function readYear(reference) {
|
|
473
|
-
if (typeof reference.year !== "number") {
|
|
474
|
-
throw new Error("temporal-fmt: parseRelative reference date is missing year.");
|
|
475
|
-
}
|
|
476
|
-
return reference.year;
|
|
477
|
-
}
|
|
478
|
-
function readMonth(reference) {
|
|
479
|
-
if (typeof reference.month !== "number") {
|
|
480
|
-
throw new Error("temporal-fmt: parseRelative reference date is missing month.");
|
|
481
|
-
}
|
|
482
|
-
return reference.month;
|
|
483
|
-
}
|
|
484
|
-
function readDay(reference) {
|
|
485
|
-
if (typeof reference.day !== "number") {
|
|
486
|
-
throw new Error("temporal-fmt: parseRelative reference date is missing day.");
|
|
487
|
-
}
|
|
488
|
-
return reference.day;
|
|
489
|
-
}
|
|
490
|
-
function extractDayOfWeek(reference) {
|
|
491
|
-
const dow = reference.dayOfWeek;
|
|
492
|
-
if (typeof dow !== "number") {
|
|
493
|
-
throw new Error(
|
|
494
|
-
"temporal-fmt: parseRelative needs a reference date exposing dayOfWeek (a Temporal.PlainDate / PlainDateTime / ZonedDateTime)."
|
|
495
|
-
);
|
|
496
|
-
}
|
|
497
|
-
return dow;
|
|
498
|
-
}
|
|
499
|
-
function nameAlternation(names) {
|
|
500
|
-
const normalized = names.map(normalizeForMatch);
|
|
501
|
-
const sorted = [...normalized].sort((a, b) => b.length - a.length);
|
|
502
|
-
return sorted.map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
503
|
-
}
|
|
504
|
-
function buildPlainDate(temporal, year, month, day) {
|
|
505
|
-
return temporal.PlainDate.from({ year, month, day }, { overflow: "reject" });
|
|
506
|
-
}
|
|
507
|
-
function addDays2(temporal, reference, days) {
|
|
508
|
-
const refDate = temporal.PlainDate.from({
|
|
509
|
-
year: readYear(reference),
|
|
510
|
-
month: readMonth(reference),
|
|
511
|
-
day: readDay(reference)
|
|
512
|
-
});
|
|
513
|
-
return refDate.add({ days });
|
|
514
|
-
}
|
|
515
|
-
function addUnits(temporal, reference, count, unit) {
|
|
516
|
-
const refDate = temporal.PlainDate.from({
|
|
517
|
-
year: readYear(reference),
|
|
518
|
-
month: readMonth(reference),
|
|
519
|
-
day: readDay(reference)
|
|
520
|
-
});
|
|
521
|
-
const duration = {};
|
|
522
|
-
if (unit === "day") duration.days = count;
|
|
523
|
-
if (unit === "week") duration.weeks = count;
|
|
524
|
-
if (unit === "month") duration.months = count;
|
|
525
|
-
if (unit === "year") duration.years = count;
|
|
526
|
-
return refDate.add(duration);
|
|
527
|
-
}
|
|
528
|
-
function weekdayOffset(rel, refDow, targetDow) {
|
|
529
|
-
if (rel === "next") {
|
|
530
|
-
let diff = targetDow - refDow;
|
|
531
|
-
if (diff <= 0) diff += 7;
|
|
532
|
-
return diff;
|
|
533
|
-
}
|
|
534
|
-
if (rel === "last") {
|
|
535
|
-
let diff = targetDow - refDow;
|
|
536
|
-
if (diff >= 0) diff -= 7;
|
|
537
|
-
return diff;
|
|
538
|
-
}
|
|
539
|
-
return targetDow - refDow;
|
|
540
|
-
}
|
|
541
|
-
function resolveToNextOccurrence(temporal, reference, month, day) {
|
|
542
|
-
const refYear = readYear(reference);
|
|
543
|
-
const refDate = temporal.PlainDate.from({
|
|
544
|
-
year: refYear,
|
|
545
|
-
month: readMonth(reference),
|
|
546
|
-
day: readDay(reference)
|
|
547
|
-
});
|
|
548
|
-
if (!temporal.PlainDate.compare) {
|
|
549
|
-
throw new Error("temporal-fmt: parseRelative needs Temporal.PlainDate.compare to resolve month-day phrases; the active implementation does not expose it.");
|
|
550
|
-
}
|
|
551
|
-
try {
|
|
552
|
-
const thisYear = temporal.PlainDate.from({ year: refYear, month, day }, { overflow: "reject" });
|
|
553
|
-
if (temporal.PlainDate.compare(thisYear, refDate) >= 0) {
|
|
554
|
-
return thisYear;
|
|
555
|
-
}
|
|
556
|
-
return temporal.PlainDate.from({ year: refYear + 1, month, day }, { overflow: "reject" });
|
|
557
|
-
} catch (err) {
|
|
558
|
-
try {
|
|
559
|
-
return temporal.PlainDate.from({ year: refYear + 1, month, day }, { overflow: "reject" });
|
|
560
|
-
} catch {
|
|
561
|
-
throw new Error(
|
|
562
|
-
`temporal-fmt: parseRelative can't resolve month ${month} day ${day} \u2014 it isn't a valid date in either ${refYear} or ${refYear + 1}. Original error: ${err.message}`
|
|
563
|
-
);
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
function weekdayIndexFromName(name, names) {
|
|
568
|
-
const normalized = normalizeForMatch(name);
|
|
569
|
-
const idx = names.findIndex((n) => normalizeForMatch(n) === normalized);
|
|
570
|
-
/* c8 ignore start @preserve -- unreachable: every caller passes a
|
|
571
|
-
* name captured by nameAlternation(names), which builds its regex
|
|
572
|
-
* alternation from this same list under the same normalizeForMatch
|
|
573
|
-
* transform. The regex can't match anything findIndex() wouldn't
|
|
574
|
-
* also find here. Defensive throw kept for the type checker and as
|
|
575
|
-
* a tripwire if that invariant ever breaks. Ignore comment sits on
|
|
576
|
-
* the `if` itself, not just the throw inside it — c8 tracks the
|
|
577
|
-
* branch outcome (was the true side ever taken) separately from the
|
|
578
|
-
* statements inside, so excluding only the inner throw still leaves
|
|
579
|
-
* the branch itself flagged as uncovered. */
|
|
580
|
-
if (idx < 0) {
|
|
581
|
-
throw new Error(`temporal-fmt: parseRelative internal error \u2014 weekday "${name}" not in names list.`);
|
|
582
|
-
}
|
|
583
|
-
/* c8 ignore stop @preserve */
|
|
584
|
-
return idx + 1;
|
|
585
|
-
}
|
|
586
|
-
function monthIndexFromName(name, longNames, shortNames = []) {
|
|
587
|
-
const normalized = normalizeForMatch(name);
|
|
588
|
-
const longIdx = longNames.findIndex((n) => normalizeForMatch(n) === normalized);
|
|
589
|
-
if (longIdx >= 0) return longIdx + 1;
|
|
590
|
-
const shortIdx = shortNames.findIndex((n) => normalizeForMatch(n) === normalized);
|
|
591
|
-
if (shortIdx >= 0) return shortIdx + 1;
|
|
592
|
-
/* c8 ignore start @preserve -- unreachable: every caller passes a name
|
|
593
|
-
* captured by nameAlternation([...longNames, ...shortNames]), so the
|
|
594
|
-
* regex alternation and these two findIndex() scans are built from
|
|
595
|
-
* the same lists under the same normalizeForMatch transform. Kept as
|
|
596
|
-
* a tripwire for the type checker in case that invariant ever breaks. */
|
|
597
|
-
throw new Error(`temporal-fmt: parseRelative internal error \u2014 month "${name}" not in names list.`);
|
|
598
|
-
/* c8 ignore stop @preserve */
|
|
599
|
-
}
|
|
600
|
-
var ENGLISH_WEEKDAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
|
601
|
-
var ENGLISH_MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
602
|
-
var ENGLISH_MONTH_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
603
|
-
var ENGLISH_GRAMMAR = {
|
|
604
|
-
supportedHint: 'Supported: weekday refs ("next Tuesday"), day offsets ("today"/"tomorrow"/"yesterday"), unit offsets ("in 3 days", "2 weeks ago"), and month-day ("March 5th").',
|
|
605
|
-
matchers: [
|
|
606
|
-
// today / tomorrow / yesterday — exact match, most rigid shape.
|
|
607
|
-
// Checked first because they're the most common phrase class.
|
|
608
|
-
{
|
|
609
|
-
pattern: /^today$/i,
|
|
610
|
-
resolve: (_m, ctx) => buildPlainDate(ctx.temporal, readYear(ctx.reference), readMonth(ctx.reference), readDay(ctx.reference))
|
|
611
|
-
},
|
|
612
|
-
{
|
|
613
|
-
pattern: /^tomorrow$/i,
|
|
614
|
-
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, 1)
|
|
615
|
-
},
|
|
616
|
-
{
|
|
617
|
-
pattern: /^yesterday$/i,
|
|
618
|
-
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, -1)
|
|
619
|
-
},
|
|
620
|
-
// weekday references: "next/last/this Tuesday". Capture the relative
|
|
621
|
-
// word and the weekday name separately, then resolve via +7 / -7.
|
|
622
|
-
{
|
|
623
|
-
pattern: new RegExp(`^(next|last|this)\\s+(${nameAlternation(ENGLISH_WEEKDAYS)})$`, "i"),
|
|
624
|
-
resolve: (m, ctx) => {
|
|
625
|
-
const rel = m[1].toLowerCase();
|
|
626
|
-
const targetDow = weekdayIndexFromName(m[2], ENGLISH_WEEKDAYS);
|
|
627
|
-
const refDow = extractDayOfWeek(ctx.reference);
|
|
628
|
-
return addDays2(ctx.temporal, ctx.reference, weekdayOffset(rel, refDow, targetDow));
|
|
629
|
-
}
|
|
630
|
-
},
|
|
631
|
-
// unit offsets: "in 3 days", "2 weeks ago", "in 1 month", "1 year ago".
|
|
632
|
-
// Two shapes share this matcher — leading "in" (future) or trailing
|
|
633
|
-
// "ago" (past). Both lead with <number> <unit>.
|
|
634
|
-
{
|
|
635
|
-
pattern: /^(in\s+)?(\d+)\s+(day|week|month|year)s?(?:\s+ago)?$/i,
|
|
636
|
-
resolve: (m, ctx) => {
|
|
637
|
-
const inPrefix = m[1];
|
|
638
|
-
const count = m[2];
|
|
639
|
-
const unitName = m[3].toLowerCase();
|
|
640
|
-
const hasIn = !!inPrefix;
|
|
641
|
-
const hasAgo = /\bago\b/i.test(m[0]);
|
|
642
|
-
if (!hasIn && !hasAgo) {
|
|
643
|
-
throw new Error(
|
|
644
|
-
`temporal-fmt: parseRelative can't tell whether "${m[0]}" is past or future \u2014 use "in ${count} ${unitName}s" or "${count} ${unitName}s ago".`
|
|
645
|
-
);
|
|
646
|
-
}
|
|
647
|
-
const sign = hasIn ? 1 : -1;
|
|
648
|
-
return addUnits(ctx.temporal, ctx.reference, sign * Number(count), unitName);
|
|
649
|
-
}
|
|
650
|
-
},
|
|
651
|
-
// month-day without year, e.g. "March 5th", "March 5", "March 5, 2026"
|
|
652
|
-
// (year is ignored if present). The ordinal suffix is decorative —
|
|
653
|
-
// strip it. The day-of-month is a 1- or 2-digit number.
|
|
654
|
-
{
|
|
655
|
-
pattern: new RegExp(`^(${nameAlternation([...ENGLISH_MONTHS, ...ENGLISH_MONTH_SHORT])})\\s+(\\d{1,2})(?:st|nd|rd|th)?(?:,?\\s*(\\d{4}))?$`, "i"),
|
|
656
|
-
resolve: (m, ctx) => {
|
|
657
|
-
const month = monthIndexFromName(m[1], ENGLISH_MONTHS, ENGLISH_MONTH_SHORT);
|
|
658
|
-
const day = Number(m[2]);
|
|
659
|
-
return resolveToNextOccurrence(ctx.temporal, ctx.reference, month, day);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
]
|
|
663
|
-
};
|
|
664
|
-
var SPANISH_WEEKDAYS = ["lunes", "martes", "mi\xE9rcoles", "jueves", "viernes", "s\xE1bado", "domingo"];
|
|
665
|
-
var SPANISH_MONTHS = ["enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"];
|
|
666
|
-
var SPANISH_MONTH_SHORT = ["ene", "feb", "mar", "abr", "may", "jun", "jul", "ago", "sept", "oct", "nov", "dic"];
|
|
667
|
-
var SPANISH_GRAMMAR = {
|
|
668
|
-
supportedHint: 'Frases soportadas: referencias de d\xEDa de la semana ("el pr\xF3ximo lunes", "el lunes pasado", "este martes"), offsets de d\xEDa ("hoy"/"ma\xF1ana"/"ayer"), offsets de unidad ("en 3 d\xEDas", "hace 2 semanas"), y mes-d\xEDa ("5 de marzo").',
|
|
669
|
-
matchers: [
|
|
670
|
-
{
|
|
671
|
-
pattern: /^hoy$/i,
|
|
672
|
-
resolve: (_m, ctx) => buildPlainDate(ctx.temporal, readYear(ctx.reference), readMonth(ctx.reference), readDay(ctx.reference))
|
|
673
|
-
},
|
|
674
|
-
{
|
|
675
|
-
pattern: /^ma[ñn]ana$/i,
|
|
676
|
-
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, 1)
|
|
677
|
-
},
|
|
678
|
-
{
|
|
679
|
-
pattern: /^ayer$/i,
|
|
680
|
-
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, -1)
|
|
681
|
-
},
|
|
682
|
-
// weekday references. Spanish has three common shapes, all meaning
|
|
683
|
-
// the same thing per rel word:
|
|
684
|
-
// "el próximo lunes" / "próximo lunes" → next
|
|
685
|
-
// "el lunes próximo" → next (suffix variant)
|
|
686
|
-
// "el lunes pasado" / "lunes pasado" → last
|
|
687
|
-
// "este lunes" → this
|
|
688
|
-
// Capture the rel word from whichever shape matched, then resolve
|
|
689
|
-
// the same way English does.
|
|
690
|
-
{
|
|
691
|
-
pattern: new RegExp(
|
|
692
|
-
`^(?:el\\s+)?(?:(pr[o\xF3]ximo|pasado)\\s+(${nameAlternation(SPANISH_WEEKDAYS)})|(${nameAlternation(SPANISH_WEEKDAYS)})\\s+(pr[o\xF3]ximo|pasado)|este\\s+(${nameAlternation(SPANISH_WEEKDAYS)}))$`,
|
|
693
|
-
"i"
|
|
694
|
-
),
|
|
695
|
-
resolve: (m, ctx) => {
|
|
696
|
-
let relWord;
|
|
697
|
-
let weekdayName;
|
|
698
|
-
if (m[1] && m[2]) {
|
|
699
|
-
relWord = m[1];
|
|
700
|
-
weekdayName = m[2];
|
|
701
|
-
} else if (m[3] && m[4]) {
|
|
702
|
-
weekdayName = m[3];
|
|
703
|
-
relWord = m[4];
|
|
704
|
-
} else {
|
|
705
|
-
relWord = "este";
|
|
706
|
-
weekdayName = m[5];
|
|
707
|
-
}
|
|
708
|
-
const rel = normalizeForMatch(relWord) === "proximo" ? "next" : relWord.toLowerCase() === "este" ? "this" : "last";
|
|
709
|
-
const targetDow = weekdayIndexFromName(weekdayName, SPANISH_WEEKDAYS);
|
|
710
|
-
const refDow = extractDayOfWeek(ctx.reference);
|
|
711
|
-
return addDays2(ctx.temporal, ctx.reference, weekdayOffset(rel, refDow, targetDow));
|
|
712
|
-
}
|
|
713
|
-
},
|
|
714
|
-
// unit offsets. Spanish uses distinct markers:
|
|
715
|
-
// "en 3 días" / "dentro de 3 días" → future
|
|
716
|
-
// "hace 2 semanas" → past
|
|
717
|
-
// Both shapes lead with the marker, unlike English where one
|
|
718
|
-
// shape leads and the other trails.
|
|
719
|
-
{
|
|
720
|
-
pattern: new RegExp(
|
|
721
|
-
`^(?:(en|dentro\\s+de)\\s+(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?|(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?\\s+(hace))$`,
|
|
722
|
-
"i"
|
|
723
|
-
),
|
|
724
|
-
resolve: (m, ctx) => {
|
|
725
|
-
let count;
|
|
726
|
-
let unitWord;
|
|
727
|
-
let sign;
|
|
728
|
-
if (m[1] && m[2] && m[3]) {
|
|
729
|
-
count = m[2];
|
|
730
|
-
unitWord = m[3];
|
|
731
|
-
sign = 1;
|
|
732
|
-
} else {
|
|
733
|
-
count = m[4];
|
|
734
|
-
unitWord = m[5];
|
|
735
|
-
sign = -1;
|
|
736
|
-
}
|
|
737
|
-
const unit = unitWordToEnglish(unitWord);
|
|
738
|
-
return addUnits(ctx.temporal, ctx.reference, sign * Number(count), unit);
|
|
739
|
-
}
|
|
740
|
-
},
|
|
741
|
-
// "hace 2 semanas" — the primary past-offset shape. Matcher kept
|
|
742
|
-
// separate from the future "en/dentro de" matcher above because
|
|
743
|
-
// Spanish word order differs between the two (marker-first for
|
|
744
|
-
// past, marker-first for future too, but with different markers).
|
|
745
|
-
{
|
|
746
|
-
pattern: new RegExp(`^hace\\s+(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?$`, "i"),
|
|
747
|
-
resolve: (m, ctx) => {
|
|
748
|
-
const count = Number(m[1]);
|
|
749
|
-
const unit = unitWordToEnglish(m[2]);
|
|
750
|
-
return addUnits(ctx.temporal, ctx.reference, -count, unit);
|
|
751
|
-
}
|
|
752
|
-
},
|
|
753
|
-
// bare "N <unit>" without "en" / "hace" — throw, since direction
|
|
754
|
-
// is ambiguous. Matched AFTER the directional shapes so the
|
|
755
|
-
// directional ones win when their marker is present.
|
|
756
|
-
{
|
|
757
|
-
pattern: new RegExp(`^(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?$`, "i"),
|
|
758
|
-
resolve: (m, _ctx) => {
|
|
759
|
-
throw new Error(
|
|
760
|
-
`temporal-fmt: parseRelative no puede decidir si "${m[0]}" es pasado o futuro \u2014 usa "en ${m[1]} ${m[2]}s" o "hace ${m[1]} ${m[2]}s".`
|
|
761
|
-
);
|
|
762
|
-
}
|
|
763
|
-
},
|
|
764
|
-
// month-day: "5 de marzo" (day first), "5 de marzo de 2026" (year
|
|
765
|
-
// ignored if present). Day is 1-2 digits, with optional trailing
|
|
766
|
-
// "." (rare in Spanish but tolerated).
|
|
767
|
-
{
|
|
768
|
-
pattern: new RegExp(
|
|
769
|
-
`^(\\d{1,2})\\.?\\s+de\\s+(${nameAlternation([...SPANISH_MONTHS, ...SPANISH_MONTH_SHORT])})(?:\\s+de\\s+(\\d{4}))?$`,
|
|
770
|
-
"i"
|
|
771
|
-
),
|
|
772
|
-
resolve: (m, ctx) => {
|
|
773
|
-
const day = Number(m[1]);
|
|
774
|
-
const month = monthIndexFromName(m[2], SPANISH_MONTHS, SPANISH_MONTH_SHORT);
|
|
775
|
-
return resolveToNextOccurrence(ctx.temporal, ctx.reference, month, day);
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
]
|
|
779
|
-
};
|
|
780
|
-
var FRENCH_WEEKDAYS = ["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"];
|
|
781
|
-
var FRENCH_MONTHS = ["janvier", "f\xE9vrier", "mars", "avril", "mai", "juin", "juillet", "ao\xFBt", "septembre", "octobre", "novembre", "d\xE9cembre"];
|
|
782
|
-
var FRENCH_MONTH_SHORT = ["janv.", "f\xE9vr.", "mars", "avr.", "mai", "juin", "juil.", "ao\xFBt", "sept.", "oct.", "nov.", "d\xE9c."];
|
|
783
|
-
var FRENCH_GRAMMAR = {
|
|
784
|
-
supportedHint: `Phrases prises en charge : r\xE9f\xE9rences de jour de la semaine ("lundi prochain", "mardi dernier", "ce mercredi"), d\xE9calages de jour ("aujourd'hui"/"demain"/"hier"), d\xE9calages d'unit\xE9 ("dans 3 jours", "il y a 2 semaines"), et mois-jour ("5 mars").`,
|
|
785
|
-
matchers: [
|
|
786
|
-
{
|
|
787
|
-
pattern: /^aujourd'hui$/i,
|
|
788
|
-
resolve: (_m, ctx) => buildPlainDate(ctx.temporal, readYear(ctx.reference), readMonth(ctx.reference), readDay(ctx.reference))
|
|
789
|
-
},
|
|
790
|
-
{
|
|
791
|
-
pattern: /^demain$/i,
|
|
792
|
-
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, 1)
|
|
793
|
-
},
|
|
794
|
-
{
|
|
795
|
-
pattern: /^hier$/i,
|
|
796
|
-
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, -1)
|
|
797
|
-
},
|
|
798
|
-
// weekday references: "lundi prochain" (next), "lundi dernier"
|
|
799
|
-
// (last), "ce lundi" (this). The relative word follows the
|
|
800
|
-
// weekday for next/last, precedes it for this.
|
|
801
|
-
{
|
|
802
|
-
pattern: new RegExp(
|
|
803
|
-
`^(?:(${nameAlternation(FRENCH_WEEKDAYS)})\\s+(prochain|dernier)|ce\\s+(${nameAlternation(FRENCH_WEEKDAYS)}))$`,
|
|
804
|
-
"i"
|
|
805
|
-
),
|
|
806
|
-
resolve: (m, ctx) => {
|
|
807
|
-
let rel;
|
|
808
|
-
let weekdayName;
|
|
809
|
-
if (m[1] && m[2]) {
|
|
810
|
-
weekdayName = m[1];
|
|
811
|
-
rel = m[2].toLowerCase() === "prochain" ? "next" : "last";
|
|
812
|
-
} else {
|
|
813
|
-
rel = "this";
|
|
814
|
-
weekdayName = m[3];
|
|
815
|
-
}
|
|
816
|
-
const targetDow = weekdayIndexFromName(weekdayName, FRENCH_WEEKDAYS);
|
|
817
|
-
const refDow = extractDayOfWeek(ctx.reference);
|
|
818
|
-
return addDays2(ctx.temporal, ctx.reference, weekdayOffset(rel, refDow, targetDow));
|
|
819
|
-
}
|
|
820
|
-
},
|
|
821
|
-
// past: "il y a 2 semaines" — multi-word marker.
|
|
822
|
-
{
|
|
823
|
-
pattern: new RegExp(`^il\\s+y\\s+a\\s+(\\d+)\\s+(jour|semaine|mois|an|ann[e\xE9e]e)s?$`, "i"),
|
|
824
|
-
resolve: (m, ctx) => {
|
|
825
|
-
const count = Number(m[1]);
|
|
826
|
-
const unit = unitWordToEnglish(m[2]);
|
|
827
|
-
return addUnits(ctx.temporal, ctx.reference, -count, unit);
|
|
828
|
-
}
|
|
829
|
-
},
|
|
830
|
-
// future: "dans 3 jours"
|
|
831
|
-
{
|
|
832
|
-
pattern: new RegExp(`^dans\\s+(\\d+)\\s+(jour|semaine|mois|an|ann[e\xE9e]e)s?$`, "i"),
|
|
833
|
-
resolve: (m, ctx) => {
|
|
834
|
-
const count = Number(m[1]);
|
|
835
|
-
const unit = unitWordToEnglish(m[2]);
|
|
836
|
-
return addUnits(ctx.temporal, ctx.reference, count, unit);
|
|
837
|
-
}
|
|
838
|
-
},
|
|
839
|
-
// bare "N <unit>" without marker — throw.
|
|
840
|
-
{
|
|
841
|
-
pattern: new RegExp(`^(\\d+)\\s+(jour|semaine|mois|an|ann[e\xE9e]e)s?$`, "i"),
|
|
842
|
-
resolve: (m, _ctx) => {
|
|
843
|
-
throw new Error(
|
|
844
|
-
`temporal-fmt: parseRelative ne peut pas d\xE9terminer si "${m[0]}" est pass\xE9 ou futur \u2014 utilisez "dans ${m[1]} ${m[2]}s" ou "il y a ${m[1]} ${m[2]}s".`
|
|
845
|
-
);
|
|
846
|
-
}
|
|
847
|
-
},
|
|
848
|
-
// month-day: "5 mars" (day first, no separator word). Year ignored.
|
|
849
|
-
{
|
|
850
|
-
pattern: new RegExp(
|
|
851
|
-
`^(\\d{1,2})\\s+(${nameAlternation([...FRENCH_MONTHS, ...FRENCH_MONTH_SHORT])})(?:\\s+(\\d{4}))?$`,
|
|
852
|
-
"i"
|
|
853
|
-
),
|
|
854
|
-
resolve: (m, ctx) => {
|
|
855
|
-
const day = Number(m[1]);
|
|
856
|
-
const month = monthIndexFromName(m[2], FRENCH_MONTHS, FRENCH_MONTH_SHORT);
|
|
857
|
-
return resolveToNextOccurrence(ctx.temporal, ctx.reference, month, day);
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
]
|
|
861
|
-
};
|
|
862
|
-
var GERMAN_WEEKDAYS = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"];
|
|
863
|
-
var GERMAN_MONTHS = ["Januar", "Februar", "M\xE4rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"];
|
|
864
|
-
var GERMAN_MONTH_SHORT = ["Jan", "Feb", "M\xE4r", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"];
|
|
865
|
-
var GERMAN_GRAMMAR = {
|
|
866
|
-
supportedHint: 'Unterst\xFCtzte Phrasen: Wochentag-Bez\xFCge ("n\xE4chsten Dienstag", "letzten Freitag", "diesen Montag"), Tages-Offsets ("heute"/"morgen"/"gestern"), Einheiten-Offsets ("in 3 Tagen", "vor 2 Wochen"), und Monat-Tag ("5. M\xE4rz").',
|
|
867
|
-
matchers: [
|
|
868
|
-
{
|
|
869
|
-
pattern: /^heute$/i,
|
|
870
|
-
resolve: (_m, ctx) => buildPlainDate(ctx.temporal, readYear(ctx.reference), readMonth(ctx.reference), readDay(ctx.reference))
|
|
871
|
-
},
|
|
872
|
-
{
|
|
873
|
-
pattern: /^morgen$/i,
|
|
874
|
-
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, 1)
|
|
875
|
-
},
|
|
876
|
-
{
|
|
877
|
-
pattern: /^gestern$/i,
|
|
878
|
-
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, -1)
|
|
879
|
-
},
|
|
880
|
-
// weekday references: "nächsten Dienstag" (next), "letzten
|
|
881
|
-
// Dienstag" (last), "diesen Dienstag" (this). Adjective precedes
|
|
882
|
-
// the weekday; case varies (nächsten/letzten/diesen all take the
|
|
883
|
-
// weak-declension -en/-en/-en ending when no article, which is
|
|
884
|
-
// convenient — one regex alternation covers all three.
|
|
885
|
-
{
|
|
886
|
-
pattern: new RegExp(`^(n(?:ae|a|\xE4)chsten|letzten|diesen)\\s+(${nameAlternation(GERMAN_WEEKDAYS)})$`, "i"),
|
|
887
|
-
resolve: (m, ctx) => {
|
|
888
|
-
const adj = normalizeForMatch(m[1]);
|
|
889
|
-
const rel = adj === "nachsten" || adj === "naechsten" ? "next" : adj === "diesen" ? "this" : "last";
|
|
890
|
-
const targetDow = weekdayIndexFromName(m[2], GERMAN_WEEKDAYS);
|
|
891
|
-
const refDow = extractDayOfWeek(ctx.reference);
|
|
892
|
-
return addDays2(ctx.temporal, ctx.reference, weekdayOffset(rel, refDow, targetDow));
|
|
893
|
-
}
|
|
894
|
-
},
|
|
895
|
-
// past: "vor 2 Wochen"
|
|
896
|
-
{
|
|
897
|
-
pattern: new RegExp(`^vor\\s+(\\d+)\\s+(Tag(?:e|n|en)?|Woche(?:n)?|Monat(?:e|n|en)?|Jahr(?:e|n|en)?)$`, "i"),
|
|
898
|
-
resolve: (m, ctx) => {
|
|
899
|
-
const count = Number(m[1]);
|
|
900
|
-
const unit = unitWordToEnglish(m[2]);
|
|
901
|
-
return addUnits(ctx.temporal, ctx.reference, -count, unit);
|
|
902
|
-
}
|
|
903
|
-
},
|
|
904
|
-
// future: "in 3 Tagen"
|
|
905
|
-
{
|
|
906
|
-
pattern: new RegExp(`^in\\s+(\\d+)\\s+(Tag(?:e|n|en)?|Woche(?:n)?|Monat(?:e|n|en)?|Jahr(?:e|n|en)?)$`, "i"),
|
|
907
|
-
resolve: (m, ctx) => {
|
|
908
|
-
const count = Number(m[1]);
|
|
909
|
-
const unit = unitWordToEnglish(m[2]);
|
|
910
|
-
return addUnits(ctx.temporal, ctx.reference, count, unit);
|
|
911
|
-
}
|
|
912
|
-
},
|
|
913
|
-
// bare "N <unit>" without "in" or "vor" — throw.
|
|
914
|
-
{
|
|
915
|
-
pattern: new RegExp(`^(\\d+)\\s+(Tag(?:e|n|en)?|Woche(?:n)?|Monat(?:e|n|en)?|Jahr(?:e|n|en)?)$`, "i"),
|
|
916
|
-
resolve: (m, _ctx) => {
|
|
917
|
-
throw new Error(
|
|
918
|
-
`temporal-fmt: parseRelative kann nicht erkennen, ob "${m[0]}" Vergangenheit oder Zukunft ist \u2014 verwende "in ${m[1]} ${m[2]}" oder "vor ${m[1]} ${m[2]}".`
|
|
919
|
-
);
|
|
920
|
-
}
|
|
921
|
-
},
|
|
922
|
-
// month-day: "5. März" (day-first with period). Year ignored.
|
|
923
|
-
{
|
|
924
|
-
pattern: new RegExp(
|
|
925
|
-
`^(\\d{1,2})\\.?\\s+(${nameAlternation([...GERMAN_MONTHS, ...GERMAN_MONTH_SHORT, "Maerz", "Maer"])})(?:\\s+(\\d{4}))?$`,
|
|
926
|
-
"i"
|
|
927
|
-
),
|
|
928
|
-
resolve: (m, ctx) => {
|
|
929
|
-
const day = Number(m[1]);
|
|
930
|
-
const month = monthIndexFromName(m[2], GERMAN_MONTHS, GERMAN_MONTH_SHORT);
|
|
931
|
-
return resolveToNextOccurrence(ctx.temporal, ctx.reference, month, day);
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
]
|
|
935
|
-
};
|
|
936
|
-
var GRAMMARS = {
|
|
937
|
-
en: ENGLISH_GRAMMAR,
|
|
938
|
-
es: SPANISH_GRAMMAR,
|
|
939
|
-
fr: FRENCH_GRAMMAR,
|
|
940
|
-
de: GERMAN_GRAMMAR
|
|
941
|
-
};
|
|
942
|
-
function grammarForLocale(locale) {
|
|
943
|
-
if (!locale) return ENGLISH_GRAMMAR;
|
|
944
|
-
try {
|
|
945
|
-
const tag = new Intl.Locale(locale.replace(/_/g, "-"));
|
|
946
|
-
const lang = tag.language.toLowerCase();
|
|
947
|
-
return GRAMMARS[lang] ?? ENGLISH_GRAMMAR;
|
|
948
|
-
} catch {
|
|
949
|
-
return ENGLISH_GRAMMAR;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
function unitWordToEnglish(word) {
|
|
953
|
-
const w = normalizeForMatch(word);
|
|
954
|
-
if (w === "day" || w === "week" || w === "month" || w === "year") return w;
|
|
955
|
-
if (w === "dia") return "day";
|
|
956
|
-
if (w === "semana") return "week";
|
|
957
|
-
if (w === "mes") return "month";
|
|
958
|
-
if (w === "ano" || w === "a\xF1o") return "year";
|
|
959
|
-
if (w === "jour") return "day";
|
|
960
|
-
if (w === "semaine") return "week";
|
|
961
|
-
if (w === "mois") return "month";
|
|
962
|
-
if (w === "an" || w === "annee") return "year";
|
|
963
|
-
if (w === "tag" || w === "tagen") return "day";
|
|
964
|
-
if (w === "woche" || w === "wochen") return "week";
|
|
965
|
-
if (w === "monat" || w === "monaten") return "month";
|
|
966
|
-
if (w === "jahr" || w === "jahren") return "year";
|
|
967
|
-
/* c8 ignore start @preserve -- unreachable: every caller passes a word
|
|
968
|
-
* captured by a regex alternation built from exactly these unit-word
|
|
969
|
-
* forms (day/week/month/year across en/es/fr/de), so the branches
|
|
970
|
-
* above already cover every string that can reach this function.
|
|
971
|
-
* Kept as a tripwire for the type checker in case a grammar adds a
|
|
972
|
-
* unit word here without a matching regex update. */
|
|
973
|
-
throw new Error(`temporal-fmt: parseRelative internal error \u2014 unrecognized unit word "${word}".`);
|
|
974
|
-
/* c8 ignore stop @preserve */
|
|
975
|
-
}
|
|
976
|
-
function parseRelative(input, referenceDate, options = {}) {
|
|
977
|
-
const reference = referenceDate;
|
|
978
|
-
const temporal = getTemporal();
|
|
979
|
-
const trimmed = (input ?? "").trim().replace(/\s+/g, " ");
|
|
980
|
-
if (trimmed.length === 0) {
|
|
981
|
-
throw new Error("temporal-fmt: parseRelative got an empty input string.");
|
|
982
|
-
}
|
|
983
|
-
if (trimmed.length > MAX_RELATIVE_INPUT_LENGTH) {
|
|
984
|
-
throw new RangeError(
|
|
985
|
-
`temporal-fmt: parseRelative input is too large (maximum ${MAX_RELATIVE_INPUT_LENGTH} characters).`
|
|
986
|
-
);
|
|
987
|
-
}
|
|
988
|
-
const normalized = normalizeForMatch(trimmed);
|
|
989
|
-
const grammar = grammarForLocale(options.locale);
|
|
990
|
-
const ctx = { temporal, reference };
|
|
991
|
-
const tryMatch = (text) => {
|
|
992
|
-
for (const matcher of grammar.matchers) {
|
|
993
|
-
const match = text.match(matcher.pattern);
|
|
994
|
-
if (match) {
|
|
995
|
-
return matcher.resolve(match, ctx);
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
return NO_MATCH;
|
|
999
|
-
};
|
|
1000
|
-
const exactResult = tryMatch(normalized);
|
|
1001
|
-
if (exactResult !== NO_MATCH) {
|
|
1002
|
-
return exactResult;
|
|
1003
|
-
}
|
|
1004
|
-
if (options.fuzzy) {
|
|
1005
|
-
if (grammar !== ENGLISH_GRAMMAR) {
|
|
1006
|
-
throw new Error(
|
|
1007
|
-
`temporal-fmt: parseRelative's { fuzzy: true } option currently only supports English. Pass no locale (or locale: 'en'), or omit { fuzzy: true } for this locale.`
|
|
1008
|
-
);
|
|
1009
|
-
}
|
|
1010
|
-
const corrected = fuzzyCorrectEnglish(normalized);
|
|
1011
|
-
if (corrected !== void 0) {
|
|
1012
|
-
const fuzzyResult = tryMatch(corrected);
|
|
1013
|
-
if (fuzzyResult !== NO_MATCH) {
|
|
1014
|
-
return fuzzyResult;
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
throw new Error(
|
|
1019
|
-
`temporal-fmt: parseRelative doesn't recognize "${trimmed}". ` + grammar.supportedHint
|
|
1020
|
-
);
|
|
1021
|
-
}
|
|
1022
|
-
var NO_MATCH = /* @__PURE__ */ Symbol("temporal-fmt: parseRelative no match");
|
|
1023
|
-
|
|
1024
|
-
// src/typeGuards.ts
|
|
1025
|
-
function isObject(v) {
|
|
1026
|
-
return typeof v === "object" && v !== null;
|
|
1027
|
-
}
|
|
1028
|
-
function hasMethod(v, name) {
|
|
1029
|
-
return typeof v[name] === "function";
|
|
1030
|
-
}
|
|
1031
|
-
function hasTag(value, typeName) {
|
|
1032
|
-
if (!isObject(value)) return false;
|
|
1033
|
-
const tag = value[Symbol.toStringTag];
|
|
1034
|
-
return tag === `Temporal.${typeName}`;
|
|
1035
|
-
}
|
|
1036
|
-
function isPlainDate(value) {
|
|
1037
|
-
if (hasTag(value, "PlainDate")) return true;
|
|
1038
|
-
if (!isObject(value)) return false;
|
|
1039
|
-
const v = value;
|
|
1040
|
-
return typeof v.year === "number" && typeof v.month === "number" && typeof v.day === "number" && typeof v.hour === "undefined" && hasMethod(v, "toPlainDateTime") && hasMethod(v, "withCalendar");
|
|
1041
|
-
}
|
|
1042
|
-
function isPlainTime(value) {
|
|
1043
|
-
if (hasTag(value, "PlainTime")) return true;
|
|
1044
|
-
if (!isObject(value)) return false;
|
|
1045
|
-
const v = value;
|
|
1046
|
-
return typeof v.hour === "number" && typeof v.year === "undefined" && !hasMethod(v, "withCalendar") && !hasMethod(v, "toPlainDate") && !hasMethod(v, "toPlainDateTime");
|
|
1047
|
-
}
|
|
1048
|
-
function isPlainDateTime(value) {
|
|
1049
|
-
if (hasTag(value, "PlainDateTime")) return true;
|
|
1050
|
-
if (!isObject(value)) return false;
|
|
1051
|
-
const v = value;
|
|
1052
|
-
return typeof v.year === "number" && typeof v.month === "number" && typeof v.day === "number" && typeof v.hour === "number" && hasMethod(v, "withPlainTime") && !hasMethod(v, "toInstant");
|
|
1053
|
-
}
|
|
1054
|
-
function isZonedDateTime(value) {
|
|
1055
|
-
if (hasTag(value, "ZonedDateTime")) return true;
|
|
1056
|
-
if (!isObject(value)) return false;
|
|
1057
|
-
const v = value;
|
|
1058
|
-
return typeof v.year === "number" && typeof v.month === "number" && typeof v.day === "number" && typeof v.hour === "number" && hasMethod(v, "withTimeZone") && hasMethod(v, "toInstant");
|
|
1059
|
-
}
|
|
1060
|
-
function isInstant(value) {
|
|
1061
|
-
if (hasTag(value, "Instant")) return true;
|
|
1062
|
-
if (!isObject(value)) return false;
|
|
1063
|
-
const v = value;
|
|
1064
|
-
return hasMethod(v, "toZonedDateTimeISO") && !hasMethod(v, "toInstant") && typeof v.year === "undefined";
|
|
1065
|
-
}
|
|
1066
|
-
function isPlainYearMonth(value) {
|
|
1067
|
-
if (hasTag(value, "PlainYearMonth")) return true;
|
|
1068
|
-
if (!isObject(value)) return false;
|
|
1069
|
-
const v = value;
|
|
1070
|
-
return typeof v.year === "number" && typeof v.month === "number" && typeof v.day === "undefined" && hasMethod(v, "toPlainDate");
|
|
1071
|
-
}
|
|
1072
|
-
function isPlainMonthDay(value) {
|
|
1073
|
-
if (hasTag(value, "PlainMonthDay")) return true;
|
|
1074
|
-
if (!isObject(value)) return false;
|
|
1075
|
-
const v = value;
|
|
1076
|
-
return typeof v.year === "undefined" && typeof v.month === "undefined" && typeof v.day === "number" && typeof v.monthCode === "string" && hasMethod(v, "toPlainDate");
|
|
1077
|
-
}
|
|
1078
|
-
function isDuration(value) {
|
|
1079
|
-
if (hasTag(value, "Duration")) return true;
|
|
1080
|
-
if (!isObject(value)) return false;
|
|
1081
|
-
const v = value;
|
|
1082
|
-
return hasMethod(v, "total");
|
|
1083
|
-
}
|
|
1084
|
-
function isTemporal(value) {
|
|
1085
|
-
if (!isObject(value)) return false;
|
|
1086
|
-
const tag = value[Symbol.toStringTag];
|
|
1087
|
-
if (typeof tag === "string" && tag.startsWith("Temporal.")) return true;
|
|
1088
|
-
const v = value;
|
|
1089
|
-
return hasMethod(v, "toInstant") || hasMethod(v, "toPlainDate") || hasMethod(v, "toPlainDateTime") || hasMethod(v, "toPlainTime") || hasMethod(v, "toPlainYearMonth") || hasMethod(v, "toPlainMonthDay") || hasMethod(v, "toZonedDateTime") || hasMethod(v, "toZonedDateTimeISO") || hasMethod(v, "withCalendar") || hasMethod(v, "withPlainTime") || hasMethod(v, "withTimeZone") || hasMethod(v, "total");
|
|
1090
|
-
}
|
|
1091
|
-
function describeValue(value) {
|
|
1092
|
-
if (value === null) return "null";
|
|
1093
|
-
if (Array.isArray(value)) return "array";
|
|
1094
|
-
if (typeof value === "object") {
|
|
1095
|
-
const ctor = value.constructor;
|
|
1096
|
-
if (ctor && typeof ctor.name === "string" && ctor.name !== "Object") {
|
|
1097
|
-
return `instance of ${ctor.name}`;
|
|
1098
|
-
}
|
|
1099
|
-
return "plain object";
|
|
1100
|
-
}
|
|
1101
|
-
return typeof value;
|
|
1102
|
-
}
|
|
1103
|
-
function assertImpl(value, guard, expectedType) {
|
|
1104
|
-
if (!guard(value)) {
|
|
1105
|
-
throw new Error(
|
|
1106
|
-
`temporal-fmt: expected a Temporal.${expectedType}, got ${describeValue(value)}.`
|
|
1107
|
-
);
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
function assertTemporal(value) {
|
|
1111
|
-
assertImpl(value, isTemporal, "object (Instant, PlainDate, PlainTime, PlainDateTime, ZonedDateTime, Duration, PlainYearMonth, or PlainMonthDay)");
|
|
1112
|
-
}
|
|
1113
|
-
function assertInstant(value) {
|
|
1114
|
-
assertImpl(value, isInstant, "Instant");
|
|
1115
|
-
}
|
|
1116
|
-
function assertPlainDate(value) {
|
|
1117
|
-
assertImpl(value, isPlainDate, "PlainDate");
|
|
1118
|
-
}
|
|
1119
|
-
function assertPlainTime(value) {
|
|
1120
|
-
assertImpl(value, isPlainTime, "PlainTime");
|
|
1121
|
-
}
|
|
1122
|
-
function assertPlainDateTime(value) {
|
|
1123
|
-
assertImpl(value, isPlainDateTime, "PlainDateTime");
|
|
1124
|
-
}
|
|
1125
|
-
function assertZonedDateTime(value) {
|
|
1126
|
-
assertImpl(value, isZonedDateTime, "ZonedDateTime");
|
|
1127
|
-
}
|
|
1128
|
-
function assertPlainYearMonth(value) {
|
|
1129
|
-
assertImpl(value, isPlainYearMonth, "PlainYearMonth");
|
|
1130
|
-
}
|
|
1131
|
-
function assertPlainMonthDay(value) {
|
|
1132
|
-
assertImpl(value, isPlainMonthDay, "PlainMonthDay");
|
|
1133
|
-
}
|
|
1134
|
-
function assertDuration(value) {
|
|
1135
|
-
assertImpl(value, isDuration, "Duration");
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
// src/tokenMetadata.ts
|
|
1139
|
-
var TYPES_WITH = {
|
|
1140
|
-
year: ["PlainDate", "PlainDateTime", "ZonedDateTime", "PlainYearMonth"],
|
|
1141
|
-
month: ["PlainDate", "PlainDateTime", "ZonedDateTime", "PlainYearMonth", "PlainMonthDay"],
|
|
1142
|
-
day: ["PlainDate", "PlainDateTime", "ZonedDateTime", "PlainMonthDay"],
|
|
1143
|
-
hour: ["PlainTime", "PlainDateTime", "ZonedDateTime", "Instant"],
|
|
1144
|
-
minute: ["PlainTime", "PlainDateTime", "ZonedDateTime", "Instant"],
|
|
1145
|
-
second: ["PlainTime", "PlainDateTime", "ZonedDateTime", "Instant"],
|
|
1146
|
-
millisecond: ["PlainTime", "PlainDateTime", "ZonedDateTime", "Instant"],
|
|
1147
|
-
dayOfWeek: ["PlainDate", "PlainDateTime", "ZonedDateTime"],
|
|
1148
|
-
timeZoneId: ["ZonedDateTime"],
|
|
1149
|
-
offset: ["ZonedDateTime"]
|
|
1150
|
-
};
|
|
1151
|
-
var TOKEN_METADATA = {
|
|
1152
|
-
yyyy: {
|
|
1153
|
-
meaning: "Four-digit year (preserves sign for BCE; no truncation).",
|
|
1154
|
-
formatCapable: true,
|
|
1155
|
-
parseCapable: true,
|
|
1156
|
-
localeSensitive: false,
|
|
1157
|
-
calendarSensitive: true,
|
|
1158
|
-
timezoneSensitive: false,
|
|
1159
|
-
supportedTypes: TYPES_WITH.year,
|
|
1160
|
-
roundTripSafe: true
|
|
1161
|
-
},
|
|
1162
|
-
yy: {
|
|
1163
|
-
meaning: "Two-digit year (year % 100). Throws on negative years.",
|
|
1164
|
-
formatCapable: true,
|
|
1165
|
-
parseCapable: true,
|
|
1166
|
-
localeSensitive: false,
|
|
1167
|
-
calendarSensitive: true,
|
|
1168
|
-
timezoneSensitive: false,
|
|
1169
|
-
supportedTypes: TYPES_WITH.year,
|
|
1170
|
-
roundTripSafe: false
|
|
1171
|
-
},
|
|
1172
|
-
MMMM: {
|
|
1173
|
-
meaning: 'Long month name (locale-aware, e.g. "January", "janvier").',
|
|
1174
|
-
formatCapable: true,
|
|
1175
|
-
parseCapable: true,
|
|
1176
|
-
localeSensitive: true,
|
|
1177
|
-
calendarSensitive: true,
|
|
1178
|
-
timezoneSensitive: false,
|
|
1179
|
-
supportedTypes: TYPES_WITH.month,
|
|
1180
|
-
roundTripSafe: true
|
|
1181
|
-
},
|
|
1182
|
-
MMM: {
|
|
1183
|
-
meaning: 'Short month name (locale-aware, e.g. "Jan", "janv.").',
|
|
1184
|
-
formatCapable: true,
|
|
1185
|
-
parseCapable: true,
|
|
1186
|
-
localeSensitive: true,
|
|
1187
|
-
calendarSensitive: true,
|
|
1188
|
-
timezoneSensitive: false,
|
|
1189
|
-
supportedTypes: TYPES_WITH.month,
|
|
1190
|
-
roundTripSafe: true
|
|
1191
|
-
},
|
|
1192
|
-
MM: {
|
|
1193
|
-
meaning: "Two-digit month (01-12, zero-padded).",
|
|
1194
|
-
formatCapable: true,
|
|
1195
|
-
parseCapable: true,
|
|
1196
|
-
localeSensitive: false,
|
|
1197
|
-
calendarSensitive: true,
|
|
1198
|
-
timezoneSensitive: false,
|
|
1199
|
-
supportedTypes: TYPES_WITH.month,
|
|
1200
|
-
roundTripSafe: true
|
|
1201
|
-
},
|
|
1202
|
-
M: {
|
|
1203
|
-
meaning: "One- or two-digit month (1-12, no padding).",
|
|
1204
|
-
formatCapable: true,
|
|
1205
|
-
parseCapable: true,
|
|
1206
|
-
localeSensitive: false,
|
|
1207
|
-
calendarSensitive: true,
|
|
1208
|
-
timezoneSensitive: false,
|
|
1209
|
-
supportedTypes: TYPES_WITH.month,
|
|
1210
|
-
roundTripSafe: true
|
|
1211
|
-
},
|
|
1212
|
-
dd: {
|
|
1213
|
-
meaning: "Two-digit day-of-month (01-31, zero-padded).",
|
|
1214
|
-
formatCapable: true,
|
|
1215
|
-
parseCapable: true,
|
|
1216
|
-
localeSensitive: false,
|
|
1217
|
-
calendarSensitive: true,
|
|
1218
|
-
timezoneSensitive: false,
|
|
1219
|
-
supportedTypes: TYPES_WITH.day,
|
|
1220
|
-
roundTripSafe: true
|
|
1221
|
-
},
|
|
1222
|
-
d: {
|
|
1223
|
-
meaning: "One- or two-digit day-of-month (1-31, no padding).",
|
|
1224
|
-
formatCapable: true,
|
|
1225
|
-
parseCapable: true,
|
|
1226
|
-
localeSensitive: false,
|
|
1227
|
-
calendarSensitive: true,
|
|
1228
|
-
timezoneSensitive: false,
|
|
1229
|
-
supportedTypes: TYPES_WITH.day,
|
|
1230
|
-
roundTripSafe: true
|
|
1231
|
-
},
|
|
1232
|
-
EEEE: {
|
|
1233
|
-
meaning: 'Long weekday name (locale-aware, e.g. "Monday", "lundi"). Parse cross-checks against the parsed date.',
|
|
1234
|
-
formatCapable: true,
|
|
1235
|
-
parseCapable: true,
|
|
1236
|
-
localeSensitive: true,
|
|
1237
|
-
calendarSensitive: true,
|
|
1238
|
-
timezoneSensitive: false,
|
|
1239
|
-
supportedTypes: TYPES_WITH.dayOfWeek,
|
|
1240
|
-
roundTripSafe: true
|
|
1241
|
-
},
|
|
1242
|
-
EEE: {
|
|
1243
|
-
meaning: 'Short weekday name (locale-aware, e.g. "Mon", "lun."). Parse cross-checks against the parsed date.',
|
|
1244
|
-
formatCapable: true,
|
|
1245
|
-
parseCapable: true,
|
|
1246
|
-
localeSensitive: true,
|
|
1247
|
-
calendarSensitive: true,
|
|
1248
|
-
timezoneSensitive: false,
|
|
1249
|
-
supportedTypes: TYPES_WITH.dayOfWeek,
|
|
1250
|
-
roundTripSafe: true
|
|
1251
|
-
},
|
|
1252
|
-
HH: {
|
|
1253
|
-
meaning: "Two-digit hour, 24-hour clock (00-23, zero-padded).",
|
|
1254
|
-
formatCapable: true,
|
|
1255
|
-
parseCapable: true,
|
|
1256
|
-
localeSensitive: false,
|
|
1257
|
-
calendarSensitive: false,
|
|
1258
|
-
timezoneSensitive: false,
|
|
1259
|
-
supportedTypes: TYPES_WITH.hour,
|
|
1260
|
-
roundTripSafe: true
|
|
1261
|
-
},
|
|
1262
|
-
H: {
|
|
1263
|
-
meaning: "One- or two-digit hour, 24-hour clock (0-23, no padding).",
|
|
1264
|
-
formatCapable: true,
|
|
1265
|
-
parseCapable: true,
|
|
1266
|
-
localeSensitive: false,
|
|
1267
|
-
calendarSensitive: false,
|
|
1268
|
-
timezoneSensitive: false,
|
|
1269
|
-
supportedTypes: TYPES_WITH.hour,
|
|
1270
|
-
roundTripSafe: true
|
|
1271
|
-
},
|
|
1272
|
-
hh: {
|
|
1273
|
-
meaning: "Two-digit hour, 12-hour clock (01-12, zero-padded). Requires `a` token on parse.",
|
|
1274
|
-
formatCapable: true,
|
|
1275
|
-
parseCapable: true,
|
|
1276
|
-
localeSensitive: false,
|
|
1277
|
-
calendarSensitive: false,
|
|
1278
|
-
timezoneSensitive: false,
|
|
1279
|
-
supportedTypes: TYPES_WITH.hour,
|
|
1280
|
-
roundTripSafe: true
|
|
1281
|
-
},
|
|
1282
|
-
h: {
|
|
1283
|
-
meaning: "One- or two-digit hour, 12-hour clock (1-12, no padding). Requires `a` token on parse.",
|
|
1284
|
-
formatCapable: true,
|
|
1285
|
-
parseCapable: true,
|
|
1286
|
-
localeSensitive: false,
|
|
1287
|
-
calendarSensitive: false,
|
|
1288
|
-
timezoneSensitive: false,
|
|
1289
|
-
supportedTypes: TYPES_WITH.hour,
|
|
1290
|
-
roundTripSafe: true
|
|
1291
|
-
},
|
|
1292
|
-
mm: {
|
|
1293
|
-
meaning: "Two-digit minute (00-59, zero-padded).",
|
|
1294
|
-
formatCapable: true,
|
|
1295
|
-
parseCapable: true,
|
|
1296
|
-
localeSensitive: false,
|
|
1297
|
-
calendarSensitive: false,
|
|
1298
|
-
timezoneSensitive: false,
|
|
1299
|
-
supportedTypes: TYPES_WITH.minute,
|
|
1300
|
-
roundTripSafe: true
|
|
1301
|
-
},
|
|
1302
|
-
m: {
|
|
1303
|
-
meaning: "One- or two-digit minute (0-59, no padding).",
|
|
1304
|
-
formatCapable: true,
|
|
1305
|
-
parseCapable: true,
|
|
1306
|
-
localeSensitive: false,
|
|
1307
|
-
calendarSensitive: false,
|
|
1308
|
-
timezoneSensitive: false,
|
|
1309
|
-
supportedTypes: TYPES_WITH.minute,
|
|
1310
|
-
roundTripSafe: true
|
|
1311
|
-
},
|
|
1312
|
-
ss: {
|
|
1313
|
-
meaning: "Two-digit second (00-59, zero-padded).",
|
|
1314
|
-
formatCapable: true,
|
|
1315
|
-
parseCapable: true,
|
|
1316
|
-
localeSensitive: false,
|
|
1317
|
-
calendarSensitive: false,
|
|
1318
|
-
timezoneSensitive: false,
|
|
1319
|
-
supportedTypes: TYPES_WITH.second,
|
|
1320
|
-
roundTripSafe: true
|
|
1321
|
-
},
|
|
1322
|
-
s: {
|
|
1323
|
-
meaning: "One- or two-digit second (0-59, no padding).",
|
|
1324
|
-
formatCapable: true,
|
|
1325
|
-
parseCapable: true,
|
|
1326
|
-
localeSensitive: false,
|
|
1327
|
-
calendarSensitive: false,
|
|
1328
|
-
timezoneSensitive: false,
|
|
1329
|
-
supportedTypes: TYPES_WITH.second,
|
|
1330
|
-
roundTripSafe: true
|
|
1331
|
-
},
|
|
1332
|
-
S: {
|
|
1333
|
-
meaning: "Fractional second, 1 digit (tenths of a second).",
|
|
1334
|
-
formatCapable: true,
|
|
1335
|
-
parseCapable: true,
|
|
1336
|
-
localeSensitive: false,
|
|
1337
|
-
calendarSensitive: false,
|
|
1338
|
-
timezoneSensitive: false,
|
|
1339
|
-
supportedTypes: TYPES_WITH.millisecond,
|
|
1340
|
-
roundTripSafe: true
|
|
1341
|
-
},
|
|
1342
|
-
SS: {
|
|
1343
|
-
meaning: "Fractional second, 2 digits (hundredths of a second).",
|
|
1344
|
-
formatCapable: true,
|
|
1345
|
-
parseCapable: true,
|
|
1346
|
-
localeSensitive: false,
|
|
1347
|
-
calendarSensitive: false,
|
|
1348
|
-
timezoneSensitive: false,
|
|
1349
|
-
supportedTypes: TYPES_WITH.millisecond,
|
|
1350
|
-
roundTripSafe: true
|
|
1351
|
-
},
|
|
1352
|
-
SSS: {
|
|
1353
|
-
meaning: "Fractional second, 3 digits (milliseconds).",
|
|
1354
|
-
formatCapable: true,
|
|
1355
|
-
parseCapable: true,
|
|
1356
|
-
localeSensitive: false,
|
|
1357
|
-
calendarSensitive: false,
|
|
1358
|
-
timezoneSensitive: false,
|
|
1359
|
-
supportedTypes: TYPES_WITH.millisecond,
|
|
1360
|
-
roundTripSafe: true
|
|
1361
|
-
},
|
|
1362
|
-
SSSS: {
|
|
1363
|
-
meaning: "Fractional second, 4 digits (tens of microseconds).",
|
|
1364
|
-
formatCapable: true,
|
|
1365
|
-
parseCapable: true,
|
|
1366
|
-
localeSensitive: false,
|
|
1367
|
-
calendarSensitive: false,
|
|
1368
|
-
timezoneSensitive: false,
|
|
1369
|
-
supportedTypes: TYPES_WITH.millisecond,
|
|
1370
|
-
roundTripSafe: true
|
|
1371
|
-
},
|
|
1372
|
-
SSSSS: {
|
|
1373
|
-
meaning: "Fractional second, 5 digits (hundred-thousandths of a second).",
|
|
1374
|
-
formatCapable: true,
|
|
1375
|
-
parseCapable: true,
|
|
1376
|
-
localeSensitive: false,
|
|
1377
|
-
calendarSensitive: false,
|
|
1378
|
-
timezoneSensitive: false,
|
|
1379
|
-
supportedTypes: TYPES_WITH.millisecond,
|
|
1380
|
-
roundTripSafe: true
|
|
1381
|
-
},
|
|
1382
|
-
SSSSSS: {
|
|
1383
|
-
meaning: "Fractional second, 6 digits (microseconds).",
|
|
1384
|
-
formatCapable: true,
|
|
1385
|
-
parseCapable: true,
|
|
1386
|
-
localeSensitive: false,
|
|
1387
|
-
calendarSensitive: false,
|
|
1388
|
-
timezoneSensitive: false,
|
|
1389
|
-
supportedTypes: TYPES_WITH.millisecond,
|
|
1390
|
-
roundTripSafe: true
|
|
1391
|
-
},
|
|
1392
|
-
SSSSSSS: {
|
|
1393
|
-
meaning: "Fractional second, 7 digits (tens of nanoseconds).",
|
|
1394
|
-
formatCapable: true,
|
|
1395
|
-
parseCapable: true,
|
|
1396
|
-
localeSensitive: false,
|
|
1397
|
-
calendarSensitive: false,
|
|
1398
|
-
timezoneSensitive: false,
|
|
1399
|
-
supportedTypes: TYPES_WITH.millisecond,
|
|
1400
|
-
roundTripSafe: true
|
|
1401
|
-
},
|
|
1402
|
-
SSSSSSSS: {
|
|
1403
|
-
meaning: "Fractional second, 8 digits (hundred-millionths of a second).",
|
|
1404
|
-
formatCapable: true,
|
|
1405
|
-
parseCapable: true,
|
|
1406
|
-
localeSensitive: false,
|
|
1407
|
-
calendarSensitive: false,
|
|
1408
|
-
timezoneSensitive: false,
|
|
1409
|
-
supportedTypes: TYPES_WITH.millisecond,
|
|
1410
|
-
roundTripSafe: true
|
|
1411
|
-
},
|
|
1412
|
-
SSSSSSSSS: {
|
|
1413
|
-
meaning: "Fractional second, 9 digits (nanoseconds).",
|
|
1414
|
-
formatCapable: true,
|
|
1415
|
-
parseCapable: true,
|
|
1416
|
-
localeSensitive: false,
|
|
1417
|
-
calendarSensitive: false,
|
|
1418
|
-
timezoneSensitive: false,
|
|
1419
|
-
supportedTypes: TYPES_WITH.millisecond,
|
|
1420
|
-
roundTripSafe: true
|
|
1421
|
-
},
|
|
1422
|
-
a: {
|
|
1423
|
-
meaning: 'Day period (locale-aware: "AM"/"PM", "\u5348\u524D"/"\u5348\u5F8C", etc.). Required alongside 12-hour tokens on parse.',
|
|
1424
|
-
formatCapable: true,
|
|
1425
|
-
parseCapable: true,
|
|
1426
|
-
localeSensitive: true,
|
|
1427
|
-
calendarSensitive: false,
|
|
1428
|
-
timezoneSensitive: false,
|
|
1429
|
-
supportedTypes: TYPES_WITH.hour,
|
|
1430
|
-
roundTripSafe: true
|
|
1431
|
-
},
|
|
1432
|
-
zzz: {
|
|
1433
|
-
meaning: 'IANA time zone id (e.g. "America/New_York") or fixed offset ("+05:30"). Requires full date+time on parse.',
|
|
1434
|
-
formatCapable: true,
|
|
1435
|
-
parseCapable: true,
|
|
1436
|
-
localeSensitive: false,
|
|
1437
|
-
calendarSensitive: false,
|
|
1438
|
-
timezoneSensitive: true,
|
|
1439
|
-
supportedTypes: TYPES_WITH.timeZoneId,
|
|
1440
|
-
roundTripSafe: true
|
|
1441
|
-
},
|
|
1442
|
-
X: {
|
|
1443
|
-
meaning: "Numeric UTC offset, short (Z for UTC, \xB1HH[MM] otherwise). Minutes omitted when zero.",
|
|
1444
|
-
formatCapable: true,
|
|
1445
|
-
parseCapable: true,
|
|
1446
|
-
localeSensitive: false,
|
|
1447
|
-
calendarSensitive: false,
|
|
1448
|
-
timezoneSensitive: true,
|
|
1449
|
-
supportedTypes: TYPES_WITH.offset,
|
|
1450
|
-
roundTripSafe: true
|
|
1451
|
-
},
|
|
1452
|
-
XX: {
|
|
1453
|
-
meaning: "Numeric UTC offset, no colon (Z for UTC, \xB1HHMM otherwise).",
|
|
1454
|
-
formatCapable: true,
|
|
1455
|
-
parseCapable: true,
|
|
1456
|
-
localeSensitive: false,
|
|
1457
|
-
calendarSensitive: false,
|
|
1458
|
-
timezoneSensitive: true,
|
|
1459
|
-
supportedTypes: TYPES_WITH.offset,
|
|
1460
|
-
roundTripSafe: true
|
|
1461
|
-
},
|
|
1462
|
-
XXX: {
|
|
1463
|
-
meaning: "Numeric UTC offset, with colon (Z for UTC, \xB1HH:MM otherwise).",
|
|
1464
|
-
formatCapable: true,
|
|
1465
|
-
parseCapable: true,
|
|
1466
|
-
localeSensitive: false,
|
|
1467
|
-
calendarSensitive: false,
|
|
1468
|
-
timezoneSensitive: true,
|
|
1469
|
-
supportedTypes: TYPES_WITH.offset,
|
|
1470
|
-
roundTripSafe: true
|
|
1471
|
-
},
|
|
1472
|
-
x: {
|
|
1473
|
-
meaning: "Numeric UTC offset, short, never Z (always \xB1HH[MM]). Lowercase variant of X.",
|
|
1474
|
-
formatCapable: true,
|
|
1475
|
-
parseCapable: true,
|
|
1476
|
-
localeSensitive: false,
|
|
1477
|
-
calendarSensitive: false,
|
|
1478
|
-
timezoneSensitive: true,
|
|
1479
|
-
supportedTypes: TYPES_WITH.offset,
|
|
1480
|
-
roundTripSafe: true
|
|
1481
|
-
},
|
|
1482
|
-
xx: {
|
|
1483
|
-
meaning: "Numeric UTC offset, no colon, never Z (always \xB1HHMM). Lowercase variant of XX.",
|
|
1484
|
-
formatCapable: true,
|
|
1485
|
-
parseCapable: true,
|
|
1486
|
-
localeSensitive: false,
|
|
1487
|
-
calendarSensitive: false,
|
|
1488
|
-
timezoneSensitive: true,
|
|
1489
|
-
supportedTypes: TYPES_WITH.offset,
|
|
1490
|
-
roundTripSafe: true
|
|
1491
|
-
},
|
|
1492
|
-
xxx: {
|
|
1493
|
-
meaning: "Numeric UTC offset, with colon, never Z (always \xB1HH:MM). Lowercase variant of XXX.",
|
|
1494
|
-
formatCapable: true,
|
|
1495
|
-
parseCapable: true,
|
|
1496
|
-
localeSensitive: false,
|
|
1497
|
-
calendarSensitive: false,
|
|
1498
|
-
timezoneSensitive: true,
|
|
1499
|
-
supportedTypes: TYPES_WITH.offset,
|
|
1500
|
-
roundTripSafe: true
|
|
1501
|
-
},
|
|
1502
|
-
do: {
|
|
1503
|
-
meaning: 'Ordinal day-of-month with English suffix ("1st", "2nd", "3rd", "4th", ... 21st, 22nd, ...). Format-only \u2014 not parseable.',
|
|
1504
|
-
formatCapable: true,
|
|
1505
|
-
parseCapable: false,
|
|
1506
|
-
localeSensitive: false,
|
|
1507
|
-
calendarSensitive: true,
|
|
1508
|
-
timezoneSensitive: false,
|
|
1509
|
-
supportedTypes: TYPES_WITH.day,
|
|
1510
|
-
roundTripSafe: false
|
|
1511
|
-
},
|
|
1512
|
-
Q: {
|
|
1513
|
-
meaning: "Quarter as a digit (1-4). Derived from month.",
|
|
1514
|
-
formatCapable: true,
|
|
1515
|
-
parseCapable: true,
|
|
1516
|
-
localeSensitive: false,
|
|
1517
|
-
calendarSensitive: true,
|
|
1518
|
-
timezoneSensitive: false,
|
|
1519
|
-
supportedTypes: TYPES_WITH.month,
|
|
1520
|
-
roundTripSafe: true
|
|
1521
|
-
},
|
|
1522
|
-
QQQ: {
|
|
1523
|
-
meaning: 'Quarter with "Q" prefix ("Q1".."Q4"). Derived from month.',
|
|
1524
|
-
formatCapable: true,
|
|
1525
|
-
parseCapable: true,
|
|
1526
|
-
localeSensitive: false,
|
|
1527
|
-
calendarSensitive: true,
|
|
1528
|
-
timezoneSensitive: false,
|
|
1529
|
-
supportedTypes: TYPES_WITH.month,
|
|
1530
|
-
roundTripSafe: true
|
|
1531
|
-
},
|
|
1532
|
-
ww: {
|
|
1533
|
-
meaning: "ISO 8601 week number (01-53). Format-only \u2014 week alone can't reconstruct a date.",
|
|
1534
|
-
formatCapable: true,
|
|
1535
|
-
parseCapable: false,
|
|
1536
|
-
localeSensitive: false,
|
|
1537
|
-
calendarSensitive: true,
|
|
1538
|
-
timezoneSensitive: false,
|
|
1539
|
-
supportedTypes: TYPES_WITH.dayOfWeek,
|
|
1540
|
-
roundTripSafe: false
|
|
1541
|
-
},
|
|
1542
|
-
RRRR: {
|
|
1543
|
-
meaning: "ISO 8601 week-numbering year (4-digit, may differ from calendar year at year boundaries). Format-only.",
|
|
1544
|
-
formatCapable: true,
|
|
1545
|
-
parseCapable: false,
|
|
1546
|
-
localeSensitive: false,
|
|
1547
|
-
calendarSensitive: true,
|
|
1548
|
-
timezoneSensitive: false,
|
|
1549
|
-
supportedTypes: TYPES_WITH.dayOfWeek,
|
|
1550
|
-
roundTripSafe: false
|
|
1551
|
-
},
|
|
1552
|
-
D: {
|
|
1553
|
-
meaning: "Day of year, unpadded (1-366). Format-only \u2014 parsing requires resolving against a year.",
|
|
1554
|
-
formatCapable: true,
|
|
1555
|
-
parseCapable: false,
|
|
1556
|
-
localeSensitive: false,
|
|
1557
|
-
calendarSensitive: true,
|
|
1558
|
-
timezoneSensitive: false,
|
|
1559
|
-
supportedTypes: TYPES_WITH.day,
|
|
1560
|
-
roundTripSafe: false
|
|
1561
|
-
},
|
|
1562
|
-
DD: {
|
|
1563
|
-
meaning: "Day of year, 2-digit minimum (01-366). Format-only.",
|
|
1564
|
-
formatCapable: true,
|
|
1565
|
-
parseCapable: false,
|
|
1566
|
-
localeSensitive: false,
|
|
1567
|
-
calendarSensitive: true,
|
|
1568
|
-
timezoneSensitive: false,
|
|
1569
|
-
supportedTypes: TYPES_WITH.day,
|
|
1570
|
-
roundTripSafe: false
|
|
1571
|
-
},
|
|
1572
|
-
DDD: {
|
|
1573
|
-
meaning: "Day of year, 3-digit zero-padded (001-366). Format-only.",
|
|
1574
|
-
formatCapable: true,
|
|
1575
|
-
parseCapable: false,
|
|
1576
|
-
localeSensitive: false,
|
|
1577
|
-
calendarSensitive: true,
|
|
1578
|
-
timezoneSensitive: false,
|
|
1579
|
-
supportedTypes: TYPES_WITH.day,
|
|
1580
|
-
roundTripSafe: false
|
|
1581
|
-
},
|
|
1582
|
-
LLLL: {
|
|
1583
|
-
meaning: "Stand-alone long month name (nominative case in Slavic locales). Identical to MMMM in most locales.",
|
|
1584
|
-
formatCapable: true,
|
|
1585
|
-
parseCapable: false,
|
|
1586
|
-
localeSensitive: true,
|
|
1587
|
-
calendarSensitive: true,
|
|
1588
|
-
timezoneSensitive: false,
|
|
1589
|
-
supportedTypes: TYPES_WITH.month,
|
|
1590
|
-
roundTripSafe: true
|
|
1591
|
-
},
|
|
1592
|
-
LLL: {
|
|
1593
|
-
meaning: "Stand-alone short month name. Identical to MMM in most locales.",
|
|
1594
|
-
formatCapable: true,
|
|
1595
|
-
parseCapable: false,
|
|
1596
|
-
localeSensitive: true,
|
|
1597
|
-
calendarSensitive: true,
|
|
1598
|
-
timezoneSensitive: false,
|
|
1599
|
-
supportedTypes: TYPES_WITH.month,
|
|
1600
|
-
roundTripSafe: true
|
|
1601
|
-
},
|
|
1602
|
-
cccc: {
|
|
1603
|
-
meaning: "Stand-alone long weekday name. Identical to EEEE in most locales.",
|
|
1604
|
-
formatCapable: true,
|
|
1605
|
-
parseCapable: false,
|
|
1606
|
-
localeSensitive: true,
|
|
1607
|
-
calendarSensitive: true,
|
|
1608
|
-
timezoneSensitive: false,
|
|
1609
|
-
supportedTypes: TYPES_WITH.dayOfWeek,
|
|
1610
|
-
roundTripSafe: true
|
|
1611
|
-
},
|
|
1612
|
-
ccc: {
|
|
1613
|
-
meaning: "Stand-alone short weekday name. Identical to EEE in most locales.",
|
|
1614
|
-
formatCapable: true,
|
|
1615
|
-
parseCapable: false,
|
|
1616
|
-
localeSensitive: true,
|
|
1617
|
-
calendarSensitive: true,
|
|
1618
|
-
timezoneSensitive: false,
|
|
1619
|
-
supportedTypes: TYPES_WITH.dayOfWeek,
|
|
1620
|
-
roundTripSafe: true
|
|
1621
|
-
},
|
|
1622
|
-
GGGG: {
|
|
1623
|
-
meaning: 'Long era name (locale-aware, e.g. "Anno Domini"/"Before Christ"). Format-only.',
|
|
1624
|
-
formatCapable: true,
|
|
1625
|
-
parseCapable: false,
|
|
1626
|
-
localeSensitive: true,
|
|
1627
|
-
calendarSensitive: true,
|
|
1628
|
-
timezoneSensitive: false,
|
|
1629
|
-
supportedTypes: TYPES_WITH.year,
|
|
1630
|
-
roundTripSafe: false
|
|
1631
|
-
},
|
|
1632
|
-
G: {
|
|
1633
|
-
meaning: 'Short era name (locale-aware, e.g. "AD"/"BC"). Format-only.',
|
|
1634
|
-
formatCapable: true,
|
|
1635
|
-
parseCapable: false,
|
|
1636
|
-
localeSensitive: true,
|
|
1637
|
-
calendarSensitive: true,
|
|
1638
|
-
timezoneSensitive: false,
|
|
1639
|
-
supportedTypes: TYPES_WITH.year,
|
|
1640
|
-
roundTripSafe: false
|
|
1641
|
-
},
|
|
1642
|
-
zzzz: {
|
|
1643
|
-
meaning: 'Localized long timezone name (e.g. "Eastern Standard Time"). Format-only.',
|
|
1644
|
-
formatCapable: true,
|
|
1645
|
-
parseCapable: false,
|
|
1646
|
-
localeSensitive: true,
|
|
1647
|
-
calendarSensitive: false,
|
|
1648
|
-
timezoneSensitive: true,
|
|
1649
|
-
supportedTypes: TYPES_WITH.timeZoneId,
|
|
1650
|
-
roundTripSafe: false
|
|
1651
|
-
},
|
|
1652
|
-
z: {
|
|
1653
|
-
meaning: 'Localized short timezone name (e.g. "EST"). Format-only.',
|
|
1654
|
-
formatCapable: true,
|
|
1655
|
-
parseCapable: false,
|
|
1656
|
-
localeSensitive: true,
|
|
1657
|
-
calendarSensitive: false,
|
|
1658
|
-
timezoneSensitive: true,
|
|
1659
|
-
supportedTypes: TYPES_WITH.timeZoneId,
|
|
1660
|
-
roundTripSafe: false
|
|
1661
|
-
}
|
|
1662
|
-
};
|
|
1663
|
-
var ALL_TOKEN_NAMES = Object.keys(TOKEN_METADATA);
|
|
1664
|
-
|
|
1665
|
-
// src/analyze.ts
|
|
1666
|
-
function tokenizeFormat(formatStr) {
|
|
1667
|
-
return tokenize(formatStr);
|
|
1668
|
-
}
|
|
1669
|
-
function listTokens() {
|
|
1670
|
-
return TOKENS.map(([name]) => ({ name, metadata: TOKEN_METADATA[name] }));
|
|
1671
|
-
}
|
|
1672
|
-
function tokenInfo(name) {
|
|
1673
|
-
return TOKEN_METADATA[name];
|
|
1674
|
-
}
|
|
1675
|
-
function analyzeFormat(formatStr) {
|
|
1676
|
-
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
1677
|
-
throw new Error(
|
|
1678
|
-
`temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`
|
|
1679
|
-
);
|
|
1680
|
-
}
|
|
1681
|
-
const pieces = tokenize(formatStr);
|
|
1682
|
-
const tokens = [];
|
|
1683
|
-
const requiredFields = /* @__PURE__ */ new Set();
|
|
1684
|
-
const compatibleTypesSet = /* @__PURE__ */ new Set();
|
|
1685
|
-
let parseable = true;
|
|
1686
|
-
let localeSensitive = false;
|
|
1687
|
-
let calendarSensitive = false;
|
|
1688
|
-
let timezoneSensitive = false;
|
|
1689
|
-
let roundTripSafe = true;
|
|
1690
|
-
const warnings = [];
|
|
1691
|
-
let offset = 0;
|
|
1692
|
-
const unpaddedRun = [];
|
|
1693
|
-
const flushRun = () => {
|
|
1694
|
-
if (unpaddedRun.length >= 2) {
|
|
1695
|
-
warnings.push({
|
|
1696
|
-
code: "AMBIGUOUS_NUMERIC_RUN",
|
|
1697
|
-
message: `Adjacent unpadded numeric tokens "${unpaddedRun.join("")}" with no separator can be ambiguous to parse. Add a separator or use the padded form (e.g. "MM" instead of "M").`
|
|
1698
|
-
});
|
|
1699
|
-
}
|
|
1700
|
-
unpaddedRun.length = 0;
|
|
1701
|
-
};
|
|
1702
|
-
for (const piece of pieces) {
|
|
1703
|
-
if (piece.kind === "literal") {
|
|
1704
|
-
offset += piece.value.length;
|
|
1705
|
-
flushRun();
|
|
1706
|
-
continue;
|
|
1707
|
-
}
|
|
1708
|
-
const metadata = TOKEN_METADATA[piece.value];
|
|
1709
|
-
if (!metadata) {
|
|
1710
|
-
warnings.push({
|
|
1711
|
-
code: "UNKNOWN_TOKEN_NO_METADATA",
|
|
1712
|
-
message: `Token "${piece.value}" is recognized by the tokenizer but has no metadata entry in tokenMetadata.ts \u2014 this is a bug in temporal-fmt.`
|
|
1713
|
-
});
|
|
1714
|
-
offset += piece.value.length;
|
|
1715
|
-
continue;
|
|
1716
|
-
}
|
|
1717
|
-
tokens.push({ name: piece.value, position: offset, metadata });
|
|
1718
|
-
const handler = _handlerFor(piece.value);
|
|
1719
|
-
if (handler) {
|
|
1720
|
-
requiredFields.add(handler.field);
|
|
1721
|
-
}
|
|
1722
|
-
if (tokens.length === 1) {
|
|
1723
|
-
for (const t of metadata.supportedTypes) compatibleTypesSet.add(t);
|
|
1724
|
-
} else {
|
|
1725
|
-
const stillCompatible = /* @__PURE__ */ new Set();
|
|
1726
|
-
for (const t of compatibleTypesSet) {
|
|
1727
|
-
if (metadata.supportedTypes.includes(t)) stillCompatible.add(t);
|
|
1728
|
-
}
|
|
1729
|
-
compatibleTypesSet.clear();
|
|
1730
|
-
for (const t of stillCompatible) compatibleTypesSet.add(t);
|
|
1731
|
-
}
|
|
1732
|
-
if (!metadata.parseCapable) {
|
|
1733
|
-
parseable = false;
|
|
1734
|
-
warnings.push({
|
|
1735
|
-
code: "FORMAT_ONLY_TOKEN",
|
|
1736
|
-
message: `Token "${piece.value}" is format-only \u2014 it can't be parsed back into a value. Use a parse-capable variant (e.g. "d" instead of "do") if you need round-trip.`
|
|
1737
|
-
});
|
|
1738
|
-
}
|
|
1739
|
-
if (metadata.localeSensitive) localeSensitive = true;
|
|
1740
|
-
if (metadata.calendarSensitive) calendarSensitive = true;
|
|
1741
|
-
if (metadata.timezoneSensitive) timezoneSensitive = true;
|
|
1742
|
-
if (!metadata.roundTripSafe) roundTripSafe = false;
|
|
1743
|
-
if (UNPADDED_NUMERIC_TOKENS.has(piece.value)) {
|
|
1744
|
-
unpaddedRun.push(piece.value);
|
|
1745
|
-
} else {
|
|
1746
|
-
flushRun();
|
|
1747
|
-
}
|
|
1748
|
-
offset += piece.value.length;
|
|
1749
|
-
}
|
|
1750
|
-
flushRun();
|
|
1751
|
-
const tokenNames = tokens.map((t) => t.name);
|
|
1752
|
-
const has12Hour = tokenNames.some((t) => t === "hh" || t === "h");
|
|
1753
|
-
const has24Hour = tokenNames.some((t) => t === "HH" || t === "H");
|
|
1754
|
-
const hasAPeriod = tokenNames.some((t) => t === "a");
|
|
1755
|
-
if (has12Hour && !hasAPeriod) {
|
|
1756
|
-
warnings.push({
|
|
1757
|
-
code: "TWELVE_HOUR_WITHOUT_A",
|
|
1758
|
-
message: `12-hour token ("hh"/"h") used without an "a" (AM/PM) token \u2014 parse() can't tell AM from PM and throws at runtime.`
|
|
1759
|
-
});
|
|
1760
|
-
}
|
|
1761
|
-
if (has12Hour && has24Hour) {
|
|
1762
|
-
warnings.push({
|
|
1763
|
-
code: "MIXED_12_AND_24_HOUR",
|
|
1764
|
-
message: "Mixing 24-hour and 12-hour tokens \u2014 parse() refuses to guess which is authoritative and throws at runtime."
|
|
1765
|
-
});
|
|
1766
|
-
}
|
|
1767
|
-
const hasOffset = tokenNames.some((t) => t === "X" || t === "XX" || t === "XXX" || t === "x" || t === "xx" || t === "xxx");
|
|
1768
|
-
const hasZzz = tokenNames.some((t) => t === "zzz");
|
|
1769
|
-
if (hasOffset && hasZzz) {
|
|
1770
|
-
warnings.push({
|
|
1771
|
-
code: "ZZZ_WITH_OFFSET_TOKEN",
|
|
1772
|
-
message: `Format string has both "zzz" and an offset token \u2014 parse() cross-checks them and throws if the parsed offset disagrees with the zone's actual offset.`
|
|
1773
|
-
});
|
|
1774
|
-
}
|
|
1775
|
-
if (hasOffset && !requiredFields.has("year")) {
|
|
1776
|
-
warnings.push({
|
|
1777
|
-
code: "OFFSET_WITHOUT_FULL_DATE",
|
|
1778
|
-
message: "Offset token used without a full date \u2014 parse() needs a complete date and time to build a ZonedDateTime and throws at runtime otherwise."
|
|
1779
|
-
});
|
|
1780
|
-
}
|
|
1781
|
-
return {
|
|
1782
|
-
tokens,
|
|
1783
|
-
requiredFields: [...requiredFields].sort(),
|
|
1784
|
-
compatibleTypes: [...compatibleTypesSet].sort(),
|
|
1785
|
-
parseable,
|
|
1786
|
-
localeSensitive,
|
|
1787
|
-
calendarSensitive,
|
|
1788
|
-
timezoneSensitive,
|
|
1789
|
-
// Ambiguous iff at least one warning fired about an ambiguous run.
|
|
1790
|
-
ambiguous: warnings.some((w) => w.code === "AMBIGUOUS_NUMERIC_RUN"),
|
|
1791
|
-
roundTripSafe: roundTripSafe && parseable,
|
|
1792
|
-
warnings
|
|
1793
|
-
};
|
|
1794
|
-
}
|
|
1795
|
-
function explainFormat(formatStr) {
|
|
1796
|
-
const analysis = analyzeFormat(formatStr);
|
|
1797
|
-
const lines = [];
|
|
1798
|
-
lines.push(`Format string: "${formatStr}"`);
|
|
1799
|
-
lines.push(`Tokens (${analysis.tokens.length}):`);
|
|
1800
|
-
for (const t of analysis.tokens) {
|
|
1801
|
-
lines.push(` ${t.name} @${t.position} \u2014 ${t.metadata.meaning}`);
|
|
1802
|
-
}
|
|
1803
|
-
if (analysis.requiredFields.length > 0) {
|
|
1804
|
-
lines.push(`Required fields: ${analysis.requiredFields.join(", ")}`);
|
|
1805
|
-
}
|
|
1806
|
-
if (analysis.compatibleTypes.length > 0) {
|
|
1807
|
-
lines.push(`Compatible Temporal types: ${analysis.compatibleTypes.join(", ")}`);
|
|
1808
|
-
}
|
|
1809
|
-
lines.push(`Parseable: ${analysis.parseable ? "yes" : "no"}`);
|
|
1810
|
-
lines.push(`Locale-sensitive: ${analysis.localeSensitive ? "yes" : "no"}`);
|
|
1811
|
-
lines.push(`Calendar-sensitive: ${analysis.calendarSensitive ? "yes" : "no"}`);
|
|
1812
|
-
lines.push(`Timezone-sensitive: ${analysis.timezoneSensitive ? "yes" : "no"}`);
|
|
1813
|
-
lines.push(`Ambiguous: ${analysis.ambiguous ? "yes" : "no"}`);
|
|
1814
|
-
lines.push(`Round-trip safe: ${analysis.roundTripSafe ? "yes" : "no"}`);
|
|
1815
|
-
if (analysis.warnings.length > 0) {
|
|
1816
|
-
lines.push("Warnings:");
|
|
1817
|
-
for (const w of analysis.warnings) {
|
|
1818
|
-
lines.push(` [${w.code}] ${w.message}`);
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
return lines.join("\n");
|
|
1822
|
-
}
|
|
1823
|
-
function isValidFormat(formatStr) {
|
|
1824
|
-
if (formatStr.length > MAX_FORMAT_LENGTH) return false;
|
|
1825
|
-
try {
|
|
1826
|
-
tokenize(formatStr);
|
|
1827
|
-
return true;
|
|
1828
|
-
} catch {
|
|
1829
|
-
return false;
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
function validateFormat(formatStr) {
|
|
1833
|
-
const analysis = analyzeFormat(formatStr);
|
|
1834
|
-
return analysis;
|
|
1835
|
-
}
|
|
1836
|
-
function fieldForToken(token) {
|
|
1837
|
-
return _handlerFor(token)?.field;
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
// src/serialization.ts
|
|
1841
|
-
function parseISO(input) {
|
|
1842
|
-
const temporal = getTemporal();
|
|
1843
|
-
try {
|
|
1844
|
-
if (/^\d{4}-\d{2}-\d{2}T/.test(input) || /T\d{2}:\d{2}/.test(input)) {
|
|
1845
|
-
if (/[zZ]$/.test(input) || /[+-]\d{2}:?\d{2}$/.test(input)) {
|
|
1846
|
-
let iso = input;
|
|
1847
|
-
if (/[zZ]$/.test(iso)) {
|
|
1848
|
-
iso = iso.slice(0, -1) + "+00:00[UTC]";
|
|
1849
|
-
} else {
|
|
1850
|
-
const offsetMatch = /([+-]\d{2}:?\d{2})$/.exec(iso);
|
|
1851
|
-
if (offsetMatch) {
|
|
1852
|
-
iso = `${iso}[${offsetMatch[1]}]`;
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
return temporal.ZonedDateTime.from(iso, { overflow: "reject" });
|
|
1856
|
-
}
|
|
1857
|
-
return temporal.PlainDateTime.from(input, { overflow: "reject" });
|
|
1858
|
-
}
|
|
1859
|
-
if (/^\d{4}-\d{2}-\d{2}/.test(input)) {
|
|
1860
|
-
return temporal.PlainDate.from(input, { overflow: "reject" });
|
|
1861
|
-
}
|
|
1862
|
-
if (/^\d{2}:\d{2}/.test(input)) {
|
|
1863
|
-
return temporal.PlainTime.from(input);
|
|
1864
|
-
}
|
|
1865
|
-
throw new Error(`temporal-fmt: parseISO("${input}") doesn't look like an ISO 8601 string.`);
|
|
1866
|
-
} catch (err) {
|
|
1867
|
-
throw new InvalidDateError({ input, reason: err.message });
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
function formatISO(value) {
|
|
1871
|
-
const v = value;
|
|
1872
|
-
if (typeof v?.toString !== "function") {
|
|
1873
|
-
throw new FormatSyntaxError({ reason: `formatISO() expects a Temporal value with toString(), got ${typeof value}.` });
|
|
1874
|
-
}
|
|
1875
|
-
return v.toString();
|
|
1876
|
-
}
|
|
1877
|
-
function parseRFC3339(input) {
|
|
1878
|
-
const re = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(\.\d+)?([Zz]|[+-]\d{2}:\d{2})$/;
|
|
1879
|
-
const m = re.exec(input);
|
|
1880
|
-
if (!m) {
|
|
1881
|
-
throw new FormatSyntaxError({ input, reason: "does not match RFC 3339 date-time grammar" });
|
|
1882
|
-
}
|
|
1883
|
-
const iso = input.replace(/[tT]/, "T").replace(/[zZ]$/, "+00:00[UTC]");
|
|
1884
|
-
return parseISO(iso);
|
|
1885
|
-
}
|
|
1886
|
-
function formatRFC3339(value) {
|
|
1887
|
-
const s = formatISO(value);
|
|
1888
|
-
if (!/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?(Z|[+-][0-9]{2}:[0-9]{2})$/.test(s)) {
|
|
1889
|
-
throw new FormatSyntaxError({ input: s, reason: "value did not produce RFC 3339-compliant output" });
|
|
1890
|
-
}
|
|
1891
|
-
return s;
|
|
1892
|
-
}
|
|
1893
|
-
function parseRFC2822(input) {
|
|
1894
|
-
const ms = Date.parse(input);
|
|
1895
|
-
if (Number.isNaN(ms)) {
|
|
1896
|
-
throw new FormatSyntaxError({ input, reason: "not a valid RFC 2822 date" });
|
|
1897
|
-
}
|
|
1898
|
-
return requireInstant().fromEpochMilliseconds(ms);
|
|
1899
|
-
}
|
|
1900
|
-
function formatRFC2822(value) {
|
|
1901
|
-
const v = value;
|
|
1902
|
-
let ms;
|
|
1903
|
-
if (typeof v?.toEpochMilliseconds === "function") {
|
|
1904
|
-
ms = v.toEpochMilliseconds();
|
|
1905
|
-
} else if (typeof v?.epochMilliseconds === "number") {
|
|
1906
|
-
ms = v.epochMilliseconds;
|
|
1907
|
-
} else if (typeof v?.toInstant === "function") {
|
|
1908
|
-
const inst = v.toInstant();
|
|
1909
|
-
if (typeof inst.epochMilliseconds === "number") {
|
|
1910
|
-
ms = inst.epochMilliseconds;
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
if (ms === void 0) {
|
|
1914
|
-
throw new FormatSyntaxError({ reason: `formatRFC2822() expects a value with epochMilliseconds, toEpochMilliseconds(), or toInstant(), got ${typeof value}.` });
|
|
1915
|
-
}
|
|
1916
|
-
return formatRFC2822FromMs(ms);
|
|
1917
|
-
}
|
|
1918
|
-
function formatRFC2822FromMs(ms) {
|
|
1919
|
-
try {
|
|
1920
|
-
const fmt = new Intl.DateTimeFormat("en-US", {
|
|
1921
|
-
weekday: "short",
|
|
1922
|
-
day: "2-digit",
|
|
1923
|
-
month: "short",
|
|
1924
|
-
year: "numeric",
|
|
1925
|
-
hour: "2-digit",
|
|
1926
|
-
minute: "2-digit",
|
|
1927
|
-
second: "2-digit",
|
|
1928
|
-
timeZone: "UTC",
|
|
1929
|
-
timeZoneName: "shortOffset",
|
|
1930
|
-
hour12: false
|
|
1931
|
-
});
|
|
1932
|
-
const parts = fmt.formatToParts(new Date(ms));
|
|
1933
|
-
const get = (t) => parts.find((p) => p.type === t)?.value ?? "";
|
|
1934
|
-
const tzRaw = get("timeZoneName");
|
|
1935
|
-
const tzMatch = tzRaw?.match(/GMT([+-])(\d+)(?::(\d+))?/);
|
|
1936
|
-
let tz;
|
|
1937
|
-
if (tzMatch) {
|
|
1938
|
-
const sign = tzMatch[1];
|
|
1939
|
-
const hours = tzMatch[2].padStart(2, "0");
|
|
1940
|
-
const minutes = (tzMatch[3] ?? "0").padStart(2, "0");
|
|
1941
|
-
tz = `${sign}${hours}${minutes}`;
|
|
1942
|
-
/* c8 ignore start @preserve -- timeZone is hardcoded to 'UTC' above,
|
|
1943
|
-
which always resolves cleanly, so shortOffset always returns a
|
|
1944
|
-
parseable "GMT+0"-shaped string in this environment's ICU. This
|
|
1945
|
-
branch only guards against an ICU build whose shortOffset output
|
|
1946
|
-
doesn't match the regex; can't trigger it without mocking Intl.
|
|
1947
|
-
The ignore starts before the closing brace of the if-block so it
|
|
1948
|
-
covers the whole else-branch node c8 tracks as a single unit. */
|
|
1949
|
-
} else {
|
|
1950
|
-
tz = "+0000";
|
|
1951
|
-
}
|
|
1952
|
-
/* c8 ignore stop @preserve */
|
|
1953
|
-
let hour = get("hour");
|
|
1954
|
-
/* c8 ignore start @preserve -- hour12:false with a fixed UTC zone
|
|
1955
|
-
never yields "24" in this environment's ICU (midnight formats as
|
|
1956
|
-
"00"). Some ICU versions/locales are documented to emit "24" for
|
|
1957
|
-
hour12:false, so this stays as a defensive normalization; not
|
|
1958
|
-
reachable here without mocking Intl.DateTimeFormat's output. */
|
|
1959
|
-
if (hour === "24") hour = "00";
|
|
1960
|
-
/* c8 ignore stop @preserve */
|
|
1961
|
-
return `${get("weekday")}, ${get("day")} ${get("month")} ${get("year")} ${hour}:${get("minute")}:${get("second")} ${tz}`;
|
|
1962
|
-
/* c8 ignore start @preserve -- Intl.DateTimeFormat is constructed
|
|
1963
|
-
above with a literal, always-valid timeZone: 'UTC' and no other
|
|
1964
|
-
user input reaches the constructor or formatToParts call, so this
|
|
1965
|
-
catch can't be triggered through the public API in a normal Intl
|
|
1966
|
-
environment (e.g. Node with full-icu). Kept as a genuine fallback
|
|
1967
|
-
for runtimes with a broken or absent Intl implementation. */
|
|
1968
|
-
} catch {
|
|
1969
|
-
const d = new Date(ms);
|
|
1970
|
-
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
1971
|
-
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
1972
|
-
const wd = days[d.getUTCDay()];
|
|
1973
|
-
const dd = String(d.getUTCDate()).padStart(2, "0");
|
|
1974
|
-
const mon = months[d.getUTCMonth()];
|
|
1975
|
-
const yyyy = d.getUTCFullYear();
|
|
1976
|
-
const hh = String(d.getUTCHours()).padStart(2, "0");
|
|
1977
|
-
const mm = String(d.getUTCMinutes()).padStart(2, "0");
|
|
1978
|
-
const ss = String(d.getUTCSeconds()).padStart(2, "0");
|
|
1979
|
-
return `${wd}, ${dd} ${mon} ${yyyy} ${hh}:${mm}:${ss} +0000`;
|
|
1980
|
-
}
|
|
1981
|
-
/* c8 ignore stop @preserve */
|
|
1982
|
-
}
|
|
1983
|
-
function parseHTTPDate(input) {
|
|
1984
|
-
const trimmed = input.trim();
|
|
1985
|
-
const ms = Date.parse(trimmed);
|
|
1986
|
-
if (Number.isNaN(ms)) {
|
|
1987
|
-
throw new FormatSyntaxError({ input, reason: "not a valid HTTP-date" });
|
|
1988
|
-
}
|
|
1989
|
-
return requireInstant().fromEpochMilliseconds(ms);
|
|
1990
|
-
}
|
|
1991
|
-
function formatHTTPDate(value) {
|
|
1992
|
-
const instant = value?.toInstant?.() ?? value;
|
|
1993
|
-
const ms = typeof instant === "object" && instant !== null && "epochMilliseconds" in instant ? instant.epochMilliseconds : (() => {
|
|
1994
|
-
throw new FormatSyntaxError({ reason: `formatHTTPDate() expects an Instant or ZonedDateTime, got ${typeof value}.` });
|
|
1995
|
-
})();
|
|
1996
|
-
const d = new Date(ms);
|
|
1997
|
-
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
1998
|
-
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
1999
|
-
const wd = days[d.getUTCDay()];
|
|
2000
|
-
const dd = String(d.getUTCDate()).padStart(2, "0");
|
|
2001
|
-
const mon = months[d.getUTCMonth()];
|
|
2002
|
-
const yyyy = d.getUTCFullYear();
|
|
2003
|
-
const hh = String(d.getUTCHours()).padStart(2, "0");
|
|
2004
|
-
const mm = String(d.getUTCMinutes()).padStart(2, "0");
|
|
2005
|
-
const ss = String(d.getUTCSeconds()).padStart(2, "0");
|
|
2006
|
-
return `${wd}, ${dd} ${mon} ${yyyy} ${hh}:${mm}:${ss} GMT`;
|
|
2007
|
-
}
|
|
2008
|
-
function getInstant(value) {
|
|
2009
|
-
const v = value;
|
|
2010
|
-
if (typeof v?.toInstant === "function") {
|
|
2011
|
-
const inst = v.toInstant();
|
|
2012
|
-
if (typeof inst.epochNanoseconds === "bigint") {
|
|
2013
|
-
return { epochMilliseconds: inst.epochMilliseconds, epochNanoseconds: inst.epochNanoseconds };
|
|
2014
|
-
}
|
|
2015
|
-
return { epochMilliseconds: inst.epochMilliseconds, epochNanoseconds: BigInt(inst.epochMilliseconds) * 1000000n };
|
|
2016
|
-
}
|
|
2017
|
-
if (typeof v?.epochNanoseconds === "bigint") {
|
|
2018
|
-
return { epochMilliseconds: Number(v.epochNanoseconds / 1000000n), epochNanoseconds: v.epochNanoseconds };
|
|
2019
|
-
}
|
|
2020
|
-
if (typeof v?.epochMilliseconds === "number") {
|
|
2021
|
-
return { epochMilliseconds: v.epochMilliseconds, epochNanoseconds: BigInt(v.epochMilliseconds) * 1000000n };
|
|
2022
|
-
}
|
|
2023
|
-
throw new FormatSyntaxError({ reason: `expected an Instant or ZonedDateTime, got ${typeof value}.` });
|
|
2024
|
-
}
|
|
2025
|
-
function requireInstant() {
|
|
2026
|
-
const t = getTemporal().Instant;
|
|
2027
|
-
if (!t) throw new Error("temporal-fmt: Temporal.Instant is not available in this implementation.");
|
|
2028
|
-
return t;
|
|
2029
|
-
}
|
|
2030
|
-
function fromUnixSeconds(seconds) {
|
|
2031
|
-
return requireInstant().fromEpochMilliseconds(seconds * 1e3);
|
|
2032
|
-
}
|
|
2033
|
-
function fromUnixMilliseconds(ms) {
|
|
2034
|
-
return requireInstant().fromEpochMilliseconds(ms);
|
|
2035
|
-
}
|
|
2036
|
-
function fromUnixMicroseconds(\u00B5s) {
|
|
2037
|
-
return requireInstant().fromEpochNanoseconds(BigInt(\u00B5s) * 1000n);
|
|
2038
|
-
}
|
|
2039
|
-
function fromUnixNanoseconds(ns) {
|
|
2040
|
-
return requireInstant().fromEpochNanoseconds(ns);
|
|
2041
|
-
}
|
|
2042
|
-
function toUnixSeconds(value) {
|
|
2043
|
-
return getInstant(value).epochMilliseconds / 1e3;
|
|
2044
|
-
}
|
|
2045
|
-
function toUnixMilliseconds(value) {
|
|
2046
|
-
return getInstant(value).epochMilliseconds;
|
|
2047
|
-
}
|
|
2048
|
-
function toUnixMicroseconds(value) {
|
|
2049
|
-
const { epochNanoseconds } = getInstant(value);
|
|
2050
|
-
return Number(epochNanoseconds / 1000n);
|
|
2051
|
-
}
|
|
2052
|
-
function toUnixNanoseconds(value) {
|
|
2053
|
-
return getInstant(value).epochNanoseconds;
|
|
2054
|
-
}
|
|
2055
|
-
function parseSQL(input) {
|
|
2056
|
-
const trimmed = input.trim();
|
|
2057
|
-
if (/^\d{4}-\d{2}-\d{2}$/.test(trimmed)) {
|
|
2058
|
-
return parse("yyyy-MM-dd", trimmed);
|
|
2059
|
-
}
|
|
2060
|
-
if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(trimmed)) {
|
|
2061
|
-
return parse("yyyy-MM-dd HH:mm:ss", trimmed);
|
|
2062
|
-
}
|
|
2063
|
-
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(trimmed)) {
|
|
2064
|
-
return parseISO(trimmed);
|
|
2065
|
-
}
|
|
2066
|
-
throw new FormatSyntaxError({ input, reason: "not a recognized SQL date/time format" });
|
|
2067
|
-
}
|
|
2068
|
-
function formatSQL(value) {
|
|
2069
|
-
const v = value;
|
|
2070
|
-
if (typeof v?.hour === "number") {
|
|
2071
|
-
return format(value, "yyyy-MM-dd HH:mm:ss");
|
|
2072
|
-
}
|
|
2073
|
-
return format(value, "yyyy-MM-dd");
|
|
2074
|
-
}
|
|
2075
|
-
|
|
2076
|
-
// src/config.ts
|
|
2077
|
-
var DEFAULT_CONFIG = {
|
|
2078
|
-
locale: DEFAULT_LOCALE,
|
|
2079
|
-
numberingSystem: "latn",
|
|
2080
|
-
firstDayOfWeek: 1,
|
|
2081
|
-
roundingMode: "nearest",
|
|
2082
|
-
disambiguation: "compatible",
|
|
2083
|
-
overflow: "reject",
|
|
2084
|
-
parseLenient: false,
|
|
2085
|
-
durationShowZeroValues: false
|
|
2086
|
-
};
|
|
2087
|
-
function createConfig(overrides = {}) {
|
|
2088
|
-
const merged = { ...DEFAULT_CONFIG, ...overrides };
|
|
2089
|
-
if (typeof merged.locale !== "string" || merged.locale.length === 0) {
|
|
2090
|
-
throw new Error(`temporal-fmt: config.locale must be a non-empty string (got ${String(merged.locale)}).`);
|
|
2091
|
-
}
|
|
2092
|
-
if (merged.firstDayOfWeek !== 1 && merged.firstDayOfWeek !== 7) {
|
|
2093
|
-
throw new Error(`temporal-fmt: config.firstDayOfWeek must be 1 (Monday) or 7 (Sunday) (got ${merged.firstDayOfWeek}).`);
|
|
2094
|
-
}
|
|
2095
|
-
if (!["nearest", "floor", "ceil", "trunc"].includes(merged.roundingMode)) {
|
|
2096
|
-
throw new Error(`temporal-fmt: config.roundingMode "${merged.roundingMode}" is not recognized.`);
|
|
2097
|
-
}
|
|
2098
|
-
if (!["compatible", "earlier", "later", "reject"].includes(merged.disambiguation)) {
|
|
2099
|
-
throw new Error(`temporal-fmt: config.disambiguation "${merged.disambiguation}" is not recognized.`);
|
|
2100
|
-
}
|
|
2101
|
-
if (!["constrain", "reject"].includes(merged.overflow)) {
|
|
2102
|
-
throw new Error(`temporal-fmt: config.overflow "${merged.overflow}" is not recognized.`);
|
|
2103
|
-
}
|
|
2104
|
-
return Object.freeze(merged);
|
|
2105
|
-
}
|
|
2106
|
-
function mergeWithConfig(config, perCall) {
|
|
2107
|
-
if (!config) return perCall;
|
|
2108
|
-
const result = { ...perCall };
|
|
2109
|
-
if (result.locale === void 0) result.locale = config.locale;
|
|
2110
|
-
if (result.calendar === void 0 && config.calendar !== void 0) result.calendar = config.calendar;
|
|
2111
|
-
if (result.timezone === void 0 && config.timezone !== void 0) result.timezone = config.timezone;
|
|
2112
|
-
if (result.numberingSystem === void 0) result.numberingSystem = config.numberingSystem;
|
|
2113
|
-
if (result.lenient === void 0 && config.parseLenient) result.lenient = true;
|
|
2114
|
-
return result;
|
|
2115
|
-
}
|
|
2116
|
-
|
|
2117
|
-
// src/relativeGrammar.ts
|
|
2118
|
-
var registeredGrammars = [];
|
|
2119
|
-
function registerRelativeGrammar(grammar) {
|
|
2120
|
-
if (typeof grammar.language !== "string" || grammar.language.length === 0) {
|
|
2121
|
-
throw new Error("temporal-fmt: registerRelativeGrammar requires a non-empty language string.");
|
|
2122
|
-
}
|
|
2123
|
-
if (!Array.isArray(grammar.matchers) || grammar.matchers.length === 0) {
|
|
2124
|
-
throw new Error("temporal-fmt: registerRelativeGrammar requires at least one matcher.");
|
|
2125
|
-
}
|
|
2126
|
-
const existingIdx = registeredGrammars.findIndex((g) => g.language === grammar.language);
|
|
2127
|
-
if (existingIdx >= 0) {
|
|
2128
|
-
registeredGrammars[existingIdx] = grammar;
|
|
2129
|
-
} else {
|
|
2130
|
-
registeredGrammars.push(grammar);
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
2133
|
-
function listRegisteredGrammars() {
|
|
2134
|
-
return registeredGrammars.map((g) => g.language);
|
|
2135
|
-
}
|
|
2136
|
-
|
|
2137
|
-
// src/businessCalendar.ts
|
|
2138
|
-
function createBusinessCalendar(options = {}) {
|
|
2139
|
-
const weekend = new Set(options.weekend ?? [6, 7]);
|
|
2140
|
-
const workingHours = options.workingHours ?? {};
|
|
2141
|
-
for (let i = 1; i <= 7; i++) {
|
|
2142
|
-
if (workingHours[i] === void 0) {
|
|
2143
|
-
workingHours[i] = weekend.has(i) ? 0 : 8;
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
return {
|
|
2147
|
-
weekend,
|
|
2148
|
-
holidays: options.holidays,
|
|
2149
|
-
workingHours,
|
|
2150
|
-
halfDays: new Set(options.halfDays ?? [])
|
|
2151
|
-
};
|
|
2152
|
-
}
|
|
2153
|
-
function isBusinessDay(cal, value) {
|
|
2154
|
-
const v = value;
|
|
2155
|
-
let dow = v.dayOfWeek;
|
|
2156
|
-
if (typeof v.year === "number" && typeof v.month === "number" && typeof v.day === "number") {
|
|
2157
|
-
const d = new Date(Date.UTC(v.year, v.month - 1, v.day));
|
|
2158
|
-
const jsDow = d.getUTCDay();
|
|
2159
|
-
dow = jsDow === 0 ? 7 : jsDow;
|
|
2160
|
-
}
|
|
2161
|
-
if (typeof dow !== "number") {
|
|
2162
|
-
throw new Error("temporal-fmt: isBusinessDay() needs a value with dayOfWeek (or year/month/day to compute it).");
|
|
2163
|
-
}
|
|
2164
|
-
if (cal.weekend.has(dow)) return false;
|
|
2165
|
-
if (cal.holidays && cal.holidays.isHoliday(value)) return false;
|
|
2166
|
-
return true;
|
|
2167
|
-
}
|
|
2168
|
-
function nextBusinessDay(cal, value) {
|
|
2169
|
-
let candidate = add(value, 1, "days");
|
|
2170
|
-
for (let i = 0; i < 14; i++) {
|
|
2171
|
-
if (isBusinessDay(cal, candidate)) return candidate;
|
|
2172
|
-
candidate = add(candidate, 1, "days");
|
|
2173
|
-
}
|
|
2174
|
-
throw new Error("temporal-fmt: nextBusinessDay() gave up after 14 days \u2014 likely a misconfigured calendar (e.g. all days are weekends or holidays).");
|
|
2175
|
-
}
|
|
2176
|
-
function previousBusinessDay(cal, value) {
|
|
2177
|
-
let candidate = add(value, -1, "days");
|
|
2178
|
-
for (let i = 0; i < 14; i++) {
|
|
2179
|
-
if (isBusinessDay(cal, candidate)) return candidate;
|
|
2180
|
-
candidate = add(candidate, -1, "days");
|
|
2181
|
-
}
|
|
2182
|
-
throw new Error("temporal-fmt: previousBusinessDay() gave up after 14 days \u2014 likely a misconfigured calendar.");
|
|
2183
|
-
}
|
|
2184
|
-
var MAX_BUSINESS_DAY_TRAVERSAL = 1e5;
|
|
2185
|
-
function assertBusinessDayCount(days) {
|
|
2186
|
-
if (!Number.isSafeInteger(days)) {
|
|
2187
|
-
throw new RangeError(
|
|
2188
|
-
`temporal-fmt: business-day count must be a finite safe integer (got ${days}).`
|
|
2189
|
-
);
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
function compareDateFields(a, b) {
|
|
2193
|
-
const av = a;
|
|
2194
|
-
const bv = b;
|
|
2195
|
-
const ay = av.year * 1e4 + av.month * 100 + av.day;
|
|
2196
|
-
const by = bv.year * 1e4 + bv.month * 100 + bv.day;
|
|
2197
|
-
return ay - by;
|
|
2198
|
-
}
|
|
2199
|
-
function addBusinessDays(cal, value, days) {
|
|
2200
|
-
assertBusinessDayCount(days);
|
|
2201
|
-
if (days === 0) return value;
|
|
2202
|
-
const sign = days > 0 ? 1 : -1;
|
|
2203
|
-
const absDays = Math.abs(days);
|
|
2204
|
-
if (absDays > MAX_BUSINESS_DAY_TRAVERSAL) {
|
|
2205
|
-
throw new RangeError(
|
|
2206
|
-
`temporal-fmt: addBusinessDays() exceeded the ${MAX_BUSINESS_DAY_TRAVERSAL}-day limit.`
|
|
2207
|
-
);
|
|
2208
|
-
}
|
|
2209
|
-
let candidate = value;
|
|
2210
|
-
for (let i = 0; i < absDays; i++) {
|
|
2211
|
-
candidate = sign > 0 ? nextBusinessDay(cal, candidate) : previousBusinessDay(cal, candidate);
|
|
2212
|
-
}
|
|
2213
|
-
return candidate;
|
|
2214
|
-
}
|
|
2215
|
-
function subtractBusinessDays(cal, value, days) {
|
|
2216
|
-
assertBusinessDayCount(days);
|
|
2217
|
-
return addBusinessDays(cal, value, -days);
|
|
2218
|
-
}
|
|
2219
|
-
function differenceInBusinessDays(cal, a, b) {
|
|
2220
|
-
const rawDirection = compareDateFields(b, a);
|
|
2221
|
-
if (rawDirection === 0) return 0;
|
|
2222
|
-
const direction = rawDirection > 0 ? 1 : -1;
|
|
2223
|
-
let candidate = a;
|
|
2224
|
-
let count = 0;
|
|
2225
|
-
let traversedDays = 0;
|
|
2226
|
-
while (compareDateFields(candidate, b) !== 0) {
|
|
2227
|
-
candidate = add(candidate, direction, "days");
|
|
2228
|
-
traversedDays++;
|
|
2229
|
-
if (traversedDays > MAX_BUSINESS_DAY_TRAVERSAL) {
|
|
2230
|
-
throw new RangeError(
|
|
2231
|
-
`temporal-fmt: differenceInBusinessDays() exceeded the ${MAX_BUSINESS_DAY_TRAVERSAL}-day traversal limit.`
|
|
2232
|
-
);
|
|
2233
|
-
}
|
|
2234
|
-
if (isBusinessDay(cal, candidate)) count += direction;
|
|
2235
|
-
}
|
|
2236
|
-
return count;
|
|
2237
|
-
}
|
|
2238
|
-
|
|
2239
|
-
// src/holidays.ts
|
|
2240
|
-
function createHolidayCalendar(specs) {
|
|
2241
|
-
const cache = /* @__PURE__ */ new Map();
|
|
2242
|
-
function forYear(year) {
|
|
2243
|
-
let list = cache.get(year);
|
|
2244
|
-
if (list) return list;
|
|
2245
|
-
list = specs.map((s) => {
|
|
2246
|
-
let md;
|
|
2247
|
-
if (s.compute) {
|
|
2248
|
-
md = s.compute(year);
|
|
2249
|
-
} else {
|
|
2250
|
-
md = { month: s.month, day: s.day };
|
|
2251
|
-
}
|
|
2252
|
-
return { ...md, name: s.name };
|
|
2253
|
-
});
|
|
2254
|
-
cache.set(year, list);
|
|
2255
|
-
return list;
|
|
2256
|
-
}
|
|
2257
|
-
return {
|
|
2258
|
-
isHoliday(value) {
|
|
2259
|
-
const v = value;
|
|
2260
|
-
if (typeof v.year !== "number" || typeof v.month !== "number" || typeof v.day !== "number") {
|
|
2261
|
-
throw new Error("temporal-fmt: isHoliday() needs a value with year/month/day.");
|
|
2262
|
-
}
|
|
2263
|
-
const list = forYear(v.year);
|
|
2264
|
-
return list.some((h) => h.month === v.month && h.day === v.day);
|
|
2265
|
-
},
|
|
2266
|
-
holidaysBetween(start, end) {
|
|
2267
|
-
const sv = start;
|
|
2268
|
-
const ev = end;
|
|
2269
|
-
const result = [];
|
|
2270
|
-
for (let y = sv.year; y <= ev.year; y++) {
|
|
2271
|
-
const list = forYear(y);
|
|
2272
|
-
for (const h of list) {
|
|
2273
|
-
const date = { year: y, month: h.month, day: h.day };
|
|
2274
|
-
if (compare(date, sv) >= 0 && compare(date, ev) <= 0) {
|
|
2275
|
-
result.push({ year: y, month: h.month, day: h.day });
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
return result;
|
|
2280
|
-
}
|
|
2281
|
-
};
|
|
2282
|
-
}
|
|
2283
|
-
function nextHoliday(cal, value) {
|
|
2284
|
-
let candidate = add(value, 1, "days");
|
|
2285
|
-
for (let i = 0; i < 365 * 5; i++) {
|
|
2286
|
-
if (cal.isHoliday(candidate)) return candidate;
|
|
2287
|
-
candidate = add(candidate, 1, "days");
|
|
2288
|
-
}
|
|
2289
|
-
return void 0;
|
|
2290
|
-
}
|
|
2291
|
-
function previousHoliday(cal, value) {
|
|
2292
|
-
let candidate = add(value, -1, "days");
|
|
2293
|
-
for (let i = 0; i < 365 * 5; i++) {
|
|
2294
|
-
if (cal.isHoliday(candidate)) return candidate;
|
|
2295
|
-
candidate = add(candidate, -1, "days");
|
|
2296
|
-
}
|
|
2297
|
-
return void 0;
|
|
2298
|
-
}
|
|
2299
|
-
function holidaysBetween(cal, start, end) {
|
|
2300
|
-
return cal.holidaysBetween(start, end);
|
|
2301
|
-
}
|
|
2302
|
-
|
|
2303
|
-
// src/extensibility.ts
|
|
2304
|
-
function createFormatter(options = {}) {
|
|
2305
|
-
const mergedTokens = [...TOKENS];
|
|
2306
|
-
const customTokenNames = /* @__PURE__ */ new Set();
|
|
2307
|
-
for (const custom of options.tokens ?? []) {
|
|
2308
|
-
customTokenNames.add(custom.name);
|
|
2309
|
-
}
|
|
2310
|
-
for (const custom of options.tokens ?? []) {
|
|
2311
|
-
const existingIdx = mergedTokens.findIndex(([name]) => name === custom.name);
|
|
2312
|
-
if (existingIdx >= 0) {
|
|
2313
|
-
mergedTokens[existingIdx] = [custom.name, custom.handler, custom.field];
|
|
2314
|
-
} else {
|
|
2315
|
-
mergedTokens.push([custom.name, custom.handler, custom.field]);
|
|
2316
|
-
}
|
|
2317
|
-
}
|
|
2318
|
-
mergedTokens.sort((a, b) => b[0].length - a[0].length);
|
|
2319
|
-
const handlerByToken = new Map(mergedTokens.map(([name, handler, field]) => [name, { handler, field }]));
|
|
2320
|
-
const sortedTokenStrings = mergedTokens.map(([name]) => name);
|
|
2321
|
-
function customTokenize(formatStr) {
|
|
2322
|
-
const pieces = [];
|
|
2323
|
-
let i = 0;
|
|
2324
|
-
while (i < formatStr.length) {
|
|
2325
|
-
const ch = formatStr[i];
|
|
2326
|
-
if (ch === "'") {
|
|
2327
|
-
if (formatStr[i + 1] === "'") {
|
|
2328
|
-
appendLiteral(pieces, "'");
|
|
2329
|
-
i += 2;
|
|
2330
|
-
continue;
|
|
2331
|
-
}
|
|
2332
|
-
let j = i + 1;
|
|
2333
|
-
let literal = "";
|
|
2334
|
-
let closed = false;
|
|
2335
|
-
while (j < formatStr.length) {
|
|
2336
|
-
if (formatStr[j] === "'") {
|
|
2337
|
-
if (formatStr[j + 1] === "'") {
|
|
2338
|
-
literal += "'";
|
|
2339
|
-
j += 2;
|
|
2340
|
-
continue;
|
|
2341
|
-
}
|
|
2342
|
-
closed = true;
|
|
2343
|
-
j += 1;
|
|
2344
|
-
break;
|
|
2345
|
-
}
|
|
2346
|
-
literal += formatStr[j];
|
|
2347
|
-
j += 1;
|
|
2348
|
-
}
|
|
2349
|
-
if (!closed) throw new Error(`temporal-fmt: unterminated quote in format string "${formatStr}"`);
|
|
2350
|
-
appendLiteral(pieces, literal);
|
|
2351
|
-
i = j;
|
|
2352
|
-
continue;
|
|
2353
|
-
}
|
|
2354
|
-
const match = sortedTokenStrings.find((tok) => formatStr.startsWith(tok, i));
|
|
2355
|
-
if (match) {
|
|
2356
|
-
pieces.push({ kind: "token", value: match });
|
|
2357
|
-
i += match.length;
|
|
2358
|
-
continue;
|
|
2359
|
-
}
|
|
2360
|
-
appendLiteral(pieces, ch);
|
|
2361
|
-
i += 1;
|
|
2362
|
-
}
|
|
2363
|
-
return pieces;
|
|
2364
|
-
}
|
|
2365
|
-
function appendLiteral(pieces, value) {
|
|
2366
|
-
const last = pieces[pieces.length - 1];
|
|
2367
|
-
if (last && last.kind === "literal") {
|
|
2368
|
-
last.value += value;
|
|
2369
|
-
} else {
|
|
2370
|
-
pieces.push({ kind: "literal", value });
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
const defaultLocale = options.defaultLocale ?? DEFAULT_LOCALE;
|
|
2374
|
-
return {
|
|
2375
|
-
format(temporal, formatStr, opts = {}) {
|
|
2376
|
-
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
2377
|
-
throw new Error(`temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`);
|
|
2378
|
-
}
|
|
2379
|
-
const locale = opts.locale ?? defaultLocale;
|
|
2380
|
-
const pieces = customTokenize(formatStr);
|
|
2381
|
-
let result = "";
|
|
2382
|
-
for (const piece of pieces) {
|
|
2383
|
-
if (piece.kind === "literal") {
|
|
2384
|
-
result += piece.value;
|
|
2385
|
-
continue;
|
|
2386
|
-
}
|
|
2387
|
-
const handler = handlerByToken.get(piece.value);
|
|
2388
|
-
/* c8 ignore start @preserve -- unreachable: customTokenize only ever produces a
|
|
2389
|
-
`kind: 'token'` piece via sortedTokenStrings.find(...), and
|
|
2390
|
-
handlerByToken is built from that same mergedTokens array, so
|
|
2391
|
-
every token piece is guaranteed a handler entry. Guards against a
|
|
2392
|
-
future customTokenize change that decouples the two lookups. */
|
|
2393
|
-
if (!handler) throw new Error(`temporal-fmt: unknown token "${piece.value}"`);
|
|
2394
|
-
/* c8 ignore stop @preserve */
|
|
2395
|
-
if (temporal[handler.field] === void 0) {
|
|
2396
|
-
throw new Error(
|
|
2397
|
-
`temporal-fmt: token "${piece.value}" requires "${String(handler.field)}", which this Temporal object doesn't have.`
|
|
2398
|
-
);
|
|
2399
|
-
}
|
|
2400
|
-
result += handler.handler(temporal, locale);
|
|
2401
|
-
}
|
|
2402
|
-
return result;
|
|
2403
|
-
},
|
|
2404
|
-
formatToParts(temporal, formatStr, opts = {}) {
|
|
2405
|
-
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
2406
|
-
throw new Error(`temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`);
|
|
2407
|
-
}
|
|
2408
|
-
const locale = opts.locale ?? defaultLocale;
|
|
2409
|
-
const pieces = customTokenize(formatStr);
|
|
2410
|
-
const out = [];
|
|
2411
|
-
for (const piece of pieces) {
|
|
2412
|
-
if (piece.kind === "literal") {
|
|
2413
|
-
const last = out[out.length - 1];
|
|
2414
|
-
/* c8 ignore start @preserve -- unreachable: customTokenize's own
|
|
2415
|
-
appendLiteral() already merges adjacent literal chars/quoted
|
|
2416
|
-
spans into a single piece before this loop ever sees them, so
|
|
2417
|
-
two literal pieces are never adjacent here. Kept as a guard
|
|
2418
|
-
against a future customTokenize change that stops merging. */
|
|
2419
|
-
if (last && last.type === "literal") last.value += piece.value;
|
|
2420
|
-
else out.push({ type: "literal", value: piece.value });
|
|
2421
|
-
continue;
|
|
2422
|
-
}
|
|
2423
|
-
const handler = handlerByToken.get(piece.value);
|
|
2424
|
-
/* c8 ignore start @preserve -- unreachable: customTokenize only emits
|
|
2425
|
-
kind:'token' pieces found in sortedTokenStrings, the same array
|
|
2426
|
-
handlerByToken is built from, so every token piece is guaranteed
|
|
2427
|
-
a handler entry. Guards against future decoupling of the two. */
|
|
2428
|
-
if (!handler) throw new Error(`temporal-fmt: unknown token "${piece.value}"`);
|
|
2429
|
-
/* c8 ignore stop @preserve */
|
|
2430
|
-
if (temporal[handler.field] === void 0) {
|
|
2431
|
-
throw new Error(`temporal-fmt: token "${piece.value}" requires "${String(handler.field)}".`);
|
|
2432
|
-
}
|
|
2433
|
-
out.push({ type: "token", value: handler.handler(temporal, locale), token: piece.value });
|
|
2434
|
-
}
|
|
2435
|
-
return out;
|
|
2436
|
-
},
|
|
2437
|
-
compileFormat(formatStr) {
|
|
2438
|
-
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
2439
|
-
throw new Error(`temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`);
|
|
2440
|
-
}
|
|
2441
|
-
const pieces = customTokenize(formatStr);
|
|
2442
|
-
return {
|
|
2443
|
-
formatStr,
|
|
2444
|
-
pieces: pieces.map((p) => p),
|
|
2445
|
-
format(temporal, opts = {}) {
|
|
2446
|
-
const locale = opts.locale ?? defaultLocale;
|
|
2447
|
-
let result = "";
|
|
2448
|
-
for (const piece of pieces) {
|
|
2449
|
-
if (piece.kind === "literal") {
|
|
2450
|
-
result += piece.value;
|
|
2451
|
-
continue;
|
|
2452
|
-
}
|
|
2453
|
-
const handler = handlerByToken.get(piece.value);
|
|
2454
|
-
/* c8 ignore start @preserve -- unreachable, see the same guard's comment
|
|
2455
|
-
above in the un-compiled format(). */
|
|
2456
|
-
if (!handler) throw new Error(`temporal-fmt: unknown token "${piece.value}"`);
|
|
2457
|
-
/* c8 ignore stop @preserve */
|
|
2458
|
-
if (temporal[handler.field] === void 0) {
|
|
2459
|
-
throw new Error(`temporal-fmt: token "${piece.value}" requires "${String(handler.field)}".`);
|
|
2460
|
-
}
|
|
2461
|
-
result += handler.handler(temporal, locale);
|
|
2462
|
-
}
|
|
2463
|
-
return result;
|
|
2464
|
-
},
|
|
2465
|
-
formatToParts(temporal, opts = {}) {
|
|
2466
|
-
const locale = opts.locale ?? defaultLocale;
|
|
2467
|
-
const out = [];
|
|
2468
|
-
for (const piece of pieces) {
|
|
2469
|
-
if (piece.kind === "literal") {
|
|
2470
|
-
const last = out[out.length - 1];
|
|
2471
|
-
/* c8 ignore start @preserve -- unreachable, see the same guard's
|
|
2472
|
-
comment above in the un-compiled formatToParts. */
|
|
2473
|
-
if (last && last.type === "literal") last.value += piece.value;
|
|
2474
|
-
else out.push({ type: "literal", value: piece.value });
|
|
2475
|
-
continue;
|
|
2476
|
-
}
|
|
2477
|
-
const handler = handlerByToken.get(piece.value);
|
|
2478
|
-
/* c8 ignore start @preserve -- unreachable, see the same guard's
|
|
2479
|
-
comment above in the un-compiled formatToParts. */
|
|
2480
|
-
if (!handler) throw new Error(`temporal-fmt: unknown token "${piece.value}"`);
|
|
2481
|
-
/* c8 ignore stop @preserve */
|
|
2482
|
-
if (temporal[handler.field] === void 0) {
|
|
2483
|
-
throw new Error(`temporal-fmt: token "${piece.value}" requires "${String(handler.field)}".`);
|
|
2484
|
-
}
|
|
2485
|
-
out.push({ type: "token", value: handler.handler(temporal, locale), token: piece.value });
|
|
2486
|
-
}
|
|
2487
|
-
return out;
|
|
2488
|
-
}
|
|
2489
|
-
};
|
|
2490
|
-
}
|
|
2491
|
-
};
|
|
2492
|
-
}
|
|
2493
|
-
|
|
2494
|
-
// src/ideData.ts
|
|
2495
|
-
function tokenFamily(name) {
|
|
2496
|
-
if (/^y+$/.test(name)) return "Year";
|
|
2497
|
-
if (/^[ML]+$/.test(name)) return "Month";
|
|
2498
|
-
if (/^[decD]+$/.test(name)) return "Day";
|
|
2499
|
-
if (/^[Ec]+$/.test(name)) return "Weekday";
|
|
2500
|
-
if (/^[Qq]+$/.test(name)) return "Quarter";
|
|
2501
|
-
if (/^[Gg]+$/.test(name)) return "Era";
|
|
2502
|
-
if (/^[Hh]+$/.test(name)) return "Hour";
|
|
2503
|
-
if (/^m+$/.test(name)) return "Minute";
|
|
2504
|
-
if (/^s+$/.test(name)) return "Second";
|
|
2505
|
-
if (/^S+$/.test(name)) return "Fractional Second";
|
|
2506
|
-
if (name === "a") return "Day Period";
|
|
2507
|
-
if (name === "zzz") return "Time Zone";
|
|
2508
|
-
if (/^[Xx]+$/.test(name)) return "UTC Offset";
|
|
2509
|
-
if (name === "do") return "Ordinal Day";
|
|
2510
|
-
if (name === "ww" || name === "RRRR") return "ISO Week";
|
|
2511
|
-
return "Other";
|
|
2512
|
-
}
|
|
2513
|
-
function getAutocompleteData() {
|
|
2514
|
-
return ALL_TOKEN_NAMES.map((name) => {
|
|
2515
|
-
const meta = TOKEN_METADATA[name];
|
|
2516
|
-
return {
|
|
2517
|
-
label: name,
|
|
2518
|
-
detail: meta.meaning,
|
|
2519
|
-
documentation: [
|
|
2520
|
-
meta.meaning,
|
|
2521
|
-
``,
|
|
2522
|
-
`Format-capable: ${meta.formatCapable}`,
|
|
2523
|
-
`Parse-capable: ${meta.parseCapable}`,
|
|
2524
|
-
`Locale-sensitive: ${meta.localeSensitive}`,
|
|
2525
|
-
`Calendar-sensitive: ${meta.calendarSensitive}`,
|
|
2526
|
-
`Timezone-sensitive: ${meta.timezoneSensitive}`,
|
|
2527
|
-
`Round-trip safe: ${meta.roundTripSafe}`,
|
|
2528
|
-
`Supported types: ${meta.supportedTypes.join(", ")}`
|
|
2529
|
-
].join("\n"),
|
|
2530
|
-
family: tokenFamily(name)
|
|
2531
|
-
};
|
|
2532
|
-
});
|
|
2533
|
-
}
|
|
2534
|
-
function getHoverDocs() {
|
|
2535
|
-
const result = {};
|
|
2536
|
-
for (const name of ALL_TOKEN_NAMES) {
|
|
2537
|
-
const meta = TOKEN_METADATA[name];
|
|
2538
|
-
result[name] = {
|
|
2539
|
-
signature: name,
|
|
2540
|
-
summary: meta.meaning,
|
|
2541
|
-
details: [
|
|
2542
|
-
// every entry in TOKEN_METADATA currently has formatCapable:
|
|
2543
|
-
// true (verified: 51/51). The 'no' branch reflects real,
|
|
2544
|
-
// intended behavior for a future format-incapable token —
|
|
2545
|
-
// there's no such token today, so this isn't reachable data,
|
|
2546
|
-
// not dead logic. Every other field on this line has real
|
|
2547
|
-
// true/false variance across the token table and is exercised
|
|
2548
|
-
// by this same loop running over ALL_TOKEN_NAMES.
|
|
2549
|
-
/* c8 ignore next */
|
|
2550
|
-
`Format-capable: ${meta.formatCapable ? "yes" : "no"}`,
|
|
2551
|
-
`Parse-capable: ${meta.parseCapable ? "yes" : "no"}`,
|
|
2552
|
-
`Locale-sensitive: ${meta.localeSensitive ? "yes" : "no"}`,
|
|
2553
|
-
`Calendar-sensitive: ${meta.calendarSensitive ? "yes" : "no"}`,
|
|
2554
|
-
`Timezone-sensitive: ${meta.timezoneSensitive ? "yes" : "no"}`,
|
|
2555
|
-
`Round-trip safe: ${meta.roundTripSafe ? "yes" : "no"}`,
|
|
2556
|
-
`Supported types: ${meta.supportedTypes.join(", ")}`
|
|
2557
|
-
].join("\n")
|
|
2558
|
-
};
|
|
2559
|
-
}
|
|
2560
|
-
return result;
|
|
2561
|
-
}
|
|
2562
|
-
function getInlineDiagnostics(formatStr) {
|
|
2563
|
-
const analysis = analyzeFormat(formatStr);
|
|
2564
|
-
const diagnostics = [];
|
|
2565
|
-
for (const warning of analysis.warnings) {
|
|
2566
|
-
let message = warning.message;
|
|
2567
|
-
let suggestion;
|
|
2568
|
-
if (warning.code === "TWELVE_HOUR_WITHOUT_A") {
|
|
2569
|
-
suggestion = 'Add an "a" token (e.g. "h:mm a") or use "H:mm" for 24-hour.';
|
|
2570
|
-
} else if (warning.code === "MIXED_12_AND_24_HOUR") {
|
|
2571
|
-
suggestion = 'Pick one form: "HH:mm" for 24-hour or "h:mm a" for 12-hour.';
|
|
2572
|
-
} else if (warning.code === "AMBIGUOUS_NUMERIC_RUN") {
|
|
2573
|
-
suggestion = 'Add a separator or use padded forms (e.g. "MM" instead of "M").';
|
|
2574
|
-
} else if (warning.code === "FORMAT_ONLY_TOKEN") {
|
|
2575
|
-
suggestion = 'Use a parse-capable variant (e.g. "d" instead of "do").';
|
|
2576
|
-
}
|
|
2577
|
-
diagnostics.push({
|
|
2578
|
-
startColumn: 0,
|
|
2579
|
-
endColumn: formatStr.length,
|
|
2580
|
-
severity: "warning",
|
|
2581
|
-
message,
|
|
2582
|
-
code: warning.code,
|
|
2583
|
-
suggestion
|
|
2584
|
-
});
|
|
2585
|
-
}
|
|
2586
|
-
return diagnostics;
|
|
2587
|
-
}
|
|
2588
|
-
var DAYJS_TO_TEMPORAL_FMT = [
|
|
2589
|
-
{ from: "YYYY", to: "yyyy" },
|
|
2590
|
-
{ from: "YY", to: "yy" },
|
|
2591
|
-
{ from: "MMMM", to: "MMMM" },
|
|
2592
|
-
{ from: "MMM", to: "MMM" },
|
|
2593
|
-
{ from: "MM", to: "MM" },
|
|
2594
|
-
{ from: "M", to: "M" },
|
|
2595
|
-
{ from: "DD", to: "dd" },
|
|
2596
|
-
{ from: "D", to: "d" },
|
|
2597
|
-
{ from: "Do", to: null, notes: `Ordinal day (AdvancedFormat) \u2014 use temporal-fmt's own "do" token instead.` },
|
|
2598
|
-
{ from: "dddd", to: "EEEE" },
|
|
2599
|
-
{ from: "ddd", to: "EEE" },
|
|
2600
|
-
{ from: "dd", to: null, notes: 'Min-name weekday (e.g. "Tu") \u2014 temporal-fmt has no equivalent width.' },
|
|
2601
|
-
{ from: "d", to: null, notes: 'Numeric weekday (0-6) \u2014 no temporal-fmt equivalent; not the same as "d" here, which is day-of-month.' },
|
|
2602
|
-
{ from: "HH", to: "HH" },
|
|
2603
|
-
{ from: "H", to: "H" },
|
|
2604
|
-
{ from: "hh", to: "hh" },
|
|
2605
|
-
{ from: "h", to: "h" },
|
|
2606
|
-
{ from: "kk", to: null, notes: "Hour 1-24 (AdvancedFormat) \u2014 no temporal-fmt equivalent." },
|
|
2607
|
-
{ from: "k", to: null, notes: "Hour 1-24 (AdvancedFormat) \u2014 no temporal-fmt equivalent." },
|
|
2608
|
-
{ from: "mm", to: "mm" },
|
|
2609
|
-
{ from: "m", to: "m" },
|
|
2610
|
-
{ from: "ss", to: "ss" },
|
|
2611
|
-
{ from: "s", to: "s" },
|
|
2612
|
-
{ from: "SSS", to: "SSS" },
|
|
2613
|
-
{ from: "A", to: "a", notes: "Uppercase AM/PM in Day.js \u2014 temporal-fmt is always lowercase." },
|
|
2614
|
-
{ from: "a", to: "a" },
|
|
2615
|
-
{ from: "ZZ", to: "XX", notes: "Numeric UTC offset, no colon." },
|
|
2616
|
-
{ from: "Z", to: "XXX", notes: "Numeric UTC offset with colon." },
|
|
2617
|
-
{ from: "X", to: null, notes: "Unix timestamp (seconds) \u2014 use fromUnixSeconds() instead." },
|
|
2618
|
-
{ from: "x", to: null, notes: "Unix timestamp (ms) \u2014 use fromUnixMilliseconds() instead." },
|
|
2619
|
-
{ from: "Qo", to: null, notes: "Ordinal quarter (AdvancedFormat) \u2014 no temporal-fmt equivalent." },
|
|
2620
|
-
{ from: "Q", to: "Q" },
|
|
2621
|
-
{ from: "Mo", to: null, notes: "Ordinal month (AdvancedFormat) \u2014 no temporal-fmt equivalent." },
|
|
2622
|
-
{ from: "ww", to: "ww" },
|
|
2623
|
-
{ from: "wo", to: null, notes: "Ordinal ISO week (AdvancedFormat) \u2014 no temporal-fmt equivalent." },
|
|
2624
|
-
{ from: "w", to: null, notes: `Unpadded ISO week \u2014 temporal-fmt's "ww" is always 2-digit.` },
|
|
2625
|
-
{ from: "gggg", to: "RRRR", notes: "Week-numbering year, not the calendar year \u2014 same caveat as temporal-fmt's RRRR." },
|
|
2626
|
-
{ from: "L", to: null, notes: "Localized date format (AdvancedFormat) \u2014 write the format string out explicitly." },
|
|
2627
|
-
{ from: "LL", to: null, notes: "Localized date format (AdvancedFormat) \u2014 write the format string out explicitly." },
|
|
2628
|
-
{ from: "LLL", to: null, notes: "Localized date format (AdvancedFormat) \u2014 write the format string out explicitly." },
|
|
2629
|
-
{ from: "LLLL", to: null, notes: "Localized date format (AdvancedFormat) \u2014 write the format string out explicitly." },
|
|
2630
|
-
{ from: "LT", to: null, notes: "Localized time format (AdvancedFormat) \u2014 write the format string out explicitly." },
|
|
2631
|
-
{ from: "LTS", to: null, notes: "Localized time format (AdvancedFormat) \u2014 write the format string out explicitly." }
|
|
2632
|
-
];
|
|
2633
|
-
var DATE_FNS_TO_TEMPORAL_FMT = [
|
|
2634
|
-
{ from: "yyyy", to: "yyyy" },
|
|
2635
|
-
{ from: "yy", to: "yy" },
|
|
2636
|
-
{ from: "y", to: null, notes: 'Unpadded calendar year, opt-in via useAdditionalWeekYearTokens \u2014 temporal-fmt has no unpadded-year token; use "yyyy".' },
|
|
2637
|
-
{ from: "MMMM", to: "MMMM" },
|
|
2638
|
-
{ from: "MMM", to: "MMM" },
|
|
2639
|
-
{ from: "MM", to: "MM" },
|
|
2640
|
-
{ from: "M", to: "M" },
|
|
2641
|
-
{ from: "LLLL", to: "LLLL" },
|
|
2642
|
-
{ from: "LLL", to: "LLL" },
|
|
2643
|
-
{ from: "dd", to: "dd" },
|
|
2644
|
-
{ from: "d", to: "d" },
|
|
2645
|
-
{ from: "do", to: "do" },
|
|
2646
|
-
{ from: "DDD", to: "DDD" },
|
|
2647
|
-
{ from: "DD", to: "DD" },
|
|
2648
|
-
{ from: "D", to: "D", notes: `Day-of-year, opt-in via useAdditionalDayOfYearTokens \u2014 matches temporal-fmt's own "D" already.` },
|
|
2649
|
-
{ from: "EEEE", to: "EEEE" },
|
|
2650
|
-
{ from: "EEE", to: "EEE" },
|
|
2651
|
-
{ from: "eeee", to: null, notes: "Locale-aware numeric weekday \u2014 no temporal-fmt equivalent." },
|
|
2652
|
-
{ from: "cccc", to: "cccc" },
|
|
2653
|
-
{ from: "ccc", to: "ccc" },
|
|
2654
|
-
{ from: "HH", to: "HH" },
|
|
2655
|
-
{ from: "H", to: "H" },
|
|
2656
|
-
{ from: "hh", to: "hh" },
|
|
2657
|
-
{ from: "h", to: "h" },
|
|
2658
|
-
{ from: "mm", to: "mm" },
|
|
2659
|
-
{ from: "m", to: "m" },
|
|
2660
|
-
{ from: "ss", to: "ss" },
|
|
2661
|
-
{ from: "s", to: "s" },
|
|
2662
|
-
{ from: "SSS", to: "SSS" },
|
|
2663
|
-
{ from: "a", to: "a" },
|
|
2664
|
-
{ from: "aaa", to: "a" },
|
|
2665
|
-
{ from: "XXX", to: "XXX" },
|
|
2666
|
-
{ from: "XX", to: "XX" },
|
|
2667
|
-
{ from: "X", to: "X", notes: `Opt-in via useAdditionalDayOfYearTokens-adjacent rules in date-fns v3+; matches temporal-fmt's own "X" already.` },
|
|
2668
|
-
{ from: "xxx", to: "xxx" },
|
|
2669
|
-
{ from: "xx", to: "xx" },
|
|
2670
|
-
{ from: "x", to: "x" },
|
|
2671
|
-
{ from: "zzzz", to: "zzzz" },
|
|
2672
|
-
{ from: "zzz", to: "zzz" },
|
|
2673
|
-
{ from: "z", to: "z" },
|
|
2674
|
-
{ from: "QQQ", to: "QQQ" },
|
|
2675
|
-
{ from: "Q", to: "Q" },
|
|
2676
|
-
{ from: "GGGG", to: "GGGG" },
|
|
2677
|
-
{ from: "GGG", to: null, notes: 'Abbreviated era \u2014 temporal-fmt only has "G" (short) and "GGGG" (long).' },
|
|
2678
|
-
{ from: "GG", to: null, notes: 'Abbreviated era \u2014 temporal-fmt only has "G" (short) and "GGGG" (long).' },
|
|
2679
|
-
{ from: "G", to: "G" },
|
|
2680
|
-
{ from: "ww", to: "ww" },
|
|
2681
|
-
{ from: "w", to: null, notes: `Unpadded local week number \u2014 temporal-fmt's "ww" is ISO-week and always 2-digit.` },
|
|
2682
|
-
{ from: "RRRR", to: "RRRR" },
|
|
2683
|
-
{ from: "R", to: null, notes: `Unpadded ISO week-numbering year \u2014 temporal-fmt's "RRRR" is always 4-digit.` },
|
|
2684
|
-
{ from: "Y", to: null, notes: 'Week-numbering year (locale week rules), opt-in \u2014 no temporal-fmt equivalent; "RRRR" is ISO week-numbering, a different rule set.' },
|
|
2685
|
-
{ from: "PPPP", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2686
|
-
{ from: "PPP", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2687
|
-
{ from: "PP", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2688
|
-
{ from: "P", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2689
|
-
{ from: "pppp", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2690
|
-
{ from: "ppp", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2691
|
-
{ from: "pp", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2692
|
-
{ from: "p", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." }
|
|
2693
|
-
];
|
|
2694
|
-
function previewFormat(formatStr, sample) {
|
|
2695
|
-
const value = sample ?? {
|
|
2696
|
-
year: 2026,
|
|
2697
|
-
month: 8,
|
|
2698
|
-
day: 4,
|
|
2699
|
-
hour: 15,
|
|
2700
|
-
minute: 45,
|
|
2701
|
-
second: 30,
|
|
2702
|
-
millisecond: 123,
|
|
2703
|
-
dayOfWeek: 2,
|
|
2704
|
-
timeZoneId: "UTC",
|
|
2705
|
-
offset: "+00:00",
|
|
2706
|
-
calendarId: "iso8601"
|
|
2707
|
-
};
|
|
2708
|
-
return format(value, formatStr, { locale: "en-US" });
|
|
2709
|
-
}
|
|
2710
|
-
function getDocUrl(tokenName) {
|
|
2711
|
-
void tokenName;
|
|
2712
|
-
return "README.md#token-reference";
|
|
2713
|
-
}
|
|
2714
|
-
|
|
2715
|
-
// src/codemod.ts
|
|
2716
|
-
function splitOnBrackets(source) {
|
|
2717
|
-
const pieces = [];
|
|
2718
|
-
let i = 0;
|
|
2719
|
-
while (i < source.length) {
|
|
2720
|
-
if (source[i] === "[") {
|
|
2721
|
-
const end = source.indexOf("]", i + 1);
|
|
2722
|
-
if (end === -1) {
|
|
2723
|
-
pieces.push({ kind: "token", value: source.slice(i) });
|
|
2724
|
-
break;
|
|
2725
|
-
}
|
|
2726
|
-
pieces.push({ kind: "literal", value: source.slice(i + 1, end) });
|
|
2727
|
-
i = end + 1;
|
|
2728
|
-
} else {
|
|
2729
|
-
let j = i;
|
|
2730
|
-
while (j < source.length && source[j] !== "[") j += 1;
|
|
2731
|
-
pieces.push({ kind: "token", value: source.slice(i, j) });
|
|
2732
|
-
i = j;
|
|
2733
|
-
}
|
|
2734
|
-
}
|
|
2735
|
-
return pieces;
|
|
2736
|
-
}
|
|
2737
|
-
function splitIntoRuns(span, sortedFrom) {
|
|
2738
|
-
const pieces = [];
|
|
2739
|
-
let i = 0;
|
|
2740
|
-
while (i < span.length) {
|
|
2741
|
-
const match = sortedFrom.find((tok) => span.startsWith(tok, i));
|
|
2742
|
-
if (match) {
|
|
2743
|
-
pieces.push({ kind: "token", value: match });
|
|
2744
|
-
i += match.length;
|
|
2745
|
-
continue;
|
|
2746
|
-
}
|
|
2747
|
-
const last = pieces[pieces.length - 1];
|
|
2748
|
-
if (last && last.kind === "literal") {
|
|
2749
|
-
last.value += span[i];
|
|
2750
|
-
} else {
|
|
2751
|
-
pieces.push({ kind: "literal", value: span[i] });
|
|
2752
|
-
}
|
|
2753
|
-
i += 1;
|
|
2754
|
-
}
|
|
2755
|
-
return pieces;
|
|
2756
|
-
}
|
|
2757
|
-
function translate(source, table, sourceLibLabel) {
|
|
2758
|
-
const byFrom = new Map(table.map((hint) => [hint.from, hint.to]));
|
|
2759
|
-
const sortedFrom = [...byFrom.keys()].sort((a, b) => b.length - a.length);
|
|
2760
|
-
const bracketPieces = splitOnBrackets(source);
|
|
2761
|
-
let out = "";
|
|
2762
|
-
for (const piece of bracketPieces) {
|
|
2763
|
-
if (piece.kind === "literal") {
|
|
2764
|
-
out += `'${piece.value.replace(/'/g, "''")}'`;
|
|
2765
|
-
continue;
|
|
2766
|
-
}
|
|
2767
|
-
for (const run of splitIntoRuns(piece.value, sortedFrom)) {
|
|
2768
|
-
if (run.kind === "token") {
|
|
2769
|
-
const mapped = byFrom.get(run.value);
|
|
2770
|
-
if (mapped === void 0 || mapped === null) {
|
|
2771
|
-
throw new Error(
|
|
2772
|
-
`temporal-fmt: "${run.value}" has no ${sourceLibLabel} -> temporal-fmt mapping (in format string "${source}"). Write the equivalent temporal-fmt token in by hand, or wrap it in brackets if it was meant as literal text.`
|
|
2773
|
-
);
|
|
2774
|
-
}
|
|
2775
|
-
out += mapped;
|
|
2776
|
-
} else if (/[a-zA-Z]/.test(run.value)) {
|
|
2777
|
-
out += `'${run.value.replace(/'/g, "''")}'`;
|
|
2778
|
-
} else {
|
|
2779
|
-
out += run.value;
|
|
2780
|
-
}
|
|
2781
|
-
}
|
|
2782
|
-
}
|
|
2783
|
-
return out;
|
|
2784
|
-
}
|
|
2785
|
-
function translateDayjsFormatString(formatStr) {
|
|
2786
|
-
return translate(formatStr, DAYJS_TO_TEMPORAL_FMT, "Day.js");
|
|
2787
|
-
}
|
|
2788
|
-
function translateDateFnsFormatString(formatStr) {
|
|
2789
|
-
return translate(formatStr, DATE_FNS_TO_TEMPORAL_FMT, "date-fns");
|
|
2790
|
-
}
|
|
2791
|
-
export {
|
|
2792
|
-
ALL_TOKEN_NAMES,
|
|
2793
|
-
AmbiguousInputError,
|
|
2794
|
-
DATE_FNS_TO_TEMPORAL_FMT,
|
|
2795
|
-
DAYJS_TO_TEMPORAL_FMT,
|
|
2796
|
-
DEFAULT_CONFIG,
|
|
2797
|
-
FORMAT_ONLY_TOKENS,
|
|
2798
|
-
FormatSyntaxError,
|
|
2799
|
-
InvalidCalendarError,
|
|
2800
|
-
InvalidDateError,
|
|
2801
|
-
InvalidDurationError,
|
|
2802
|
-
InvalidLocaleError,
|
|
2803
|
-
InvalidOffsetError,
|
|
2804
|
-
InvalidTimeError,
|
|
2805
|
-
InvalidTimeZoneError,
|
|
2806
|
-
ParseMismatchError,
|
|
2807
|
-
SUPPORTED_NUMBERING_SYSTEMS,
|
|
2808
|
-
TOKEN_METADATA,
|
|
2809
|
-
TemporalFmtError,
|
|
2810
|
-
UnknownTokenError,
|
|
2811
|
-
add,
|
|
2812
|
-
addBusinessDays,
|
|
2813
|
-
addDays,
|
|
2814
|
-
addDuration,
|
|
2815
|
-
addHours,
|
|
2816
|
-
addMilliseconds,
|
|
2817
|
-
addMinutes,
|
|
2818
|
-
addMonths,
|
|
2819
|
-
addSeconds,
|
|
2820
|
-
addWeeks,
|
|
2821
|
-
addYears,
|
|
2822
|
-
analyzeFormat,
|
|
2823
|
-
applyNumbering,
|
|
2824
|
-
applyParseNumbering,
|
|
2825
|
-
asDateFieldView,
|
|
2826
|
-
assertDuration,
|
|
2827
|
-
assertInstant,
|
|
2828
|
-
assertPlainDate,
|
|
2829
|
-
assertPlainDateTime,
|
|
2830
|
-
assertPlainMonthDay,
|
|
2831
|
-
assertPlainTime,
|
|
2832
|
-
assertPlainYearMonth,
|
|
2833
|
-
assertTemporal,
|
|
2834
|
-
assertZonedDateTime,
|
|
2835
|
-
balanceDuration,
|
|
2836
|
-
between,
|
|
2837
|
-
ceil,
|
|
2838
|
-
clamp,
|
|
2839
|
-
compare,
|
|
2840
|
-
compareDuration,
|
|
2841
|
-
compileFormat,
|
|
2842
|
-
compileParser,
|
|
2843
|
-
convertDigits,
|
|
2844
|
-
convertDigitsToAscii,
|
|
2845
|
-
createBusinessCalendar,
|
|
2846
|
-
createConfig,
|
|
2847
|
-
createFormatter,
|
|
2848
|
-
createHolidayCalendar,
|
|
2849
|
-
dayOfYearHelper as dayOfYear,
|
|
2850
|
-
daysInMonth,
|
|
2851
|
-
daysInYear,
|
|
2852
|
-
difference,
|
|
2853
|
-
differenceInBusinessDays,
|
|
2854
|
-
differenceInDays,
|
|
2855
|
-
differenceInHours,
|
|
2856
|
-
differenceInMilliseconds,
|
|
2857
|
-
differenceInMinutes,
|
|
2858
|
-
differenceInMonths,
|
|
2859
|
-
differenceInSeconds,
|
|
2860
|
-
differenceInWeeks,
|
|
2861
|
-
differenceInYears,
|
|
2862
|
-
endOf,
|
|
2863
|
-
explainFormat,
|
|
2864
|
-
fieldForToken,
|
|
2865
|
-
floor,
|
|
2866
|
-
format,
|
|
2867
|
-
formatDistance,
|
|
2868
|
-
formatDistanceToNow,
|
|
2869
|
-
formatDuration,
|
|
2870
|
-
formatDurationToParts,
|
|
2871
|
-
formatHTTPDate,
|
|
2872
|
-
formatISO,
|
|
2873
|
-
formatISODuration,
|
|
2874
|
-
formatRFC2822,
|
|
2875
|
-
formatRFC3339,
|
|
2876
|
-
formatRRule,
|
|
2877
|
-
formatRange,
|
|
2878
|
-
formatRangeToParts,
|
|
2879
|
-
formatRelative,
|
|
2880
|
-
formatRelativeToNow,
|
|
2881
|
-
formatSQL,
|
|
2882
|
-
formatToParts,
|
|
2883
|
-
fromUnixMicroseconds,
|
|
2884
|
-
fromUnixMilliseconds,
|
|
2885
|
-
fromUnixNanoseconds,
|
|
2886
|
-
fromUnixSeconds,
|
|
2887
|
-
getAutocompleteData,
|
|
2888
|
-
getDocUrl,
|
|
2889
|
-
getHoverDocs,
|
|
2890
|
-
getInlineDiagnostics,
|
|
2891
|
-
getLocale,
|
|
2892
|
-
getMonth,
|
|
2893
|
-
getNextTransition,
|
|
2894
|
-
getOffset,
|
|
2895
|
-
getOffsetNanoseconds,
|
|
2896
|
-
getPreviousTransition,
|
|
2897
|
-
getQuarter,
|
|
2898
|
-
getTimeZone,
|
|
2899
|
-
getTransitions,
|
|
2900
|
-
getWeekday,
|
|
2901
|
-
hasLocale,
|
|
2902
|
-
holidaysBetween,
|
|
2903
|
-
intersection,
|
|
2904
|
-
intersects,
|
|
2905
|
-
interval,
|
|
2906
|
-
contains as intervalContains,
|
|
2907
|
-
difference2 as intervalDifference,
|
|
2908
|
-
isAfter2 as intervalIsAfter,
|
|
2909
|
-
isBefore2 as intervalIsBefore,
|
|
2910
|
-
subtract2 as intervalSubtract,
|
|
2911
|
-
isAfter,
|
|
2912
|
-
isBefore,
|
|
2913
|
-
isBetween,
|
|
2914
|
-
isBusinessDay,
|
|
2915
|
-
isDST,
|
|
2916
|
-
isDuration,
|
|
2917
|
-
isEqual,
|
|
2918
|
-
isInstant,
|
|
2919
|
-
isLeapMonth,
|
|
2920
|
-
isLeapYear,
|
|
2921
|
-
isPlainDate,
|
|
2922
|
-
isPlainDateTime,
|
|
2923
|
-
isPlainMonthDay,
|
|
2924
|
-
isPlainTime,
|
|
2925
|
-
isPlainYearMonth,
|
|
2926
|
-
isSameDay,
|
|
2927
|
-
isSameMonth,
|
|
2928
|
-
isSameQuarter,
|
|
2929
|
-
isSameWeek,
|
|
2930
|
-
isSameYear,
|
|
2931
|
-
isTemporal,
|
|
2932
|
-
isToday,
|
|
2933
|
-
isTomorrow,
|
|
2934
|
-
isValidFormat,
|
|
2935
|
-
isWeekday,
|
|
2936
|
-
isWeekend,
|
|
2937
|
-
isYesterday,
|
|
2938
|
-
isZonedDateTime,
|
|
2939
|
-
listRegisteredGrammars,
|
|
2940
|
-
listTokens,
|
|
2941
|
-
max,
|
|
2942
|
-
mergeIntervals,
|
|
2943
|
-
mergeWithConfig,
|
|
2944
|
-
min,
|
|
2945
|
-
monthsInYear,
|
|
2946
|
-
nextBusinessDay,
|
|
2947
|
-
nextHoliday,
|
|
2948
|
-
overlaps,
|
|
2949
|
-
parse,
|
|
2950
|
-
parseDuration,
|
|
2951
|
-
parseHTTPDate,
|
|
2952
|
-
parseISO,
|
|
2953
|
-
parseISODuration,
|
|
2954
|
-
parseRFC2822,
|
|
2955
|
-
parseRFC3339,
|
|
2956
|
-
parseRRule,
|
|
2957
|
-
parseRelative,
|
|
2958
|
-
parseSQL,
|
|
2959
|
-
parseToParts,
|
|
2960
|
-
possibleInstantsFor,
|
|
2961
|
-
previewFormat,
|
|
2962
|
-
previousBusinessDay,
|
|
2963
|
-
previousHoliday,
|
|
2964
|
-
recurrence,
|
|
2965
|
-
registerLocale,
|
|
2966
|
-
registerLocaleVocab,
|
|
2967
|
-
registerRelativeGrammar,
|
|
2968
|
-
resolveZoned,
|
|
2969
|
-
round,
|
|
2970
|
-
roundDuration,
|
|
2971
|
-
roundDuration as roundDurationAlias,
|
|
2972
|
-
safeParse,
|
|
2973
|
-
setTemporal,
|
|
2974
|
-
skip,
|
|
2975
|
-
splitInterval,
|
|
2976
|
-
startOf,
|
|
2977
|
-
subtract,
|
|
2978
|
-
subtractBusinessDays,
|
|
2979
|
-
subtractDays,
|
|
2980
|
-
subtractDuration,
|
|
2981
|
-
subtractHours,
|
|
2982
|
-
subtractMilliseconds,
|
|
2983
|
-
subtractMinutes,
|
|
2984
|
-
subtractMonths,
|
|
2985
|
-
subtractSeconds,
|
|
2986
|
-
subtractWeeks,
|
|
2987
|
-
subtractYears,
|
|
2988
|
-
take,
|
|
2989
|
-
toUnixMicroseconds,
|
|
2990
|
-
toUnixMilliseconds,
|
|
2991
|
-
toUnixNanoseconds,
|
|
2992
|
-
toUnixSeconds,
|
|
2993
|
-
tokenInfo,
|
|
2994
|
-
tokenizeFormat,
|
|
2995
|
-
totalDuration,
|
|
2996
|
-
translateDateFnsFormatString,
|
|
2997
|
-
translateDayjsFormatString,
|
|
2998
|
-
truncate,
|
|
2999
|
-
tryParse,
|
|
3000
|
-
union,
|
|
3001
|
-
validateFormat,
|
|
3002
|
-
weekOfYear,
|
|
3003
|
-
weekYear
|
|
3004
|
-
};
|
|
1
|
+
import{a as nr,b as tr}from"./chunk-NBXF7V5B.js";import{a as Er,b as xr,c as Cr,d as Rr,e as Fr,f as $r,g as Ir,h as Ar,i as Or}from"./chunk-J2AQNXF2.js";import{a as _n,b as Ln,c as Hn,d as Un,e as $e,f as Gn,g as Zn,h as Wn,i as Yn,j as Bn,k as Xn,l as qn,m as Kn,n as Jn,o as Qn}from"./chunk-2JHEV7ZF.js";import{a as ir,b as sr,c as lr,d as mr,e as ur,f as dr,g as cr,h as fr,i as pr,j as yr,k as gr,l as hr,m as Tr,n as wr}from"./chunk-F4RGUDA3.js";import{a as L,b as at,c as it,e as he}from"./chunk-4JWGUR4O.js";import{a as rr,b as or,c as ar}from"./chunk-XH46JNPK.js";import{a as st,b as Ae,c as K,d as lt,e as mt,f as ut,g as dt}from"./chunk-YB6YAG7E.js";import{a as q,b as et,c as nt,d as tt,e as rt,f as ot}from"./chunk-R52YOKI3.js";import{a as _,b as X}from"./chunk-C5YESWFT.js";import{b as Vn,c as A}from"./chunk-3MZLTVP3.js";import{a as Fn,b as w,c as pe,d as $n,e as ye,f as In,g as An,h as On,i as Pn,j as zn,k as ge,l as Nn,o as jn,p as Ie}from"./chunk-5U5WJ465.js";import{a as vr,b as br,c as Sr,d as kr,e as Mr,f as Dr}from"./chunk-ZGMTY52O.js";import{A as Nt,a as v,b as ct,c as ft,d as pt,e as yt,f as gt,g as ht,h as Tt,i as wt,j as vt,k as bt,l as St,m as kt,n as Mt,o as Dt,p as Et,q as xt,r as Ct,s as Rt,t as Ft,u as $t,v as It,w as At,x as Ot,y as Pt,z as zt}from"./chunk-VQXUMFB2.js";import{a as J,b as _t,c as Lt,d as Ht,e as Ut,f as jt,g as Gt,h as Zt,i as Wt,j as Yt,k as Bt,l as Xt,m as qt,n as Kt,o as Jt,p as Qt,q as Vt,r as er}from"./chunk-UJR6DHXY.js";import{a as gn,b as hn,c as Tn,d as wn,e as vn,f as bn,g as Sn,h as kn,i as Mn,j as Dn,k as En,l as xn,m as Cn,n as Rn}from"./chunk-EHLRZULM.js";import{a as fe,b as Fe}from"./chunk-C6ZZ62ET.js";function Oe(e,n){if(e===null||typeof e!="object")throw new Error(`temporal-fmt: formatDistance expects Temporal values, got ${n} = ${String(e)}.`);let t=e,r=typeof t.year=="number",a=typeof t.month=="number",o=typeof t.day=="number";if(r!==a||a!==o)throw new Error(`temporal-fmt: formatDistance got a ${n} with a partial date (some of year/month/day missing). Pass a full Temporal.PlainDate / PlainDateTime / ZonedDateTime.`);return{year:r?t.year:void 0,month:a?t.month:void 0,day:o?t.day:void 0,hour:typeof t.hour=="number"?t.hour:void 0,minute:typeof t.minute=="number"?t.minute:void 0,second:typeof t.second=="number"?t.second:void 0,millisecond:typeof t.millisecond=="number"?t.millisecond:void 0}}var Te=2e3,Q=1e3,V=60*Q,ee=60*V,F=24*ee;function Pr(e,n,t){let r=0;if(e>=Te)for(let a=Te;a<e;a++)r+=fe(a)?366:365;else for(let a=e;a<Te;a++)r-=fe(a)?366:365;return r+=Fe(e,n,t)-1,r}function Pe(e){if(e.year===void 0||e.month===void 0||e.day===void 0)throw new Error("temporal-fmt: formatDistance needs a Temporal value with year/month/day fields (PlainDate, PlainDateTime, or ZonedDateTime). A PlainTime or other shape has no anchor date to diff against.");let n=Pr(e.year,e.month,e.day),t=e.hour??0,r=e.minute??0,a=e.second??0,o=e.millisecond??0;return n*F+t*ee+r*V+a*Q+o}var zr={seconds:60,minutes:60,hours:24,days:30,months:365};function Nr(e){let n={...zr,...e};for(let d of Object.keys(n)){let i=n[d];if(typeof i!="number"||!Number.isFinite(i)||i<=0)throw new Error(`temporal-fmt: formatDistance cutoff "${d}" must be a positive finite number (got ${String(i)}).`)}let t=n.seconds*Q,r=n.minutes*V,a=n.hours*ee,o=n.days*F,s=n.months*F;if(!(t<=r&&r<=a&&a<=o&&o<=s))throw new Error(`temporal-fmt: formatDistance cutoffs must be monotonically non-decreasing in equivalent ms (seconds \u2264 minutes \u2264 hours \u2264 days \u2264 months). Got: seconds=${n.seconds}s, minutes=${n.minutes}min, hours=${n.hours}h, days=${n.days}d, months=${n.months}d \u2014 pick a sequence where each boundary is at least as large as the one before it.`);return[{maxMs:t,unit:"second"},{maxMs:r,unit:"minute"},{maxMs:a,unit:"hour"},{maxMs:o,unit:"day"},{maxMs:s,unit:"month"}]}var G=new Map,_r=100;function Lr(e,n){let t=`${Hr(e)}|${n}`,r=G.get(t);if(r)return r;if(G.size>=_r){let a=G.keys().next().value;a!==void 0&&G.delete(a)}try{r=new Intl.RelativeTimeFormat(Ie(e),{numeric:n})}catch(a){throw new ge({actual:e,reason:a.message})}return G.set(t,r),r}function Hr(e){try{return new Intl.Locale(e.replace(/_/g,"-")).toString().toLowerCase()}catch{return e}}function ze(e,n,t={}){let r=Oe(e,"date1"),a=Oe(n,"date2"),o=Pe(r)-Pe(a),s=Math.abs(o),d=Nr(t.cutoffs),i="year";for(let{maxMs:c,unit:g}of d)if(s<c){i=g;break}let m=jr(i),l=Math.round(o/m),T=t.numeric??"auto",y=t.locale??_;return Lr(y,T).format(l,i)}function Ur(e,n={}){let t=new Date,r={year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds(),millisecond:t.getMilliseconds()};return ze(e,r,n)}function jr(e){switch(e){case"second":return Q;case"minute":return V;case"hour":return ee;case"day":return F;case"week":return 7*F;case"month":return 30*F;case"quarter":return 91*F;case"year":return 365*F;default:throw new Error(`temporal-fmt: formatDistance hit unhandled unit "${String(e)}".`)}}var Ne=100,H=[];function Gr(e){if(typeof e.language!="string"||e.language.length===0)throw new Error("temporal-fmt: registerRelativeGrammar requires a non-empty language string.");if(!Array.isArray(e.matchers)||e.matchers.length===0)throw new Error("temporal-fmt: registerRelativeGrammar requires at least one matcher.");let n=H.findIndex(t=>t.language===e.language);if(n>=0)H[n]=e;else{if(H.length>=Ne)throw new RangeError(`temporal-fmt: registerRelativeGrammar reached the ${Ne}-grammar limit.`);H.push(e)}}function _e(e,n,t){for(let r of H)if(r.language===e)for(let a of r.matchers){let o=a(n);if(o===null)continue;let s=A();if(o.resolve){let d=o.resolve(t);return s.PlainDate.from(d,{overflow:"reject"})}return s.PlainDate.from({year:o.year??t.year,month:o.month??t.month,day:o.day??t.day},{overflow:"reject"})}return null}function Zr(){return H.map(e=>e.language)}function k(e){return e.toLowerCase().replace(/ä/g,"ae").replace(/ö/g,"oe").replace(/ü/g,"ue").replace(/ß/g,"ss").normalize("NFD").replace(/[\u0300-\u036f]/g,"")}function Wr(e,n){/* c8 ignore start @preserve -- unreachable through the only call
|
|
2
|
+
* site (fuzzyCorrectEnglish): `a` is always a word that already
|
|
3
|
+
* failed the `vocabulary.includes(word)` exact-match check, so
|
|
4
|
+
* a === b never holds against any `b` drawn from that same
|
|
5
|
+
* vocabulary; and neither `a` (split from a non-empty normalized
|
|
6
|
+
* string) nor `b` (a vocabulary entry) is ever empty. Kept as
|
|
7
|
+
* general-purpose guards in case levenshtein() gets a second caller
|
|
8
|
+
* later. */if(e===n)return 0;if(e.length===0)return n.length;if(n.length===0)return e.length;/* c8 ignore stop @preserve */let t=new Array(n.length+1),r=new Array(n.length+1);for(let a=0;a<=n.length;a++)t[a]=a;for(let a=1;a<=e.length;a++){r[0]=a;for(let o=1;o<=n.length;o++){let s=e[a-1]===n[o-1]?0:1;r[o]=Math.min(t[o]+1,r[o-1]+1,t[o-1]+s)}[t,r]=[r,t]}return t[n.length]}var Le=2,te=4096,He=32;function Yr(){return[...Se,...ke,...Me,"today","tomorrow","yesterday","next","last","this","in","ago","day","days","week","weeks","month","months","year","years"].map(k)}var we;function Br(){return we||(we=Object.freeze(Yr())),we}function Xr(e){let n=Br(),t=e.split(" ");if(e.length>te||t.length>He)throw new RangeError(`temporal-fmt: parseRelative fuzzy input is too large (maximum ${te} characters and ${He} words).`);let r=!1,a=t.map(o=>{if(/^\d+(?:st|nd|rd|th)?$/.test(o)||n.includes(o))return o;let s,d=Le+1;for(let i of n){let m=Wr(o,i);m<d&&(d=m,s=i)}return s!==void 0&&d<=Le?(r=!0,s):o});return r?a.join(" "):void 0}function P(e){if(typeof e.year!="number")throw new Error("temporal-fmt: parseRelative reference date is missing year.");return e.year}function z(e){if(typeof e.month!="number")throw new Error("temporal-fmt: parseRelative reference date is missing month.");return e.month}function N(e){if(typeof e.day!="number")throw new Error("temporal-fmt: parseRelative reference date is missing day.");return e.day}function re(e){let n=e.dayOfWeek;if(typeof n!="number")throw new Error("temporal-fmt: parseRelative needs a reference date exposing dayOfWeek (a Temporal.PlainDate / PlainDateTime / ZonedDateTime).");return n}function S(e){return[...e.map(k)].sort((r,a)=>a.length-r.length).map(r=>r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")}function oe(e,n,t,r){return e.PlainDate.from({year:n,month:t,day:r},{overflow:"reject"})}function b(e,n,t){return e.PlainDate.from({year:P(n),month:z(n),day:N(n)}).add({days:t})}function O(e,n,t,r){let a=e.PlainDate.from({year:P(n),month:z(n),day:N(n)}),o={};return r==="day"&&(o.days=t),r==="week"&&(o.weeks=t),r==="month"&&(o.months=t),r==="year"&&(o.years=t),a.add(o)}function ae(e,n,t){if(e==="next"){let r=t-n;return r<=0&&(r+=7),r}if(e==="last"){let r=t-n;return r>=0&&(r-=7),r}return t-n}function ie(e,n,t,r){let a=P(n),o=e.PlainDate.from({year:a,month:z(n),day:N(n)});if(!e.PlainDate.compare)throw new Error("temporal-fmt: parseRelative needs Temporal.PlainDate.compare to resolve month-day phrases; the active implementation does not expose it.");try{let s=e.PlainDate.from({year:a,month:t,day:r},{overflow:"reject"});return e.PlainDate.compare(s,o)>=0?s:e.PlainDate.from({year:a+1,month:t,day:r},{overflow:"reject"})}catch(s){try{return e.PlainDate.from({year:a+1,month:t,day:r},{overflow:"reject"})}catch{throw new Error(`temporal-fmt: parseRelative can't resolve month ${t} day ${r} \u2014 it isn't a valid date in either ${a} or ${a+1}. Original error: ${s.message}`)}}}function se(e,n){let t=k(e),r=n.findIndex(a=>k(a)===t);/* c8 ignore start @preserve -- unreachable: every caller passes a
|
|
9
|
+
* name captured by nameAlternation(names), which builds its regex
|
|
10
|
+
* alternation from this same list under the same normalizeForMatch
|
|
11
|
+
* transform. The regex can't match anything findIndex() wouldn't
|
|
12
|
+
* also find here. Defensive throw kept for the type checker and as
|
|
13
|
+
* a tripwire if that invariant ever breaks. Ignore comment sits on
|
|
14
|
+
* the `if` itself, not just the throw inside it — c8 tracks the
|
|
15
|
+
* branch outcome (was the true side ever taken) separately from the
|
|
16
|
+
* statements inside, so excluding only the inner throw still leaves
|
|
17
|
+
* the branch itself flagged as uncovered. */if(r<0)throw new Error(`temporal-fmt: parseRelative internal error \u2014 weekday "${e}" not in names list.`);/* c8 ignore stop @preserve */return r+1}function le(e,n,t=[]){let r=k(e),a=n.findIndex(s=>k(s)===r);if(a>=0)return a+1;let o=t.findIndex(s=>k(s)===r);if(o>=0)return o+1;/* c8 ignore start @preserve -- unreachable: every caller passes a name
|
|
18
|
+
* captured by nameAlternation([...longNames, ...shortNames]), so the
|
|
19
|
+
* regex alternation and these two findIndex() scans are built from
|
|
20
|
+
* the same lists under the same normalizeForMatch transform. Kept as
|
|
21
|
+
* a tripwire for the type checker in case that invariant ever breaks. */throw new Error(`temporal-fmt: parseRelative internal error \u2014 month "${e}" not in names list.`);/* c8 ignore stop @preserve */}var Se=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],ke=["January","February","March","April","May","June","July","August","September","October","November","December"],Me=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Z={supportedHint:'Supported: weekday refs ("next Tuesday"), day offsets ("today"/"tomorrow"/"yesterday"), unit offsets ("in 3 days", "2 weeks ago"), and month-day ("March 5th").',matchers:[{pattern:/^today$/i,resolve:(e,n)=>oe(n.temporal,P(n.reference),z(n.reference),N(n.reference))},{pattern:/^tomorrow$/i,resolve:(e,n)=>b(n.temporal,n.reference,1)},{pattern:/^yesterday$/i,resolve:(e,n)=>b(n.temporal,n.reference,-1)},{pattern:new RegExp(`^(next|last|this)\\s+(${S(Se)})$`,"i"),resolve:(e,n)=>{let t=e[1].toLowerCase(),r=se(e[2],Se),a=re(n.reference);return b(n.temporal,n.reference,ae(t,a,r))}},{pattern:/^(in\s+)?(\d+)\s+(day|week|month|year)s?(?:\s+ago)?$/i,resolve:(e,n)=>{let t=e[1],r=e[2],a=e[3].toLowerCase(),o=!!t,s=/\bago\b/i.test(e[0]);if(!o&&!s)throw new Error(`temporal-fmt: parseRelative can't tell whether "${e[0]}" is past or future \u2014 use "in ${r} ${a}s" or "${r} ${a}s ago".`);let d=o?1:-1;return O(n.temporal,n.reference,d*Number(r),a)}},{pattern:new RegExp(`^(${S([...ke,...Me])})\\s+(\\d{1,2})(?:st|nd|rd|th)?(?:,?\\s*(\\d{4}))?$`,"i"),resolve:(e,n)=>{let t=le(e[1],ke,Me),r=Number(e[2]);return ie(n.temporal,n.reference,t,r)}}]},ne=["lunes","martes","mi\xE9rcoles","jueves","viernes","s\xE1bado","domingo"],Ue=["enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"],je=["ene","feb","mar","abr","may","jun","jul","ago","sept","oct","nov","dic"],qr={supportedHint:'Frases soportadas: referencias de d\xEDa de la semana ("el pr\xF3ximo lunes", "el lunes pasado", "este martes"), offsets de d\xEDa ("hoy"/"ma\xF1ana"/"ayer"), offsets de unidad ("en 3 d\xEDas", "hace 2 semanas"), y mes-d\xEDa ("5 de marzo").',matchers:[{pattern:/^hoy$/i,resolve:(e,n)=>oe(n.temporal,P(n.reference),z(n.reference),N(n.reference))},{pattern:/^ma[ñn]ana$/i,resolve:(e,n)=>b(n.temporal,n.reference,1)},{pattern:/^ayer$/i,resolve:(e,n)=>b(n.temporal,n.reference,-1)},{pattern:new RegExp(`^(?:el\\s+)?(?:(pr[o\xF3]ximo|pasado)\\s+(${S(ne)})|(${S(ne)})\\s+(pr[o\xF3]ximo|pasado)|este\\s+(${S(ne)}))$`,"i"),resolve:(e,n)=>{let t,r;e[1]&&e[2]?(t=e[1],r=e[2]):e[3]&&e[4]?(r=e[3],t=e[4]):(t="este",r=e[5]);let a=k(t)==="proximo"?"next":t.toLowerCase()==="este"?"this":"last",o=se(r,ne),s=re(n.reference);return b(n.temporal,n.reference,ae(a,s,o))}},{pattern:new RegExp("^(?:(en|dentro\\s+de)\\s+(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?|(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?\\s+(hace))$","i"),resolve:(e,n)=>{let t,r,a;e[1]&&e[2]&&e[3]?(t=e[2],r=e[3],a=1):(t=e[4],r=e[5],a=-1);let o=U(r);return O(n.temporal,n.reference,a*Number(t),o)}},{pattern:new RegExp("^hace\\s+(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?$","i"),resolve:(e,n)=>{let t=Number(e[1]),r=U(e[2]);return O(n.temporal,n.reference,-t,r)}},{pattern:new RegExp("^(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?$","i"),resolve:(e,n)=>{throw new Error(`temporal-fmt: parseRelative no puede decidir si "${e[0]}" es pasado o futuro \u2014 usa "en ${e[1]} ${e[2]}s" o "hace ${e[1]} ${e[2]}s".`)}},{pattern:new RegExp(`^(\\d{1,2})\\.?\\s+de\\s+(${S([...Ue,...je])})(?:\\s+de\\s+(\\d{4}))?$`,"i"),resolve:(e,n)=>{let t=Number(e[1]),r=le(e[2],Ue,je);return ie(n.temporal,n.reference,r,t)}}]},ve=["lundi","mardi","mercredi","jeudi","vendredi","samedi","dimanche"],Ge=["janvier","f\xE9vrier","mars","avril","mai","juin","juillet","ao\xFBt","septembre","octobre","novembre","d\xE9cembre"],Ze=["janv.","f\xE9vr.","mars","avr.","mai","juin","juil.","ao\xFBt","sept.","oct.","nov.","d\xE9c."],Kr={supportedHint:`Phrases prises en charge : r\xE9f\xE9rences de jour de la semaine ("lundi prochain", "mardi dernier", "ce mercredi"), d\xE9calages de jour ("aujourd'hui"/"demain"/"hier"), d\xE9calages d'unit\xE9 ("dans 3 jours", "il y a 2 semaines"), et mois-jour ("5 mars").`,matchers:[{pattern:/^aujourd'hui$/i,resolve:(e,n)=>oe(n.temporal,P(n.reference),z(n.reference),N(n.reference))},{pattern:/^demain$/i,resolve:(e,n)=>b(n.temporal,n.reference,1)},{pattern:/^hier$/i,resolve:(e,n)=>b(n.temporal,n.reference,-1)},{pattern:new RegExp(`^(?:(${S(ve)})\\s+(prochain|dernier)|ce\\s+(${S(ve)}))$`,"i"),resolve:(e,n)=>{let t,r;e[1]&&e[2]?(r=e[1],t=e[2].toLowerCase()==="prochain"?"next":"last"):(t="this",r=e[3]);let a=se(r,ve),o=re(n.reference);return b(n.temporal,n.reference,ae(t,o,a))}},{pattern:new RegExp("^il\\s+y\\s+a\\s+(\\d+)\\s+(jour|semaine|mois|an|ann[e\xE9e]e)s?$","i"),resolve:(e,n)=>{let t=Number(e[1]),r=U(e[2]);return O(n.temporal,n.reference,-t,r)}},{pattern:new RegExp("^dans\\s+(\\d+)\\s+(jour|semaine|mois|an|ann[e\xE9e]e)s?$","i"),resolve:(e,n)=>{let t=Number(e[1]),r=U(e[2]);return O(n.temporal,n.reference,t,r)}},{pattern:new RegExp("^(\\d+)\\s+(jour|semaine|mois|an|ann[e\xE9e]e)s?$","i"),resolve:(e,n)=>{throw new Error(`temporal-fmt: parseRelative ne peut pas d\xE9terminer si "${e[0]}" est pass\xE9 ou futur \u2014 utilisez "dans ${e[1]} ${e[2]}s" ou "il y a ${e[1]} ${e[2]}s".`)}},{pattern:new RegExp(`^(\\d{1,2})\\s+(${S([...Ge,...Ze])})(?:\\s+(\\d{4}))?$`,"i"),resolve:(e,n)=>{let t=Number(e[1]),r=le(e[2],Ge,Ze);return ie(n.temporal,n.reference,r,t)}}]},We=["Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"],Ye=["Januar","Februar","M\xE4rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],Be=["Jan","Feb","M\xE4r","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"],Jr={supportedHint:'Unterst\xFCtzte Phrasen: Wochentag-Bez\xFCge ("n\xE4chsten Dienstag", "letzten Freitag", "diesen Montag"), Tages-Offsets ("heute"/"morgen"/"gestern"), Einheiten-Offsets ("in 3 Tagen", "vor 2 Wochen"), und Monat-Tag ("5. M\xE4rz").',matchers:[{pattern:/^heute$/i,resolve:(e,n)=>oe(n.temporal,P(n.reference),z(n.reference),N(n.reference))},{pattern:/^morgen$/i,resolve:(e,n)=>b(n.temporal,n.reference,1)},{pattern:/^gestern$/i,resolve:(e,n)=>b(n.temporal,n.reference,-1)},{pattern:new RegExp(`^(n(?:ae|a|\xE4)chsten|letzten|diesen)\\s+(${S(We)})$`,"i"),resolve:(e,n)=>{let t=k(e[1]),r=t==="nachsten"||t==="naechsten"?"next":t==="diesen"?"this":"last",a=se(e[2],We),o=re(n.reference);return b(n.temporal,n.reference,ae(r,o,a))}},{pattern:new RegExp("^vor\\s+(\\d+)\\s+(Tag(?:e|n|en)?|Woche(?:n)?|Monat(?:e|n|en)?|Jahr(?:e|n|en)?)$","i"),resolve:(e,n)=>{let t=Number(e[1]),r=U(e[2]);return O(n.temporal,n.reference,-t,r)}},{pattern:new RegExp("^in\\s+(\\d+)\\s+(Tag(?:e|n|en)?|Woche(?:n)?|Monat(?:e|n|en)?|Jahr(?:e|n|en)?)$","i"),resolve:(e,n)=>{let t=Number(e[1]),r=U(e[2]);return O(n.temporal,n.reference,t,r)}},{pattern:new RegExp("^(\\d+)\\s+(Tag(?:e|n|en)?|Woche(?:n)?|Monat(?:e|n|en)?|Jahr(?:e|n|en)?)$","i"),resolve:(e,n)=>{throw new Error(`temporal-fmt: parseRelative kann nicht erkennen, ob "${e[0]}" Vergangenheit oder Zukunft ist \u2014 verwende "in ${e[1]} ${e[2]}" oder "vor ${e[1]} ${e[2]}".`)}},{pattern:new RegExp(`^(\\d{1,2})\\.?\\s+(${S([...Ye,...Be,"Maerz","Maer"])})(?:\\s+(\\d{4}))?$`,"i"),resolve:(e,n)=>{let t=Number(e[1]),r=le(e[2],Ye,Be);return ie(n.temporal,n.reference,r,t)}}]},Qr={en:Z,es:qr,fr:Kr,de:Jr};function Vr(e){if(!e)return Z;try{let t=new Intl.Locale(e.replace(/_/g,"-")).language.toLowerCase();return Qr[t]??Z}catch{return Z}}function eo(e){if(!e)return"en";try{return new Intl.Locale(e.replace(/_/g,"-")).language.toLowerCase()}catch{return"en"}}function U(e){let n=k(e);if(n==="day"||n==="week"||n==="month"||n==="year")return n;if(n==="dia")return"day";if(n==="semana")return"week";if(n==="mes")return"month";if(n==="ano"||n==="a\xF1o")return"year";if(n==="jour")return"day";if(n==="semaine")return"week";if(n==="mois")return"month";if(n==="an"||n==="annee")return"year";if(n==="tag"||n==="tagen")return"day";if(n==="woche"||n==="wochen")return"week";if(n==="monat"||n==="monaten")return"month";if(n==="jahr"||n==="jahren")return"year";/* c8 ignore start @preserve -- unreachable: every caller passes a word
|
|
22
|
+
* captured by a regex alternation built from exactly these unit-word
|
|
23
|
+
* forms (day/week/month/year across en/es/fr/de), so the branches
|
|
24
|
+
* above already cover every string that can reach this function.
|
|
25
|
+
* Kept as a tripwire for the type checker in case a grammar adds a
|
|
26
|
+
* unit word here without a matching regex update. */throw new Error(`temporal-fmt: parseRelative internal error \u2014 unrecognized unit word "${e}".`);/* c8 ignore stop @preserve */}function no(e,n,t={}){let r=n,a=A(),o=(e??"").trim().replace(/\s+/g," ");if(o.length===0)throw new Error("temporal-fmt: parseRelative got an empty input string.");if(o.length>te)throw new RangeError(`temporal-fmt: parseRelative input is too large (maximum ${te} characters).`);let s=k(o),d=Vr(t.locale),i={temporal:a,reference:r},m=_e(eo(t.locale),o,{year:r.year,month:r.month,day:r.day,dayOfWeek:r.dayOfWeek});if(m!==null)return m;let l=y=>{for(let f of d.matchers){let c=y.match(f.pattern);if(c)return f.resolve(c,i)}return be},T=l(s);if(T!==be)return T;if(t.fuzzy){if(d!==Z)throw new Error("temporal-fmt: parseRelative's { fuzzy: true } option currently only supports English. Pass no locale (or locale: 'en'), or omit { fuzzy: true } for this locale.");let y=Xr(s);if(y!==void 0){let f=l(y);if(f!==be)return f}}throw new Error(`temporal-fmt: parseRelative doesn't recognize "${o}". `+d.supportedHint)}var be=Symbol("temporal-fmt: parseRelative no match");function M(e){return typeof e=="object"&&e!==null}function x(e){return n=>{try{return e(n)}catch{return!1}}}function h(e,n){return typeof e[n]=="function"}function $(e,n){return M(e)?e[Symbol.toStringTag]===`Temporal.${n}`:!1}var Xe=x(function(n){if($(n,"PlainDate"))return!0;if(!M(n))return!1;let t=n;return typeof t.year=="number"&&typeof t.month=="number"&&typeof t.day=="number"&&typeof t.hour>"u"&&h(t,"toPlainDateTime")&&h(t,"withCalendar")}),qe=x(function(n){if($(n,"PlainTime"))return!0;if(!M(n))return!1;let t=n;return typeof t.hour=="number"&&typeof t.year>"u"&&!h(t,"withCalendar")&&!h(t,"toPlainDate")&&!h(t,"toPlainDateTime")}),Ke=x(function(n){if($(n,"PlainDateTime"))return!0;if(!M(n))return!1;let t=n;return typeof t.year=="number"&&typeof t.month=="number"&&typeof t.day=="number"&&typeof t.hour=="number"&&h(t,"withPlainTime")&&!h(t,"toInstant")}),Je=x(function(n){if($(n,"ZonedDateTime"))return!0;if(!M(n))return!1;let t=n;return typeof t.year=="number"&&typeof t.month=="number"&&typeof t.day=="number"&&typeof t.hour=="number"&&h(t,"withTimeZone")&&h(t,"toInstant")}),Qe=x(function(n){if($(n,"Instant"))return!0;if(!M(n))return!1;let t=n;return h(t,"toZonedDateTimeISO")&&!h(t,"toInstant")&&typeof t.year>"u"}),Ve=x(function(n){if($(n,"PlainYearMonth"))return!0;if(!M(n))return!1;let t=n;return typeof t.year=="number"&&typeof t.month=="number"&&typeof t.day>"u"&&h(t,"toPlainDate")}),en=x(function(n){if($(n,"PlainMonthDay"))return!0;if(!M(n))return!1;let t=n;return typeof t.year>"u"&&typeof t.month>"u"&&typeof t.day=="number"&&typeof t.monthCode=="string"&&h(t,"toPlainDate")}),nn=x(function(n){return $(n,"Duration")?!0:M(n)?h(n,"total"):!1}),tn=x(function(n){if(!M(n))return!1;let t=n[Symbol.toStringTag];if(typeof t=="string"&&t.startsWith("Temporal."))return!0;let r=n;return h(r,"toInstant")||h(r,"toPlainDate")||h(r,"toPlainDateTime")||h(r,"toPlainTime")||h(r,"toPlainYearMonth")||h(r,"toPlainMonthDay")||h(r,"toZonedDateTime")||h(r,"toZonedDateTimeISO")||h(r,"withCalendar")||h(r,"withPlainTime")||h(r,"withTimeZone")||h(r,"total")});function to(e){if(e===null)return"null";if(Array.isArray(e))return"array";if(typeof e=="object"){let n=e.constructor;return n&&typeof n.name=="string"&&n.name!=="Object"?`instance of ${n.name}`:"plain object"}return typeof e}function C(e,n,t){if(!n(e))throw new Error(`temporal-fmt: expected a Temporal.${t}, got ${to(e)}.`)}function ro(e){C(e,tn,"object (Instant, PlainDate, PlainTime, PlainDateTime, ZonedDateTime, Duration, PlainYearMonth, or PlainMonthDay)")}function oo(e){C(e,Qe,"Instant")}function ao(e){C(e,Xe,"PlainDate")}function io(e){C(e,qe,"PlainTime")}function so(e){C(e,Ke,"PlainDateTime")}function lo(e){C(e,Je,"ZonedDateTime")}function mo(e){C(e,Ve,"PlainYearMonth")}function uo(e){C(e,en,"PlainMonthDay")}function co(e){C(e,nn,"Duration")}var u={year:["PlainDate","PlainDateTime","ZonedDateTime","PlainYearMonth"],month:["PlainDate","PlainDateTime","ZonedDateTime","PlainYearMonth","PlainMonthDay"],day:["PlainDate","PlainDateTime","ZonedDateTime","PlainMonthDay"],hour:["PlainTime","PlainDateTime","ZonedDateTime","Instant"],minute:["PlainTime","PlainDateTime","ZonedDateTime","Instant"],second:["PlainTime","PlainDateTime","ZonedDateTime","Instant"],millisecond:["PlainTime","PlainDateTime","ZonedDateTime","Instant"],dayOfWeek:["PlainDate","PlainDateTime","ZonedDateTime"],timeZoneId:["ZonedDateTime"],offset:["ZonedDateTime"]},R={yyyy:{meaning:"Four-digit year (preserves sign for BCE; no truncation).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.year,roundTripSafe:!0},yy:{meaning:"Two-digit year (year % 100). Throws on negative years.",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.year,roundTripSafe:!1},MMMM:{meaning:'Long month name (locale-aware, e.g. "January", "janvier").',formatCapable:!0,parseCapable:!0,localeSensitive:!0,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.month,roundTripSafe:!0},MMM:{meaning:'Short month name (locale-aware, e.g. "Jan", "janv.").',formatCapable:!0,parseCapable:!0,localeSensitive:!0,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.month,roundTripSafe:!0},MM:{meaning:"Two-digit month (01-12, zero-padded).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.month,roundTripSafe:!0},M:{meaning:"One- or two-digit month (1-12, no padding).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.month,roundTripSafe:!0},dd:{meaning:"Two-digit day-of-month (01-31, zero-padded).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.day,roundTripSafe:!0},d:{meaning:"One- or two-digit day-of-month (1-31, no padding).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.day,roundTripSafe:!0},EEEE:{meaning:'Long weekday name (locale-aware, e.g. "Monday", "lundi"). Parse cross-checks against the parsed date.',formatCapable:!0,parseCapable:!0,localeSensitive:!0,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.dayOfWeek,roundTripSafe:!0},EEE:{meaning:'Short weekday name (locale-aware, e.g. "Mon", "lun."). Parse cross-checks against the parsed date.',formatCapable:!0,parseCapable:!0,localeSensitive:!0,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.dayOfWeek,roundTripSafe:!0},HH:{meaning:"Two-digit hour, 24-hour clock (00-23, zero-padded).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.hour,roundTripSafe:!0},H:{meaning:"One- or two-digit hour, 24-hour clock (0-23, no padding).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.hour,roundTripSafe:!0},hh:{meaning:"Two-digit hour, 12-hour clock (01-12, zero-padded). Requires `a` token on parse.",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.hour,roundTripSafe:!0},h:{meaning:"One- or two-digit hour, 12-hour clock (1-12, no padding). Requires `a` token on parse.",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.hour,roundTripSafe:!0},mm:{meaning:"Two-digit minute (00-59, zero-padded).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.minute,roundTripSafe:!0},m:{meaning:"One- or two-digit minute (0-59, no padding).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.minute,roundTripSafe:!0},ss:{meaning:"Two-digit second (00-59, zero-padded).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.second,roundTripSafe:!0},s:{meaning:"One- or two-digit second (0-59, no padding).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.second,roundTripSafe:!0},S:{meaning:"Fractional second, 1 digit (tenths of a second).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.millisecond,roundTripSafe:!0},SS:{meaning:"Fractional second, 2 digits (hundredths of a second).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.millisecond,roundTripSafe:!0},SSS:{meaning:"Fractional second, 3 digits (milliseconds).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.millisecond,roundTripSafe:!0},SSSS:{meaning:"Fractional second, 4 digits (tens of microseconds).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.millisecond,roundTripSafe:!0},SSSSS:{meaning:"Fractional second, 5 digits (hundred-thousandths of a second).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.millisecond,roundTripSafe:!0},SSSSSS:{meaning:"Fractional second, 6 digits (microseconds).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.millisecond,roundTripSafe:!0},SSSSSSS:{meaning:"Fractional second, 7 digits (tens of nanoseconds).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.millisecond,roundTripSafe:!0},SSSSSSSS:{meaning:"Fractional second, 8 digits (hundred-millionths of a second).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.millisecond,roundTripSafe:!0},SSSSSSSSS:{meaning:"Fractional second, 9 digits (nanoseconds).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.millisecond,roundTripSafe:!0},a:{meaning:'Day period (locale-aware: "AM"/"PM", "\u5348\u524D"/"\u5348\u5F8C", etc.). Required alongside 12-hour tokens on parse.',formatCapable:!0,parseCapable:!0,localeSensitive:!0,calendarSensitive:!1,timezoneSensitive:!1,supportedTypes:u.hour,roundTripSafe:!0},zzz:{meaning:'IANA time zone id (e.g. "America/New_York") or fixed offset ("+05:30"). Requires full date+time on parse.',formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!0,supportedTypes:u.timeZoneId,roundTripSafe:!0},X:{meaning:"Numeric UTC offset, short (Z for UTC, \xB1HH[MM] otherwise). Minutes omitted when zero.",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!0,supportedTypes:u.offset,roundTripSafe:!0},XX:{meaning:"Numeric UTC offset, no colon (Z for UTC, \xB1HHMM otherwise).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!0,supportedTypes:u.offset,roundTripSafe:!0},XXX:{meaning:"Numeric UTC offset, with colon (Z for UTC, \xB1HH:MM otherwise).",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!0,supportedTypes:u.offset,roundTripSafe:!0},x:{meaning:"Numeric UTC offset, short, never Z (always \xB1HH[MM]). Lowercase variant of X.",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!0,supportedTypes:u.offset,roundTripSafe:!0},xx:{meaning:"Numeric UTC offset, no colon, never Z (always \xB1HHMM). Lowercase variant of XX.",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!0,supportedTypes:u.offset,roundTripSafe:!0},xxx:{meaning:"Numeric UTC offset, with colon, never Z (always \xB1HH:MM). Lowercase variant of XXX.",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!1,timezoneSensitive:!0,supportedTypes:u.offset,roundTripSafe:!0},do:{meaning:'Ordinal day-of-month with English suffix ("1st", "2nd", "3rd", "4th", ... 21st, 22nd, ...). Format-only \u2014 not parseable.',formatCapable:!0,parseCapable:!1,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.day,roundTripSafe:!1},Q:{meaning:"Quarter as a digit (1-4). Derived from month.",formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.month,roundTripSafe:!0},QQQ:{meaning:'Quarter with "Q" prefix ("Q1".."Q4"). Derived from month.',formatCapable:!0,parseCapable:!0,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.month,roundTripSafe:!0},ww:{meaning:"ISO 8601 week number (01-53). Format-only \u2014 week alone can't reconstruct a date.",formatCapable:!0,parseCapable:!1,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.dayOfWeek,roundTripSafe:!1},RRRR:{meaning:"ISO 8601 week-numbering year (4-digit, may differ from calendar year at year boundaries). Format-only.",formatCapable:!0,parseCapable:!1,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.dayOfWeek,roundTripSafe:!1},D:{meaning:"Day of year, unpadded (1-366). Format-only \u2014 parsing requires resolving against a year.",formatCapable:!0,parseCapable:!1,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.day,roundTripSafe:!1},DD:{meaning:"Day of year, 2-digit minimum (01-366). Format-only.",formatCapable:!0,parseCapable:!1,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.day,roundTripSafe:!1},DDD:{meaning:"Day of year, 3-digit zero-padded (001-366). Format-only.",formatCapable:!0,parseCapable:!1,localeSensitive:!1,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.day,roundTripSafe:!1},LLLL:{meaning:"Stand-alone long month name (nominative case in Slavic locales). Identical to MMMM in most locales.",formatCapable:!0,parseCapable:!1,localeSensitive:!0,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.month,roundTripSafe:!0},LLL:{meaning:"Stand-alone short month name. Identical to MMM in most locales.",formatCapable:!0,parseCapable:!1,localeSensitive:!0,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.month,roundTripSafe:!0},cccc:{meaning:"Stand-alone long weekday name. Identical to EEEE in most locales.",formatCapable:!0,parseCapable:!1,localeSensitive:!0,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.dayOfWeek,roundTripSafe:!0},ccc:{meaning:"Stand-alone short weekday name. Identical to EEE in most locales.",formatCapable:!0,parseCapable:!1,localeSensitive:!0,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.dayOfWeek,roundTripSafe:!0},GGGG:{meaning:'Long era name (locale-aware, e.g. "Anno Domini"/"Before Christ"). Format-only.',formatCapable:!0,parseCapable:!1,localeSensitive:!0,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.year,roundTripSafe:!1},G:{meaning:'Short era name (locale-aware, e.g. "AD"/"BC"). Format-only.',formatCapable:!0,parseCapable:!1,localeSensitive:!0,calendarSensitive:!0,timezoneSensitive:!1,supportedTypes:u.year,roundTripSafe:!1},zzzz:{meaning:'Localized long timezone name (e.g. "Eastern Standard Time"). Format-only.',formatCapable:!0,parseCapable:!1,localeSensitive:!0,calendarSensitive:!1,timezoneSensitive:!0,supportedTypes:u.timeZoneId,roundTripSafe:!1},z:{meaning:'Localized short timezone name (e.g. "EST"). Format-only.',formatCapable:!0,parseCapable:!1,localeSensitive:!0,calendarSensitive:!1,timezoneSensitive:!0,supportedTypes:u.timeZoneId,roundTripSafe:!1}},me=Object.keys(R);function fo(e){return q(e)}function rn(){return X.map(([e])=>({name:e,metadata:R[e]}))}function po(e){return R[e]}function W(e){if(e.length>1e3)throw new Error(`temporal-fmt: format string exceeds maximum length of ${1e3} characters (got ${e.length}).`);let n=q(e),t=[],r=new Set,a=new Set,o=!0,s=!1,d=!1,i=!1,m=!0,l=[],T=0,y=[],f=()=>{y.length>=2&&l.push({code:"AMBIGUOUS_NUMERIC_RUN",message:`Adjacent unpadded numeric tokens "${y.join("")}" with no separator can be ambiguous to parse. Add a separator or use the padded form (e.g. "MM" instead of "M").`}),y.length=0};for(let p of n){if(p.kind==="literal"){T+=p.value.length,f();continue}let E=R[p.value];if(!E){l.push({code:"UNKNOWN_TOKEN_NO_METADATA",message:`Token "${p.value}" is recognized by the tokenizer but has no metadata entry in tokenMetadata.ts \u2014 this is a bug in temporal-fmt.`}),T+=p.value.length;continue}t.push({name:p.value,position:T,metadata:E});let Re=he(p.value);if(Re&&r.add(Re.field),t.length===1)for(let Y of E.supportedTypes)a.add(Y);else{let Y=new Set;for(let B of a)E.supportedTypes.includes(B)&&Y.add(B);a.clear();for(let B of Y)a.add(B)}E.parseCapable||(o=!1,l.push({code:"FORMAT_ONLY_TOKEN",message:`Token "${p.value}" is format-only \u2014 it can't be parsed back into a value. Use a parse-capable variant (e.g. "d" instead of "do") if you need round-trip.`})),E.localeSensitive&&(s=!0),E.calendarSensitive&&(d=!0),E.timezoneSensitive&&(i=!0),E.roundTripSafe||(m=!1),Ae.has(p.value)?y.push(p.value):f(),T+=p.value.length}f();let c=t.map(p=>p.name),g=c.some(p=>p==="hh"||p==="h"),D=c.some(p=>p==="HH"||p==="H"),pn=c.some(p=>p==="a");g&&!pn&&l.push({code:"TWELVE_HOUR_WITHOUT_A",message:`12-hour token ("hh"/"h") used without an "a" (AM/PM) token \u2014 parse() can't tell AM from PM and throws at runtime.`}),g&&D&&l.push({code:"MIXED_12_AND_24_HOUR",message:"Mixing 24-hour and 12-hour tokens \u2014 parse() refuses to guess which is authoritative and throws at runtime."});let Ce=c.some(p=>p==="X"||p==="XX"||p==="XXX"||p==="x"||p==="xx"||p==="xxx"),yn=c.some(p=>p==="zzz");return Ce&&yn&&l.push({code:"ZZZ_WITH_OFFSET_TOKEN",message:`Format string has both "zzz" and an offset token \u2014 parse() cross-checks them and throws if the parsed offset disagrees with the zone's actual offset.`}),Ce&&!r.has("year")&&l.push({code:"OFFSET_WITHOUT_FULL_DATE",message:"Offset token used without a full date \u2014 parse() needs a complete date and time to build a ZonedDateTime and throws at runtime otherwise."}),{tokens:t,requiredFields:[...r].sort(),compatibleTypes:[...a].sort(),parseable:o,localeSensitive:s,calendarSensitive:d,timezoneSensitive:i,ambiguous:l.some(p=>p.code==="AMBIGUOUS_NUMERIC_RUN"),roundTripSafe:m&&o,warnings:l}}function yo(e){let n=W(e),t=[];t.push(`Format string: "${e}"`),t.push(`Tokens (${n.tokens.length}):`);for(let r of n.tokens)t.push(` ${r.name} @${r.position} \u2014 ${r.metadata.meaning}`);if(n.requiredFields.length>0&&t.push(`Required fields: ${n.requiredFields.join(", ")}`),n.compatibleTypes.length>0&&t.push(`Compatible Temporal types: ${n.compatibleTypes.join(", ")}`),t.push(`Parseable: ${n.parseable?"yes":"no"}`),t.push(`Locale-sensitive: ${n.localeSensitive?"yes":"no"}`),t.push(`Calendar-sensitive: ${n.calendarSensitive?"yes":"no"}`),t.push(`Timezone-sensitive: ${n.timezoneSensitive?"yes":"no"}`),t.push(`Ambiguous: ${n.ambiguous?"yes":"no"}`),t.push(`Round-trip safe: ${n.roundTripSafe?"yes":"no"}`),n.warnings.length>0){t.push("Warnings:");for(let r of n.warnings)t.push(` [${r.code}] ${r.message}`)}return t.join(`
|
|
27
|
+
`)}function go(e){if(e.length>1e3)return!1;try{return q(e),!0}catch{return!1}}function ho(e){return W(e)}function To(e){return he(e)?.field}function De(e){let n=A();try{if(/^\d{4}-\d{2}-\d{2}T/.test(e)||/T\d{2}:\d{2}/.test(e)){if(/[zZ]$/.test(e)||/[+-]\d{2}:?\d{2}$/.test(e)){let t=e;if(/[zZ]$/.test(t))t=t.slice(0,-1)+"+00:00[UTC]";else{let r=/([+-]\d{2}:?\d{2})$/.exec(t);r&&(t=`${t}[${r[1]}]`)}return n.ZonedDateTime.from(t,{overflow:"reject"})}return n.PlainDateTime.from(e,{overflow:"reject"})}if(/^\d{4}-\d{2}-\d{2}/.test(e))return n.PlainDate.from(e,{overflow:"reject"});if(/^\d{2}:\d{2}/.test(e))return n.PlainTime.from(e);throw new Error(`temporal-fmt: parseISO("${e}") doesn't look like an ISO 8601 string.`)}catch(t){throw new ye({input:e,reason:t.message})}}function on(e){let n=e;if(typeof n?.toString!="function")throw new w({reason:`formatISO() expects a Temporal value with toString(), got ${typeof e}.`});return n.toString()}function wo(e){if(!/^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(\.\d+)?([Zz]|[+-]\d{2}:\d{2})$/.exec(e))throw new w({input:e,reason:"does not match RFC 3339 date-time grammar"});let r=e.replace(/[tT]/,"T").replace(/[zZ]$/,"+00:00[UTC]");return De(r)}function vo(e){let n=on(e);if(!/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?(Z|[+-][0-9]{2}:[0-9]{2})$/.test(n))throw new w({input:n,reason:"value did not produce RFC 3339-compliant output"});return n}function bo(e){if(!/^(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s+)?\d{1,2}\s+(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+\d{2,4}\s+\d{2}:\d{2}(?::\d{2})?\s+(?:[+-]\d{4}|[A-Za-z]{1,5})$/.test(e.trim()))throw new w({input:e,reason:"not a valid RFC 2822 date"});let t=Date.parse(e);if(Number.isNaN(t))throw new w({input:e,reason:"not a valid RFC 2822 date"});return j().fromEpochMilliseconds(t)}function So(e){let n=e,t;if(typeof n?.toEpochMilliseconds=="function")t=n.toEpochMilliseconds();else if(typeof n?.epochMilliseconds=="number")t=n.epochMilliseconds;else if(typeof n?.toInstant=="function"){let r=n.toInstant();typeof r.epochMilliseconds=="number"&&(t=r.epochMilliseconds)}if(t===void 0)throw new w({reason:`formatRFC2822() expects a value with epochMilliseconds, toEpochMilliseconds(), or toInstant(), got ${typeof e}.`});return ko(t)}function ko(e){try{let t=new Intl.DateTimeFormat("en-US",{weekday:"short",day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZone:"UTC",timeZoneName:"shortOffset",hour12:!1}).formatToParts(new Date(e)),r=i=>t.find(m=>m.type===i)?.value??"",o=r("timeZoneName")?.match(/GMT([+-])(\d+)(?::(\d+))?/),s;if(o){let i=o[1],m=o[2].padStart(2,"0"),l=(o[3]??"0").padStart(2,"0");s=`${i}${m}${l}`;/* c8 ignore start @preserve -- timeZone is hardcoded to 'UTC' above,
|
|
28
|
+
which always resolves cleanly, so shortOffset always returns a
|
|
29
|
+
parseable "GMT+0"-shaped string in this environment's ICU. This
|
|
30
|
+
branch only guards against an ICU build whose shortOffset output
|
|
31
|
+
doesn't match the regex; can't trigger it without mocking Intl.
|
|
32
|
+
The ignore starts before the closing brace of the if-block so it
|
|
33
|
+
covers the whole else-branch node c8 tracks as a single unit. */}else s="+0000";/* c8 ignore stop @preserve */let d=r("hour");/* c8 ignore start @preserve -- hour12:false with a fixed UTC zone
|
|
34
|
+
never yields "24" in this environment's ICU (midnight formats as
|
|
35
|
+
"00"). Some ICU versions/locales are documented to emit "24" for
|
|
36
|
+
hour12:false, so this stays as a defensive normalization; not
|
|
37
|
+
reachable here without mocking Intl.DateTimeFormat's output. */d==="24"&&(d="00");/* c8 ignore stop @preserve */return`${r("weekday")}, ${r("day")} ${r("month")} ${r("year")} ${d}:${r("minute")}:${r("second")} ${s}`;/* c8 ignore start @preserve -- Intl.DateTimeFormat is constructed
|
|
38
|
+
above with a literal, always-valid timeZone: 'UTC' and no other
|
|
39
|
+
user input reaches the constructor or formatToParts call, so this
|
|
40
|
+
catch can't be triggered through the public API in a normal Intl
|
|
41
|
+
environment (e.g. Node with full-icu). Kept as a genuine fallback
|
|
42
|
+
for runtimes with a broken or absent Intl implementation. */}catch{let n=new Date(e),t=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],a=t[n.getUTCDay()],o=String(n.getUTCDate()).padStart(2,"0"),s=r[n.getUTCMonth()],d=n.getUTCFullYear(),i=String(n.getUTCHours()).padStart(2,"0"),m=String(n.getUTCMinutes()).padStart(2,"0"),l=String(n.getUTCSeconds()).padStart(2,"0");return`${a}, ${o} ${s} ${d} ${i}:${m}:${l} +0000`}/* c8 ignore stop @preserve */}function Mo(e){let n=e.trim(),t=Date.parse(n);if(Number.isNaN(t))throw new w({input:e,reason:"not a valid HTTP-date"});return j().fromEpochMilliseconds(t)}function Do(e){let n=e?.toInstant?.()??e,t=typeof n=="object"&&n!==null&&"epochMilliseconds"in n?n.epochMilliseconds:(()=>{throw new w({reason:`formatHTTPDate() expects an Instant or ZonedDateTime, got ${typeof e}.`})})(),r=new Date(t),a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],o=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],s=a[r.getUTCDay()],d=String(r.getUTCDate()).padStart(2,"0"),i=o[r.getUTCMonth()],m=r.getUTCFullYear(),l=String(r.getUTCHours()).padStart(2,"0"),T=String(r.getUTCMinutes()).padStart(2,"0"),y=String(r.getUTCSeconds()).padStart(2,"0");return`${s}, ${d} ${i} ${m} ${l}:${T}:${y} GMT`}function ue(e){let n=e;if(typeof n?.toInstant=="function"){let t=n.toInstant();return typeof t.epochNanoseconds=="bigint"?{epochMilliseconds:t.epochMilliseconds,epochNanoseconds:t.epochNanoseconds}:{epochMilliseconds:t.epochMilliseconds,epochNanoseconds:BigInt(t.epochMilliseconds)*1000000n}}if(typeof n?.epochNanoseconds=="bigint")return{epochMilliseconds:Number(n.epochNanoseconds/1000000n),epochNanoseconds:n.epochNanoseconds};if(typeof n?.epochMilliseconds=="number")return{epochMilliseconds:n.epochMilliseconds,epochNanoseconds:BigInt(n.epochMilliseconds)*1000000n};throw new w({reason:`expected an Instant or ZonedDateTime, got ${typeof e}.`})}function j(){let e=A().Instant;if(!e)throw new Error("temporal-fmt: Temporal.Instant is not available in this implementation.");return e}function Eo(e){return ue(e).epochMilliseconds/1e3}function xo(e){return j().fromEpochMilliseconds(e*1e3)}function Co(e){return j().fromEpochMilliseconds(e)}function Ro(e){return j().fromEpochNanoseconds(BigInt(e)*1000n)}function Fo(e){return j().fromEpochNanoseconds(e)}function $o(e){return ue(e).epochMilliseconds}function Io(e){let{epochNanoseconds:n}=ue(e);return Number(n/1000n)}function Ao(e){return ue(e).epochNanoseconds}function Oo(e){let n=e.trim();if(/^\d{4}-\d{2}-\d{2}$/.test(n))return K("yyyy-MM-dd",n);if(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(n))return K("yyyy-MM-dd HH:mm:ss",n);if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(n))return De(n);throw new w({input:e,reason:"not a recognized SQL date/time format"})}function Po(e){return typeof e?.hour=="number"?L(e,"yyyy-MM-dd HH:mm:ss"):L(e,"yyyy-MM-dd")}var an={locale:_,numberingSystem:"latn",firstDayOfWeek:1,roundingMode:"nearest",disambiguation:"compatible",overflow:"reject",parseLenient:!1,durationShowZeroValues:!1};function zo(e={}){let n={...an,...e};if(typeof n.locale!="string"||n.locale.length===0)throw new Error(`temporal-fmt: config.locale must be a non-empty string (got ${String(n.locale)}).`);if(n.firstDayOfWeek!==1&&n.firstDayOfWeek!==7)throw new Error(`temporal-fmt: config.firstDayOfWeek must be 1 (Monday) or 7 (Sunday) (got ${n.firstDayOfWeek}).`);if(!["nearest","floor","ceil","trunc"].includes(n.roundingMode))throw new Error(`temporal-fmt: config.roundingMode "${n.roundingMode}" is not recognized.`);if(!["compatible","earlier","later","reject"].includes(n.disambiguation))throw new Error(`temporal-fmt: config.disambiguation "${n.disambiguation}" is not recognized.`);if(!["constrain","reject"].includes(n.overflow))throw new Error(`temporal-fmt: config.overflow "${n.overflow}" is not recognized.`);return Object.freeze(n)}function No(e,n){if(!e)return n;let t={...n};return t.locale===void 0&&(t.locale=e.locale),t.calendar===void 0&&e.calendar!==void 0&&(t.calendar=e.calendar),t.timezone===void 0&&e.timezone!==void 0&&(t.timezone=e.timezone),t.numberingSystem===void 0&&(t.numberingSystem=e.numberingSystem),t.lenient===void 0&&e.parseLenient&&(t.lenient=!0),t}function _o(e={}){let n=new Set(e.weekend??[6,7]),t={...e.workingHours??{}};for(let r=1;r<=7;r++)t[r]===void 0&&(t[r]=n.has(r)?0:8);return{weekend:n,holidays:e.holidays,workingHours:t,halfDays:new Set(e.halfDays??[])}}function ce(e,n){let t=n,r=t.dayOfWeek;if(typeof t.year=="number"&&typeof t.month=="number"&&typeof t.day=="number"){let o=new Date(Date.UTC(t.year,t.month-1,t.day)).getUTCDay();r=o===0?7:o}if(typeof r!="number")throw new Error("temporal-fmt: isBusinessDay() needs a value with dayOfWeek (or year/month/day to compute it).");return!(e.weekend.has(r)||e.holidays&&e.holidays.isHoliday(n))}function ln(e,n){let t=v(n,1,"days");for(let r=0;r<14;r++){if(ce(e,t))return t;t=v(t,1,"days")}throw new Error("temporal-fmt: nextBusinessDay() gave up after 14 days \u2014 likely a misconfigured calendar (e.g. all days are weekends or holidays).")}function mn(e,n){let t=v(n,-1,"days");for(let r=0;r<14;r++){if(ce(e,t))return t;t=v(t,-1,"days")}throw new Error("temporal-fmt: previousBusinessDay() gave up after 14 days \u2014 likely a misconfigured calendar.")}var de=1e5;function un(e){if(!Number.isSafeInteger(e))throw new RangeError(`temporal-fmt: business-day count must be a finite safe integer (got ${e}).`)}function sn(e,n){let t=e,r=n,a=t.year*1e4+t.month*100+t.day,o=r.year*1e4+r.month*100+r.day;return a-o}function dn(e,n,t){if(un(t),t===0)return n;let r=t>0?1:-1,a=Math.abs(t);if(a>de)throw new RangeError(`temporal-fmt: addBusinessDays() exceeded the ${de}-day limit.`);let o=n;for(let s=0;s<a;s++)o=r>0?ln(e,o):mn(e,o);return o}function Lo(e,n,t){return un(t),dn(e,n,-t)}function Ho(e,n,t){let r=sn(t,n);if(r===0)return 0;let a=r>0?1:-1,o=n,s=0,d=0;for(;sn(o,t)!==0;){if(o=v(o,a,"days"),d++,d>de)throw new RangeError(`temporal-fmt: differenceInBusinessDays() exceeded the ${de}-day traversal limit.`);ce(e,o)&&(s+=a)}return s}var cn=5e3;function Uo(e){let n=new Map;function t(r){let a=n.get(r);return a||(a=e.map(o=>{let s;return o.compute?s=o.compute(r):s={month:o.month,day:o.day},{...s,name:o.name}}),n.set(r,a),a)}return{isHoliday(r){let a=r;if(typeof a.year!="number"||typeof a.month!="number"||typeof a.day!="number")throw new Error("temporal-fmt: isHoliday() needs a value with year/month/day.");return t(a.year).some(s=>s.month===a.month&&s.day===a.day)},holidaysBetween(r,a){let o=r,s=a;if(typeof o?.year!="number"||typeof s?.year!="number")throw new Error("temporal-fmt: holidaysBetween() needs start/end values with year/month/day.");if(s.year-o.year>cn)throw new RangeError(`temporal-fmt: holidaysBetween() year range (${o.year}\u2013${s.year}) exceeds the ${cn}-year limit. Split the query into smaller ranges.`);let d=[];for(let i=o.year;i<=s.year;i++){let m=t(i);for(let l of m){let T={year:i,month:l.month,day:l.day};J(T,o)>=0&&J(T,s)<=0&&d.push({year:i,month:l.month,day:l.day})}}return d}}}function jo(e,n){let t=v(n,1,"days");for(let r=0;r<365*5;r++){if(e.isHoliday(t))return t;t=v(t,1,"days")}}function Go(e,n){let t=v(n,-1,"days");for(let r=0;r<365*5;r++){if(e.isHoliday(t))return t;t=v(t,-1,"days")}}function Zo(e,n,t){return e.holidaysBetween(n,t)}function Wo(e={}){let n=[...X],t=new Set;for(let i of e.tokens??[])t.add(i.name);for(let i of e.tokens??[]){let m=n.findIndex(([l])=>l===i.name);m>=0?n[m]=[i.name,i.handler,i.field]:n.push([i.name,i.handler,i.field])}n.sort((i,m)=>m[0].length-i[0].length);let r=new Map(n.map(([i,m,l])=>[i,{handler:m,field:l}])),a=n.map(([i])=>i);function o(i){let m=[],l=0;for(;l<i.length;){let T=i[l];if(T==="'"){if(i[l+1]==="'"){s(m,"'"),l+=2;continue}let f=l+1,c="",g=!1;for(;f<i.length;){if(i[f]==="'"){if(i[f+1]==="'"){c+="'",f+=2;continue}g=!0,f+=1;break}c+=i[f],f+=1}if(!g)throw new Error(`temporal-fmt: unterminated quote in format string "${i}"`);s(m,c),l=f;continue}let y=a.find(f=>i.startsWith(f,l));if(y){let f=y[y.length-1];if(i[l+y.length]===f){let c=l+y.length;for(;i[c]===f;)c+=1;throw new pe({token:i.slice(l,c),format:i,message:`temporal-fmt: "${i.slice(l,c)}" in format string "${i}" isn't a recognized token \u2014 did you mean "${y}"?`})}m.push({kind:"token",value:y}),l+=y.length;continue}s(m,T),l+=1}return m}function s(i,m){let l=i[i.length-1];l&&l.kind==="literal"?l.value+=m:i.push({kind:"literal",value:m})}let d=e.defaultLocale??_;return{format(i,m,l={}){if(m.length>1e3)throw new Error(`temporal-fmt: format string exceeds maximum length of ${1e3} characters (got ${m.length}).`);let T=l.locale??d,y=o(m),f="";for(let c of y){if(c.kind==="literal"){f+=c.value;continue}let g=r.get(c.value);/* c8 ignore start @preserve -- unreachable: customTokenize only ever produces a
|
|
43
|
+
`kind: 'token'` piece via sortedTokenStrings.find(...), and
|
|
44
|
+
handlerByToken is built from that same mergedTokens array, so
|
|
45
|
+
every token piece is guaranteed a handler entry. Guards against a
|
|
46
|
+
future customTokenize change that decouples the two lookups. */if(!g)throw new Error(`temporal-fmt: unknown token "${c.value}"`);/* c8 ignore stop @preserve */if(i[g.field]===void 0)throw new Error(`temporal-fmt: token "${c.value}" requires "${String(g.field)}", which this Temporal object doesn't have.`);f+=g.handler(i,T)}return f},formatToParts(i,m,l={}){if(m.length>1e3)throw new Error(`temporal-fmt: format string exceeds maximum length of ${1e3} characters (got ${m.length}).`);let T=l.locale??d,y=o(m),f=[];for(let c of y){if(c.kind==="literal"){let D=f[f.length-1];/* c8 ignore start @preserve -- unreachable: customTokenize's own
|
|
47
|
+
appendLiteral() already merges adjacent literal chars/quoted
|
|
48
|
+
spans into a single piece before this loop ever sees them, so
|
|
49
|
+
two literal pieces are never adjacent here. Kept as a guard
|
|
50
|
+
against a future customTokenize change that stops merging. */D&&D.type==="literal"?D.value+=c.value:f.push({type:"literal",value:c.value});continue}let g=r.get(c.value);/* c8 ignore start @preserve -- unreachable: customTokenize only emits
|
|
51
|
+
kind:'token' pieces found in sortedTokenStrings, the same array
|
|
52
|
+
handlerByToken is built from, so every token piece is guaranteed
|
|
53
|
+
a handler entry. Guards against future decoupling of the two. */if(!g)throw new Error(`temporal-fmt: unknown token "${c.value}"`);/* c8 ignore stop @preserve */if(i[g.field]===void 0)throw new Error(`temporal-fmt: token "${c.value}" requires "${String(g.field)}".`);f.push({type:"token",value:g.handler(i,T),token:c.value})}return f},compileFormat(i){if(i.length>1e3)throw new Error(`temporal-fmt: format string exceeds maximum length of ${1e3} characters (got ${i.length}).`);let m=o(i);return{formatStr:i,pieces:m.map(l=>l),format(l,T={}){let y=T.locale??d,f="";for(let c of m){if(c.kind==="literal"){f+=c.value;continue}let g=r.get(c.value);/* c8 ignore start @preserve -- unreachable, see the same guard's comment
|
|
54
|
+
above in the un-compiled format(). */if(!g)throw new Error(`temporal-fmt: unknown token "${c.value}"`);/* c8 ignore stop @preserve */if(l[g.field]===void 0)throw new Error(`temporal-fmt: token "${c.value}" requires "${String(g.field)}".`);f+=g.handler(l,y)}return f},formatToParts(l,T={}){let y=T.locale??d,f=[];for(let c of m){if(c.kind==="literal"){let D=f[f.length-1];/* c8 ignore start @preserve -- unreachable, see the same guard's
|
|
55
|
+
comment above in the un-compiled formatToParts. */D&&D.type==="literal"?D.value+=c.value:f.push({type:"literal",value:c.value});continue}let g=r.get(c.value);/* c8 ignore start @preserve -- unreachable, see the same guard's
|
|
56
|
+
comment above in the un-compiled formatToParts. */if(!g)throw new Error(`temporal-fmt: unknown token "${c.value}"`);/* c8 ignore stop @preserve */if(l[g.field]===void 0)throw new Error(`temporal-fmt: token "${c.value}" requires "${String(g.field)}".`);f.push({type:"token",value:g.handler(l,y),token:c.value})}return f}}}}}function Yo(e){return/^y+$/.test(e)?"Year":/^[ML]+$/.test(e)?"Month":/^[decD]+$/.test(e)?"Day":/^[Ec]+$/.test(e)?"Weekday":/^[Qq]+$/.test(e)?"Quarter":/^[Gg]+$/.test(e)?"Era":/^[Hh]+$/.test(e)?"Hour":/^m+$/.test(e)?"Minute":/^s+$/.test(e)?"Second":/^S+$/.test(e)?"Fractional Second":e==="a"?"Day Period":e==="zzz"?"Time Zone":/^[Xx]+$/.test(e)?"UTC Offset":e==="do"?"Ordinal Day":e==="ww"||e==="RRRR"?"ISO Week":"Other"}function Bo(){return me.map(e=>{let n=R[e];return{label:e,detail:n.meaning,documentation:[n.meaning,"",`Format-capable: ${n.formatCapable}`,`Parse-capable: ${n.parseCapable}`,`Locale-sensitive: ${n.localeSensitive}`,`Calendar-sensitive: ${n.calendarSensitive}`,`Timezone-sensitive: ${n.timezoneSensitive}`,`Round-trip safe: ${n.roundTripSafe}`,`Supported types: ${n.supportedTypes.join(", ")}`].join(`
|
|
57
|
+
`),family:Yo(e)}})}function Xo(){let e={};for(let n of me){let t=R[n];e[n]={signature:n,summary:t.meaning,details:[`Format-capable: ${t.formatCapable?"yes":"no"}`,`Parse-capable: ${t.parseCapable?"yes":"no"}`,`Locale-sensitive: ${t.localeSensitive?"yes":"no"}`,`Calendar-sensitive: ${t.calendarSensitive?"yes":"no"}`,`Timezone-sensitive: ${t.timezoneSensitive?"yes":"no"}`,`Round-trip safe: ${t.roundTripSafe?"yes":"no"}`,`Supported types: ${t.supportedTypes.join(", ")}`].join(`
|
|
58
|
+
`)}}return e}function qo(e){let n=W(e),t=[];for(let r of n.warnings){let a=r.message,o;r.code==="TWELVE_HOUR_WITHOUT_A"?o='Add an "a" token (e.g. "h:mm a") or use "H:mm" for 24-hour.':r.code==="MIXED_12_AND_24_HOUR"?o='Pick one form: "HH:mm" for 24-hour or "h:mm a" for 12-hour.':r.code==="AMBIGUOUS_NUMERIC_RUN"?o='Add a separator or use padded forms (e.g. "MM" instead of "M").':r.code==="FORMAT_ONLY_TOKEN"&&(o='Use a parse-capable variant (e.g. "d" instead of "do").'),t.push({startColumn:0,endColumn:e.length,severity:"warning",message:a,code:r.code,suggestion:o})}return t}var Ee=[{from:"YYYY",to:"yyyy"},{from:"YY",to:"yy"},{from:"MMMM",to:"MMMM"},{from:"MMM",to:"MMM"},{from:"MM",to:"MM"},{from:"M",to:"M"},{from:"DD",to:"dd"},{from:"D",to:"d"},{from:"Do",to:null,notes:`Ordinal day (AdvancedFormat) \u2014 use temporal-fmt's own "do" token instead.`},{from:"dddd",to:"EEEE"},{from:"ddd",to:"EEE"},{from:"dd",to:null,notes:'Min-name weekday (e.g. "Tu") \u2014 temporal-fmt has no equivalent width.'},{from:"d",to:null,notes:'Numeric weekday (0-6) \u2014 no temporal-fmt equivalent; not the same as "d" here, which is day-of-month.'},{from:"HH",to:"HH"},{from:"H",to:"H"},{from:"hh",to:"hh"},{from:"h",to:"h"},{from:"kk",to:null,notes:"Hour 1-24 (AdvancedFormat) \u2014 no temporal-fmt equivalent."},{from:"k",to:null,notes:"Hour 1-24 (AdvancedFormat) \u2014 no temporal-fmt equivalent."},{from:"mm",to:"mm"},{from:"m",to:"m"},{from:"ss",to:"ss"},{from:"s",to:"s"},{from:"SSS",to:"SSS"},{from:"A",to:"a",notes:"Uppercase AM/PM in Day.js \u2014 temporal-fmt is always lowercase."},{from:"a",to:"a"},{from:"ZZ",to:"XX",notes:"Numeric UTC offset, no colon."},{from:"Z",to:"XXX",notes:"Numeric UTC offset with colon."},{from:"X",to:null,notes:"Unix timestamp (seconds) \u2014 use fromUnixSeconds() instead."},{from:"x",to:null,notes:"Unix timestamp (ms) \u2014 use fromUnixMilliseconds() instead."},{from:"Qo",to:null,notes:"Ordinal quarter (AdvancedFormat) \u2014 no temporal-fmt equivalent."},{from:"Q",to:"Q"},{from:"Mo",to:null,notes:"Ordinal month (AdvancedFormat) \u2014 no temporal-fmt equivalent."},{from:"ww",to:"ww"},{from:"wo",to:null,notes:"Ordinal ISO week (AdvancedFormat) \u2014 no temporal-fmt equivalent."},{from:"w",to:null,notes:`Unpadded ISO week \u2014 temporal-fmt's "ww" is always 2-digit.`},{from:"gggg",to:"RRRR",notes:"Week-numbering year, not the calendar year \u2014 same caveat as temporal-fmt's RRRR."},{from:"L",to:null,notes:"Localized date format (AdvancedFormat) \u2014 write the format string out explicitly."},{from:"LL",to:null,notes:"Localized date format (AdvancedFormat) \u2014 write the format string out explicitly."},{from:"LLL",to:null,notes:"Localized date format (AdvancedFormat) \u2014 write the format string out explicitly."},{from:"LLLL",to:null,notes:"Localized date format (AdvancedFormat) \u2014 write the format string out explicitly."},{from:"LT",to:null,notes:"Localized time format (AdvancedFormat) \u2014 write the format string out explicitly."},{from:"LTS",to:null,notes:"Localized time format (AdvancedFormat) \u2014 write the format string out explicitly."}],xe=[{from:"yyyy",to:"yyyy"},{from:"yy",to:"yy"},{from:"y",to:null,notes:'Unpadded calendar year, opt-in via useAdditionalWeekYearTokens \u2014 temporal-fmt has no unpadded-year token; use "yyyy".'},{from:"MMMM",to:"MMMM"},{from:"MMM",to:"MMM"},{from:"MM",to:"MM"},{from:"M",to:"M"},{from:"LLLL",to:"LLLL"},{from:"LLL",to:"LLL"},{from:"dd",to:"dd"},{from:"d",to:"d"},{from:"do",to:"do"},{from:"DDD",to:"DDD"},{from:"DD",to:"DD"},{from:"D",to:"D",notes:`Day-of-year, opt-in via useAdditionalDayOfYearTokens \u2014 matches temporal-fmt's own "D" already.`},{from:"EEEE",to:"EEEE"},{from:"EEE",to:"EEE"},{from:"eeee",to:null,notes:"Locale-aware numeric weekday \u2014 no temporal-fmt equivalent."},{from:"cccc",to:"cccc"},{from:"ccc",to:"ccc"},{from:"HH",to:"HH"},{from:"H",to:"H"},{from:"hh",to:"hh"},{from:"h",to:"h"},{from:"mm",to:"mm"},{from:"m",to:"m"},{from:"ss",to:"ss"},{from:"s",to:"s"},{from:"SSS",to:"SSS"},{from:"a",to:"a"},{from:"aaa",to:"a"},{from:"XXX",to:"XXX"},{from:"XX",to:"XX"},{from:"X",to:"X",notes:`Opt-in via useAdditionalDayOfYearTokens-adjacent rules in date-fns v3+; matches temporal-fmt's own "X" already.`},{from:"xxx",to:"xxx"},{from:"xx",to:"xx"},{from:"x",to:"x"},{from:"zzzz",to:"zzzz"},{from:"zzz",to:"zzz"},{from:"z",to:"z"},{from:"QQQ",to:"QQQ"},{from:"Q",to:"Q"},{from:"GGGG",to:"GGGG"},{from:"GGG",to:null,notes:'Abbreviated era \u2014 temporal-fmt only has "G" (short) and "GGGG" (long).'},{from:"GG",to:null,notes:'Abbreviated era \u2014 temporal-fmt only has "G" (short) and "GGGG" (long).'},{from:"G",to:"G"},{from:"ww",to:"ww"},{from:"w",to:null,notes:`Unpadded local week number \u2014 temporal-fmt's "ww" is ISO-week and always 2-digit.`},{from:"RRRR",to:"RRRR"},{from:"R",to:null,notes:`Unpadded ISO week-numbering year \u2014 temporal-fmt's "RRRR" is always 4-digit.`},{from:"Y",to:null,notes:'Week-numbering year (locale week rules), opt-in \u2014 no temporal-fmt equivalent; "RRRR" is ISO week-numbering, a different rule set.'},{from:"PPPP",to:null,notes:"Localized composite format \u2014 write the format string out explicitly."},{from:"PPP",to:null,notes:"Localized composite format \u2014 write the format string out explicitly."},{from:"PP",to:null,notes:"Localized composite format \u2014 write the format string out explicitly."},{from:"P",to:null,notes:"Localized composite format \u2014 write the format string out explicitly."},{from:"pppp",to:null,notes:"Localized composite format \u2014 write the format string out explicitly."},{from:"ppp",to:null,notes:"Localized composite format \u2014 write the format string out explicitly."},{from:"pp",to:null,notes:"Localized composite format \u2014 write the format string out explicitly."},{from:"p",to:null,notes:"Localized composite format \u2014 write the format string out explicitly."}];function Ko(e,n){return L(n??{year:2026,month:8,day:4,hour:15,minute:45,second:30,millisecond:123,dayOfWeek:2,timeZoneId:"UTC",offset:"+00:00",calendarId:"iso8601"},e,{locale:"en-US"})}function Jo(e){return"README.md#token-reference"}function Qo(e){let n=[],t=0;for(;t<e.length;)if(e[t]==="["){let r=e.indexOf("]",t+1);if(r===-1){n.push({kind:"token",value:e.slice(t)});break}n.push({kind:"literal",value:e.slice(t+1,r)}),t=r+1}else{let r=t;for(;r<e.length&&e[r]!=="[";)r+=1;n.push({kind:"token",value:e.slice(t,r)}),t=r}return n}function Vo(e,n){let t=[],r=0;for(;r<e.length;){let a=n.find(s=>e.startsWith(s,r));if(a){t.push({kind:"token",value:a}),r+=a.length;continue}let o=t[t.length-1];o&&o.kind==="literal"?o.value+=e[r]:t.push({kind:"literal",value:e[r]}),r+=1}return t}function fn(e,n,t){let r=new Map(n.map(d=>[d.from,d.to])),a=[...r.keys()].sort((d,i)=>i.length-d.length),o=Qo(e),s="";for(let d of o){if(d.kind==="literal"){s+=`'${d.value.replace(/'/g,"''")}'`;continue}for(let i of Vo(d.value,a))if(i.kind==="token"){let m=r.get(i.value);if(m==null)throw new Error(`temporal-fmt: "${i.value}" has no ${t} -> temporal-fmt mapping (in format string "${e}"). Write the equivalent temporal-fmt token in by hand, or wrap it in brackets if it was meant as literal text.`);s+=m}else/[a-zA-Z]/.test(i.value)?s+=`'${i.value.replace(/'/g,"''")}'`:s+=i.value}return s}function ea(e){return fn(e,Ee,"Day.js")}function na(e){return fn(e,xe,"date-fns")}export{me as ALL_TOKEN_NAMES,zn as AmbiguousInputError,xe as DATE_FNS_TO_TEMPORAL_FMT,Ee as DAYJS_TO_TEMPORAL_FMT,an as DEFAULT_CONFIG,st as FORMAT_ONLY_TOKENS,w as FormatSyntaxError,Pn as InvalidCalendarError,ye as InvalidDateError,Nn as InvalidDurationError,ge as InvalidLocaleError,An as InvalidOffsetError,In as InvalidTimeError,On as InvalidTimeZoneError,$n as ParseMismatchError,et as SUPPORTED_NUMBERING_SYSTEMS,R as TOKEN_METADATA,Fn as TemporalFmtError,pe as UnknownTokenError,v as add,dn as addBusinessDays,gt as addDays,Jn as addDuration,ht as addHours,vt as addMilliseconds,Tt as addMinutes,pt as addMonths,wt as addSeconds,yt as addWeeks,ft as addYears,W as analyzeFormat,rt as applyNumbering,ot as applyParseNumbering,Rn as asDateFieldView,co as assertDuration,oo as assertInstant,ao as assertPlainDate,so as assertPlainDateTime,uo as assertPlainMonthDay,io as assertPlainTime,mo as assertPlainYearMonth,ro as assertTemporal,lo as assertZonedDateTime,Xn as balanceDuration,kr as between,Hn as ceil,Gt as clamp,J as compare,Kn as compareDuration,it as compileFormat,dt as compileParser,nt as convertDigits,tt as convertDigitsToAscii,_o as createBusinessCalendar,zo as createConfig,Wo as createFormatter,Uo as createHolidayCalendar,bn as dayOfYear,gn as daysInMonth,hn as daysInYear,Rt as difference,Ho as differenceInBusinessDays,At as differenceInDays,Ot as differenceInHours,Nt as differenceInMilliseconds,Pt as differenceInMinutes,$t as differenceInMonths,zt as differenceInSeconds,It as differenceInWeeks,Ft as differenceInYears,Cn as endOf,yo as explainFormat,To as fieldForToken,Ln as floor,L as format,ze as formatDistance,Ur as formatDistanceToNow,Gn as formatDuration,Zn as formatDurationToParts,Do as formatHTTPDate,on as formatISO,Yn as formatISODuration,So as formatRFC2822,vo as formatRFC3339,Dr as formatRRule,Tr as formatRange,wr as formatRangeToParts,nr as formatRelative,tr as formatRelativeToNow,Po as formatSQL,at as formatToParts,Ro as fromUnixMicroseconds,Co as fromUnixMilliseconds,Fo as fromUnixNanoseconds,xo as fromUnixSeconds,Bo as getAutocompleteData,Jo as getDocUrl,Xo as getHoverDocs,qo as getInlineDiagnostics,or as getLocale,Dn as getMonth,$r as getNextTransition,Cr as getOffset,Rr as getOffsetNanoseconds,Ir as getPreviousTransition,Mn as getQuarter,xr as getTimeZone,Ar as getTransitions,En as getWeekday,ar as hasLocale,Zo as holidaysBetween,cr as intersection,mr as intersects,ir as interval,sr as intervalContains,pr as intervalDifference,dr as intervalIsAfter,ur as intervalIsBefore,yr as intervalSubtract,Ht as isAfter,Lt as isBefore,Zt as isBetween,ce as isBusinessDay,Fr as isDST,nn as isDuration,_t as isEqual,Qe as isInstant,vn as isLeapMonth,wn as isLeapYear,Xe as isPlainDate,Ke as isPlainDateTime,en as isPlainMonthDay,qe as isPlainTime,Ve as isPlainYearMonth,Wt as isSameDay,Kt as isSameMonth,Jt as isSameQuarter,qt as isSameWeek,Qt as isSameYear,tn as isTemporal,Yt as isToday,Bt as isTomorrow,go as isValidFormat,er as isWeekday,Vt as isWeekend,Xt as isYesterday,Je as isZonedDateTime,Zr as listRegisteredGrammars,rn as listTokens,jt as max,gr as mergeIntervals,No as mergeWithConfig,Ut as min,Tn as monthsInYear,ln as nextBusinessDay,jo as nextHoliday,lr as overlaps,K as parse,Bn as parseDuration,Mo as parseHTTPDate,De as parseISO,Wn as parseISODuration,bo as parseRFC2822,wo as parseRFC3339,Mr as parseRRule,no as parseRelative,Oo as parseSQL,ut as parseToParts,Or as possibleInstantsFor,Ko as previewFormat,mn as previousBusinessDay,Go as previousHoliday,vr as recurrence,rr as registerLocale,jn as registerLocaleVocab,Gr as registerRelativeGrammar,Er as resolveZoned,_n as round,$e as roundDuration,$e as roundDurationAlias,lt as safeParse,Vn as setTemporal,Sr as skip,hr as splitInterval,xn as startOf,ct as subtract,Lo as subtractBusinessDays,Mt as subtractDays,Qn as subtractDuration,Dt as subtractHours,Ct as subtractMilliseconds,Et as subtractMinutes,St as subtractMonths,xt as subtractSeconds,kt as subtractWeeks,bt as subtractYears,br as take,Io as toUnixMicroseconds,$o as toUnixMilliseconds,Ao as toUnixNanoseconds,Eo as toUnixSeconds,po as tokenInfo,fo as tokenizeFormat,qn as totalDuration,na as translateDateFnsFormatString,ea as translateDayjsFormatString,Un as truncate,mt as tryParse,fr as union,ho as validateFormat,Sn as weekOfYear,kn as weekYear};
|
|
3005
59
|
//# sourceMappingURL=index.js.map
|