temporal-fmt 0.9.71 → 0.9.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -49
- package/dist/{chunk-MXXTJ5CW.js → chunk-5KP5H7X2.js} +3 -3
- package/dist/{chunk-ZT3UXRAA.js → chunk-DMJWJTFY.js} +3 -8
- package/dist/chunk-DMJWJTFY.js.map +1 -0
- package/dist/{chunk-CQJYB7E7.js → chunk-HGRT37LT.js} +4 -10
- package/dist/chunk-HGRT37LT.js.map +1 -0
- package/dist/{chunk-3FMUGYE2.js → chunk-KV6GMX4D.js} +4 -159
- package/dist/chunk-KV6GMX4D.js.map +1 -0
- package/dist/chunk-UGYSEYUQ.js +168 -0
- package/dist/chunk-UGYSEYUQ.js.map +1 -0
- package/dist/{chunk-3SC5AVSY.js → chunk-WEVNKOQA.js} +2 -2
- package/dist/chunk-WP7TBCTT.js +241 -0
- package/dist/chunk-WP7TBCTT.js.map +1 -0
- package/dist/{chunk-BQET6RUR.js → chunk-Z245NHDT.js} +2 -19
- package/dist/{chunk-BQET6RUR.js.map → chunk-Z245NHDT.js.map} +1 -1
- package/dist/format.cjs +0 -17
- package/dist/format.cjs.map +1 -1
- package/dist/format.js +3 -3
- package/dist/index.cjs +3832 -4705
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -103
- package/dist/index.d.ts +20 -103
- package/dist/index.js +2406 -846
- package/dist/index.js.map +1 -1
- package/dist/interval.cjs +106 -4773
- package/dist/interval.cjs.map +1 -1
- package/dist/interval.js +5 -10
- package/dist/parse.cjs +0 -13
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.js +3 -3
- package/dist/recurrence.js +2 -1
- package/dist/relativeTime.cjs.map +1 -1
- package/dist/relativeTime.js +2 -2
- package/dist/tokens.d.cts +0 -4
- package/dist/tokens.d.ts +0 -4
- package/package.json +5 -21
- package/MODS.md +0 -148
- package/dist/chunk-3FMUGYE2.js.map +0 -1
- package/dist/chunk-CQJYB7E7.js.map +0 -1
- package/dist/chunk-ZT3UXRAA.js.map +0 -1
- package/dist/chunk-ZTIF4ZHX.js +0 -3041
- package/dist/chunk-ZTIF4ZHX.js.map +0 -1
- package/dist/modApi.d.cts +0 -147
- package/dist/modApi.d.ts +0 -147
- package/dist/runtime.d.cts +0 -206
- package/dist/runtime.d.ts +0 -206
- package/scripts/cli.mjs +0 -324
- package/scripts/loadMods.d.mts +0 -37
- package/scripts/loadMods.mjs +0 -801
- package/scripts/managePermissions.mjs +0 -126
- package/scripts/modConfig.mjs +0 -96
- package/scripts/modSandbox.d.mts +0 -13
- package/scripts/modSandbox.mjs +0 -855
- package/scripts/modWire.mjs +0 -241
- package/scripts/modWorker.mjs +0 -574
- package/scripts/semverRange.mjs +0 -157
- package/scripts/versions.json +0 -42
- /package/dist/{chunk-MXXTJ5CW.js.map → chunk-5KP5H7X2.js.map} +0 -0
- /package/dist/{chunk-3SC5AVSY.js.map → chunk-WEVNKOQA.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,244 +1,86 @@
|
|
|
1
1
|
import {
|
|
2
2
|
formatRelative,
|
|
3
3
|
formatRelativeToNow
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import {
|
|
6
|
-
ALL_TOKEN_NAMES,
|
|
7
|
-
DATE_FNS_TO_TEMPORAL_FMT,
|
|
8
|
-
DAYJS_TO_TEMPORAL_FMT,
|
|
9
|
-
DEFAULT_CONFIG,
|
|
10
|
-
OverrideConflictError,
|
|
11
|
-
TOKEN_METADATA,
|
|
12
|
-
addBusinessDays,
|
|
13
|
-
analyzeFormat,
|
|
14
|
-
contains,
|
|
15
|
-
createHolidayCalendar,
|
|
16
|
-
difference,
|
|
17
|
-
differenceInBusinessDays,
|
|
18
|
-
formatHTTPDate,
|
|
19
|
-
formatISO,
|
|
20
|
-
formatRFC2822,
|
|
21
|
-
formatRange,
|
|
22
|
-
fromUnixMilliseconds,
|
|
23
|
-
fromUnixSeconds,
|
|
24
|
-
getBalanceDurationImpl,
|
|
25
|
-
getBetweenImpl,
|
|
26
|
-
getCeilImpl,
|
|
27
|
-
getClampImpl,
|
|
28
|
-
getCompareDurationImpl,
|
|
29
|
-
getCompileFormatImpl,
|
|
30
|
-
getCompileParserImpl,
|
|
31
|
-
getCreateBusinessCalendarImpl,
|
|
32
|
-
getCreateConfigImpl,
|
|
33
|
-
getExplainFormatImpl,
|
|
34
|
-
getFieldForTokenImpl,
|
|
35
|
-
getFloorImpl,
|
|
36
|
-
getFormatDurationToPartsImpl,
|
|
37
|
-
getFormatISODurationImpl,
|
|
38
|
-
getFormatImpl,
|
|
39
|
-
getFormatRFC3339Impl,
|
|
40
|
-
getFormatRRuleImpl,
|
|
41
|
-
getFormatRangeToPartsImpl,
|
|
42
|
-
getFormatSQLImpl,
|
|
43
|
-
getFromUnixMicrosecondsImpl,
|
|
44
|
-
getFromUnixNanosecondsImpl,
|
|
45
|
-
getGetAutocompleteDataImpl,
|
|
46
|
-
getGetDocUrlImpl,
|
|
47
|
-
getGetHoverDocsImpl,
|
|
48
|
-
getGetInlineDiagnosticsImpl,
|
|
49
|
-
getGetLocaleImpl,
|
|
50
|
-
getGetMonthImpl,
|
|
51
|
-
getGetNextTransitionImpl,
|
|
52
|
-
getGetPreviousTransitionImpl,
|
|
53
|
-
getGetWeekdayImpl,
|
|
54
|
-
getHasLocaleImpl,
|
|
55
|
-
getIntersectionImpl,
|
|
56
|
-
getIntervalImpl,
|
|
57
|
-
getIsAfterImpl,
|
|
58
|
-
getIsBeforeImpl,
|
|
59
|
-
getIsBetweenImpl,
|
|
60
|
-
getIsEqualImpl,
|
|
61
|
-
getIsLeapMonthImpl,
|
|
62
|
-
getIsLeapYearImpl,
|
|
63
|
-
getIsSameDayImpl,
|
|
64
|
-
getIsSameMonthImpl,
|
|
65
|
-
getIsSameQuarterImpl,
|
|
66
|
-
getIsSameWeekImpl,
|
|
67
|
-
getIsSameYearImpl,
|
|
68
|
-
getIsTodayImpl,
|
|
69
|
-
getIsTomorrowImpl,
|
|
70
|
-
getIsValidFormatImpl,
|
|
71
|
-
getIsWeekdayImpl,
|
|
72
|
-
getIsYesterdayImpl,
|
|
73
|
-
getListRegisteredGrammarsImpl,
|
|
74
|
-
getListTokensImpl,
|
|
75
|
-
getMergeIntervalsImpl,
|
|
76
|
-
getMergeWithConfigImpl,
|
|
77
|
-
getMonthsInYearImpl,
|
|
78
|
-
getNextHolidayImpl,
|
|
79
|
-
getOverlapsImpl,
|
|
80
|
-
getParseDurationImpl,
|
|
81
|
-
getParseHTTPDateImpl,
|
|
82
|
-
getParseISODurationImpl,
|
|
83
|
-
getParseImpl,
|
|
84
|
-
getParseRFC2822Impl,
|
|
85
|
-
getParseRFC3339Impl,
|
|
86
|
-
getParseRRuleImpl,
|
|
87
|
-
getParseRelativeImpl,
|
|
88
|
-
getParseSQLImpl,
|
|
89
|
-
getPossibleInstantsForImpl,
|
|
90
|
-
getPreviewFormatImpl,
|
|
91
|
-
getPreviousHolidayImpl,
|
|
92
|
-
getResolveZonedImpl,
|
|
93
|
-
getSubtractBusinessDaysImpl,
|
|
94
|
-
getSubtractDurationImpl,
|
|
95
|
-
getToUnixMicrosecondsImpl,
|
|
96
|
-
getToUnixMillisecondsImpl,
|
|
97
|
-
getToUnixNanosecondsImpl,
|
|
98
|
-
getToUnixSecondsImpl,
|
|
99
|
-
getTokenInfoImpl,
|
|
100
|
-
getTokenizeFormatImpl,
|
|
101
|
-
getTranslateDateFnsFormatStringImpl,
|
|
102
|
-
getTruncateImpl,
|
|
103
|
-
getUnionImpl,
|
|
104
|
-
getValidateFormatImpl,
|
|
105
|
-
getWeekOfYearImpl,
|
|
106
|
-
getWeekYearImpl,
|
|
107
|
-
holidaysBetween,
|
|
108
|
-
intersects,
|
|
109
|
-
isAfter,
|
|
110
|
-
isBefore,
|
|
111
|
-
isBusinessDay,
|
|
112
|
-
nextBusinessDay,
|
|
113
|
-
parseISO,
|
|
114
|
-
previousBusinessDay,
|
|
115
|
-
registerFormatToken,
|
|
116
|
-
registerRelativeGrammar,
|
|
117
|
-
setBalanceDurationOverride,
|
|
118
|
-
setBetweenOverride,
|
|
119
|
-
setCeilOverride,
|
|
120
|
-
setClampOverride,
|
|
121
|
-
setCompareDurationOverride,
|
|
122
|
-
setCompileFormatOverride,
|
|
123
|
-
setCompileParserOverride,
|
|
124
|
-
setCreateBusinessCalendarOverride,
|
|
125
|
-
setCreateConfigOverride,
|
|
126
|
-
setExplainFormatOverride,
|
|
127
|
-
setFieldForTokenOverride,
|
|
128
|
-
setFloorOverride,
|
|
129
|
-
setFormatDurationToPartsOverride,
|
|
130
|
-
setFormatISODurationOverride,
|
|
131
|
-
setFormatOverride,
|
|
132
|
-
setFormatRFC3339Override,
|
|
133
|
-
setFormatRRuleOverride,
|
|
134
|
-
setFormatRangeToPartsOverride,
|
|
135
|
-
setFormatSQLOverride,
|
|
136
|
-
setFromUnixMicrosecondsOverride,
|
|
137
|
-
setFromUnixNanosecondsOverride,
|
|
138
|
-
setGetAutocompleteDataOverride,
|
|
139
|
-
setGetDocUrlOverride,
|
|
140
|
-
setGetHoverDocsOverride,
|
|
141
|
-
setGetInlineDiagnosticsOverride,
|
|
142
|
-
setGetLocaleOverride,
|
|
143
|
-
setGetMonthOverride,
|
|
144
|
-
setGetNextTransitionOverride,
|
|
145
|
-
setGetPreviousTransitionOverride,
|
|
146
|
-
setGetWeekdayOverride,
|
|
147
|
-
setHasLocaleOverride,
|
|
148
|
-
setIntersectionOverride,
|
|
149
|
-
setIntervalOverride,
|
|
150
|
-
setIsAfterOverride,
|
|
151
|
-
setIsBeforeOverride,
|
|
152
|
-
setIsBetweenOverride,
|
|
153
|
-
setIsEqualOverride,
|
|
154
|
-
setIsLeapMonthOverride,
|
|
155
|
-
setIsLeapYearOverride,
|
|
156
|
-
setIsSameDayOverride,
|
|
157
|
-
setIsSameMonthOverride,
|
|
158
|
-
setIsSameQuarterOverride,
|
|
159
|
-
setIsSameWeekOverride,
|
|
160
|
-
setIsSameYearOverride,
|
|
161
|
-
setIsTodayOverride,
|
|
162
|
-
setIsTomorrowOverride,
|
|
163
|
-
setIsValidFormatOverride,
|
|
164
|
-
setIsWeekdayOverride,
|
|
165
|
-
setIsYesterdayOverride,
|
|
166
|
-
setListRegisteredGrammarsOverride,
|
|
167
|
-
setListTokensOverride,
|
|
168
|
-
setMergeIntervalsOverride,
|
|
169
|
-
setMergeWithConfigOverride,
|
|
170
|
-
setMonthsInYearOverride,
|
|
171
|
-
setNextHolidayOverride,
|
|
172
|
-
setOverlapsOverride,
|
|
173
|
-
setParseDurationOverride,
|
|
174
|
-
setParseHTTPDateOverride,
|
|
175
|
-
setParseISODurationOverride,
|
|
176
|
-
setParseOverride,
|
|
177
|
-
setParseRFC2822Override,
|
|
178
|
-
setParseRFC3339Override,
|
|
179
|
-
setParseRRuleOverride,
|
|
180
|
-
setParseRelativeOverride,
|
|
181
|
-
setParseSQLOverride,
|
|
182
|
-
setPossibleInstantsForOverride,
|
|
183
|
-
setPreviewFormatOverride,
|
|
184
|
-
setPreviousHolidayOverride,
|
|
185
|
-
setResolveZonedOverride,
|
|
186
|
-
setSubtractBusinessDaysOverride,
|
|
187
|
-
setSubtractDurationOverride,
|
|
188
|
-
setToUnixMicrosecondsOverride,
|
|
189
|
-
setToUnixMillisecondsOverride,
|
|
190
|
-
setToUnixNanosecondsOverride,
|
|
191
|
-
setToUnixSecondsOverride,
|
|
192
|
-
setTokenInfoOverride,
|
|
193
|
-
setTokenizeFormatOverride,
|
|
194
|
-
setTranslateDateFnsFormatStringOverride,
|
|
195
|
-
setTruncateOverride,
|
|
196
|
-
setUnionOverride,
|
|
197
|
-
setValidateFormatOverride,
|
|
198
|
-
setWeekOfYearOverride,
|
|
199
|
-
setWeekYearOverride,
|
|
200
|
-
splitInterval,
|
|
201
|
-
subtract,
|
|
202
|
-
translateDayjsFormatString
|
|
203
|
-
} from "./chunk-ZTIF4ZHX.js";
|
|
4
|
+
} from "./chunk-WEVNKOQA.js";
|
|
204
5
|
import {
|
|
6
|
+
getNextTransition,
|
|
205
7
|
getOffset,
|
|
206
8
|
getOffsetNanoseconds,
|
|
9
|
+
getPreviousTransition,
|
|
207
10
|
getTimeZone,
|
|
208
11
|
getTransitions,
|
|
209
|
-
isDST
|
|
12
|
+
isDST,
|
|
13
|
+
possibleInstantsFor,
|
|
14
|
+
resolveZoned
|
|
210
15
|
} from "./chunk-64UB3WDT.js";
|
|
211
16
|
import {
|
|
212
17
|
addDuration,
|
|
18
|
+
balanceDuration,
|
|
19
|
+
ceil,
|
|
20
|
+
compareDuration,
|
|
21
|
+
floor,
|
|
213
22
|
formatDuration,
|
|
23
|
+
formatDurationToParts,
|
|
24
|
+
formatISODuration,
|
|
25
|
+
parseDuration,
|
|
26
|
+
parseISODuration,
|
|
214
27
|
round,
|
|
215
28
|
roundDuration,
|
|
216
|
-
|
|
29
|
+
subtractDuration,
|
|
30
|
+
totalDuration,
|
|
31
|
+
truncate
|
|
217
32
|
} from "./chunk-LHR5PCP4.js";
|
|
218
33
|
import {
|
|
34
|
+
contains,
|
|
35
|
+
difference as difference2,
|
|
36
|
+
formatRange,
|
|
37
|
+
formatRangeToParts,
|
|
38
|
+
intersection,
|
|
39
|
+
intersects,
|
|
40
|
+
interval,
|
|
41
|
+
isAfter as isAfter2,
|
|
42
|
+
isBefore as isBefore2,
|
|
43
|
+
mergeIntervals,
|
|
44
|
+
overlaps,
|
|
45
|
+
splitInterval,
|
|
46
|
+
subtract as subtract2,
|
|
47
|
+
union
|
|
48
|
+
} from "./chunk-WP7TBCTT.js";
|
|
49
|
+
import {
|
|
50
|
+
_handlerFor,
|
|
51
|
+
compileFormat,
|
|
52
|
+
format,
|
|
219
53
|
formatToParts
|
|
220
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-HGRT37LT.js";
|
|
221
55
|
import {
|
|
56
|
+
getLocale,
|
|
57
|
+
hasLocale,
|
|
222
58
|
registerLocale
|
|
223
59
|
} from "./chunk-FLMOMOAQ.js";
|
|
224
60
|
import {
|
|
225
61
|
FORMAT_ONLY_TOKENS,
|
|
62
|
+
UNPADDED_NUMERIC_TOKENS,
|
|
63
|
+
compileParser,
|
|
64
|
+
parse,
|
|
226
65
|
parseToParts,
|
|
227
66
|
safeParse,
|
|
228
67
|
tryParse
|
|
229
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-5KP5H7X2.js";
|
|
230
69
|
import {
|
|
231
70
|
SUPPORTED_NUMBERING_SYSTEMS,
|
|
232
71
|
applyNumbering,
|
|
233
72
|
applyParseNumbering,
|
|
234
73
|
convertDigits,
|
|
235
|
-
convertDigitsToAscii
|
|
236
|
-
|
|
74
|
+
convertDigitsToAscii,
|
|
75
|
+
tokenize,
|
|
76
|
+
tokenizeWithSpans
|
|
77
|
+
} from "./chunk-DMJWJTFY.js";
|
|
237
78
|
import {
|
|
238
79
|
DEFAULT_LOCALE,
|
|
239
80
|
TOKENS
|
|
240
|
-
} from "./chunk-
|
|
81
|
+
} from "./chunk-Z245NHDT.js";
|
|
241
82
|
import {
|
|
83
|
+
getTemporal,
|
|
242
84
|
setTemporal
|
|
243
85
|
} from "./chunk-DFWTCRS3.js";
|
|
244
86
|
import {
|
|
@@ -261,14 +103,13 @@ import {
|
|
|
261
103
|
registerLocaleVocab
|
|
262
104
|
} from "./chunk-QRLQ7RR7.js";
|
|
263
105
|
import {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
min,
|
|
106
|
+
between,
|
|
107
|
+
formatRRule,
|
|
108
|
+
parseRRule,
|
|
268
109
|
recurrence,
|
|
269
110
|
skip,
|
|
270
111
|
take
|
|
271
|
-
} from "./chunk-
|
|
112
|
+
} from "./chunk-KV6GMX4D.js";
|
|
272
113
|
import {
|
|
273
114
|
add,
|
|
274
115
|
addDays,
|
|
@@ -279,7 +120,7 @@ import {
|
|
|
279
120
|
addSeconds,
|
|
280
121
|
addWeeks,
|
|
281
122
|
addYears,
|
|
282
|
-
difference
|
|
123
|
+
difference,
|
|
283
124
|
differenceInDays,
|
|
284
125
|
differenceInHours,
|
|
285
126
|
differenceInMilliseconds,
|
|
@@ -288,7 +129,7 @@ import {
|
|
|
288
129
|
differenceInSeconds,
|
|
289
130
|
differenceInWeeks,
|
|
290
131
|
differenceInYears,
|
|
291
|
-
subtract
|
|
132
|
+
subtract,
|
|
292
133
|
subtractDays,
|
|
293
134
|
subtractHours,
|
|
294
135
|
subtractMilliseconds,
|
|
@@ -298,16 +139,44 @@ import {
|
|
|
298
139
|
subtractWeeks,
|
|
299
140
|
subtractYears
|
|
300
141
|
} from "./chunk-SC6ENLEB.js";
|
|
142
|
+
import {
|
|
143
|
+
clamp,
|
|
144
|
+
compare,
|
|
145
|
+
isAfter,
|
|
146
|
+
isBefore,
|
|
147
|
+
isBetween,
|
|
148
|
+
isEqual,
|
|
149
|
+
isSameDay,
|
|
150
|
+
isSameMonth,
|
|
151
|
+
isSameQuarter,
|
|
152
|
+
isSameWeek,
|
|
153
|
+
isSameYear,
|
|
154
|
+
isToday,
|
|
155
|
+
isTomorrow,
|
|
156
|
+
isWeekday,
|
|
157
|
+
isWeekend,
|
|
158
|
+
isYesterday,
|
|
159
|
+
max,
|
|
160
|
+
min
|
|
161
|
+
} from "./chunk-UGYSEYUQ.js";
|
|
301
162
|
import {
|
|
302
163
|
asDateFieldView,
|
|
303
164
|
dayOfYearHelper,
|
|
304
165
|
daysInMonth,
|
|
305
166
|
daysInYear,
|
|
306
167
|
endOf,
|
|
168
|
+
getMonth,
|
|
307
169
|
getQuarter,
|
|
308
|
-
|
|
170
|
+
getWeekday,
|
|
171
|
+
isLeapMonth,
|
|
172
|
+
isLeapYear,
|
|
173
|
+
monthsInYear,
|
|
174
|
+
startOf,
|
|
175
|
+
weekOfYear,
|
|
176
|
+
weekYear
|
|
309
177
|
} from "./chunk-KEPIXQK7.js";
|
|
310
178
|
import {
|
|
179
|
+
dayOfWeekFromCivil,
|
|
311
180
|
daysFromCivil,
|
|
312
181
|
isGregorianLeapYear
|
|
313
182
|
} from "./chunk-BLZDBPSV.js";
|
|
@@ -648,110 +517,2016 @@ function assertDuration(value) {
|
|
|
648
517
|
assertImpl(value, isDuration, "Duration");
|
|
649
518
|
}
|
|
650
519
|
|
|
651
|
-
// src/
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
520
|
+
// src/tokenMetadata.ts
|
|
521
|
+
var TYPES_WITH = {
|
|
522
|
+
year: ["PlainDate", "PlainDateTime", "ZonedDateTime", "PlainYearMonth"],
|
|
523
|
+
month: ["PlainDate", "PlainDateTime", "ZonedDateTime", "PlainYearMonth", "PlainMonthDay"],
|
|
524
|
+
day: ["PlainDate", "PlainDateTime", "ZonedDateTime", "PlainMonthDay"],
|
|
525
|
+
// Instant deliberately NOT listed: Temporal.Instant exposes no
|
|
526
|
+
// hour/minute/second/millisecond wall-clock fields (they're
|
|
527
|
+
// zone-dependent), so format(instant, 'HH') throws at the field
|
|
528
|
+
// check — the metadata used to claim Instant was supported, telling
|
|
529
|
+
// analyzer/IDE consumers the opposite of what runtime does.
|
|
530
|
+
hour: ["PlainTime", "PlainDateTime", "ZonedDateTime"],
|
|
531
|
+
minute: ["PlainTime", "PlainDateTime", "ZonedDateTime"],
|
|
532
|
+
second: ["PlainTime", "PlainDateTime", "ZonedDateTime"],
|
|
533
|
+
millisecond: ["PlainTime", "PlainDateTime", "ZonedDateTime"],
|
|
534
|
+
dayOfWeek: ["PlainDate", "PlainDateTime", "ZonedDateTime"],
|
|
535
|
+
timeZoneId: ["ZonedDateTime"],
|
|
536
|
+
offset: ["ZonedDateTime"]
|
|
537
|
+
};
|
|
538
|
+
var TOKEN_METADATA = {
|
|
539
|
+
yyyy: {
|
|
540
|
+
meaning: "Four-digit year (preserves sign for BCE; no truncation).",
|
|
541
|
+
formatCapable: true,
|
|
542
|
+
parseCapable: true,
|
|
543
|
+
localeSensitive: false,
|
|
544
|
+
calendarSensitive: true,
|
|
545
|
+
timezoneSensitive: false,
|
|
546
|
+
supportedTypes: TYPES_WITH.year,
|
|
547
|
+
roundTripSafe: true
|
|
548
|
+
},
|
|
549
|
+
yy: {
|
|
550
|
+
meaning: "Two-digit year (year % 100). Throws on negative years.",
|
|
551
|
+
formatCapable: true,
|
|
552
|
+
parseCapable: true,
|
|
553
|
+
localeSensitive: false,
|
|
554
|
+
calendarSensitive: true,
|
|
555
|
+
timezoneSensitive: false,
|
|
556
|
+
supportedTypes: TYPES_WITH.year,
|
|
557
|
+
roundTripSafe: false
|
|
558
|
+
},
|
|
559
|
+
y: {
|
|
560
|
+
meaning: "Unpadded year, any width (preserves sign for BCE; no truncation, no minimum digits). Cannot sit directly next to another digit-reading token or a literal starting with a digit \u2014 there would be no way to tell where it ends.",
|
|
561
|
+
formatCapable: true,
|
|
562
|
+
parseCapable: true,
|
|
563
|
+
localeSensitive: false,
|
|
564
|
+
calendarSensitive: true,
|
|
565
|
+
timezoneSensitive: false,
|
|
566
|
+
supportedTypes: TYPES_WITH.year,
|
|
567
|
+
roundTripSafe: true
|
|
568
|
+
},
|
|
569
|
+
MMMM: {
|
|
570
|
+
meaning: 'Long month name (locale-aware, e.g. "January", "janvier").',
|
|
571
|
+
formatCapable: true,
|
|
572
|
+
parseCapable: true,
|
|
573
|
+
localeSensitive: true,
|
|
574
|
+
calendarSensitive: true,
|
|
575
|
+
timezoneSensitive: false,
|
|
576
|
+
supportedTypes: TYPES_WITH.month,
|
|
577
|
+
roundTripSafe: true
|
|
578
|
+
},
|
|
579
|
+
MMM: {
|
|
580
|
+
meaning: 'Short month name (locale-aware, e.g. "Jan", "janv.").',
|
|
581
|
+
formatCapable: true,
|
|
582
|
+
parseCapable: true,
|
|
583
|
+
localeSensitive: true,
|
|
584
|
+
calendarSensitive: true,
|
|
585
|
+
timezoneSensitive: false,
|
|
586
|
+
supportedTypes: TYPES_WITH.month,
|
|
587
|
+
roundTripSafe: true
|
|
588
|
+
},
|
|
589
|
+
MM: {
|
|
590
|
+
meaning: "Two-digit month (01-12, zero-padded).",
|
|
591
|
+
formatCapable: true,
|
|
592
|
+
parseCapable: true,
|
|
593
|
+
localeSensitive: false,
|
|
594
|
+
calendarSensitive: true,
|
|
595
|
+
timezoneSensitive: false,
|
|
596
|
+
supportedTypes: TYPES_WITH.month,
|
|
597
|
+
roundTripSafe: true
|
|
598
|
+
},
|
|
599
|
+
M: {
|
|
600
|
+
meaning: "One- or two-digit month (1-12, no padding).",
|
|
601
|
+
formatCapable: true,
|
|
602
|
+
parseCapable: true,
|
|
603
|
+
localeSensitive: false,
|
|
604
|
+
calendarSensitive: true,
|
|
605
|
+
timezoneSensitive: false,
|
|
606
|
+
supportedTypes: TYPES_WITH.month,
|
|
607
|
+
roundTripSafe: true
|
|
608
|
+
},
|
|
609
|
+
dd: {
|
|
610
|
+
meaning: "Two-digit day-of-month (01-31, zero-padded).",
|
|
611
|
+
formatCapable: true,
|
|
612
|
+
parseCapable: true,
|
|
613
|
+
localeSensitive: false,
|
|
614
|
+
calendarSensitive: true,
|
|
615
|
+
timezoneSensitive: false,
|
|
616
|
+
supportedTypes: TYPES_WITH.day,
|
|
617
|
+
roundTripSafe: true
|
|
618
|
+
},
|
|
619
|
+
d: {
|
|
620
|
+
meaning: "One- or two-digit day-of-month (1-31, no padding).",
|
|
621
|
+
formatCapable: true,
|
|
622
|
+
parseCapable: true,
|
|
623
|
+
localeSensitive: false,
|
|
624
|
+
calendarSensitive: true,
|
|
625
|
+
timezoneSensitive: false,
|
|
626
|
+
supportedTypes: TYPES_WITH.day,
|
|
627
|
+
roundTripSafe: true
|
|
628
|
+
},
|
|
629
|
+
EEEE: {
|
|
630
|
+
meaning: 'Long weekday name (locale-aware, e.g. "Monday", "lundi"). Parse cross-checks against the parsed date.',
|
|
631
|
+
formatCapable: true,
|
|
632
|
+
parseCapable: true,
|
|
633
|
+
localeSensitive: true,
|
|
634
|
+
calendarSensitive: true,
|
|
635
|
+
timezoneSensitive: false,
|
|
636
|
+
supportedTypes: TYPES_WITH.dayOfWeek,
|
|
637
|
+
roundTripSafe: true
|
|
638
|
+
},
|
|
639
|
+
EEE: {
|
|
640
|
+
meaning: 'Short weekday name (locale-aware, e.g. "Mon", "lun."). Parse cross-checks against the parsed date.',
|
|
641
|
+
formatCapable: true,
|
|
642
|
+
parseCapable: true,
|
|
643
|
+
localeSensitive: true,
|
|
644
|
+
calendarSensitive: true,
|
|
645
|
+
timezoneSensitive: false,
|
|
646
|
+
supportedTypes: TYPES_WITH.dayOfWeek,
|
|
647
|
+
roundTripSafe: true
|
|
648
|
+
},
|
|
649
|
+
HH: {
|
|
650
|
+
meaning: "Two-digit hour, 24-hour clock (00-23, zero-padded).",
|
|
651
|
+
formatCapable: true,
|
|
652
|
+
parseCapable: true,
|
|
653
|
+
localeSensitive: false,
|
|
654
|
+
calendarSensitive: false,
|
|
655
|
+
timezoneSensitive: false,
|
|
656
|
+
supportedTypes: TYPES_WITH.hour,
|
|
657
|
+
roundTripSafe: true
|
|
658
|
+
},
|
|
659
|
+
H: {
|
|
660
|
+
meaning: "One- or two-digit hour, 24-hour clock (0-23, no padding).",
|
|
661
|
+
formatCapable: true,
|
|
662
|
+
parseCapable: true,
|
|
663
|
+
localeSensitive: false,
|
|
664
|
+
calendarSensitive: false,
|
|
665
|
+
timezoneSensitive: false,
|
|
666
|
+
supportedTypes: TYPES_WITH.hour,
|
|
667
|
+
roundTripSafe: true
|
|
668
|
+
},
|
|
669
|
+
hh: {
|
|
670
|
+
meaning: "Two-digit hour, 12-hour clock (01-12, zero-padded). Requires `a` token on parse.",
|
|
671
|
+
formatCapable: true,
|
|
672
|
+
parseCapable: true,
|
|
673
|
+
localeSensitive: false,
|
|
674
|
+
calendarSensitive: false,
|
|
675
|
+
timezoneSensitive: false,
|
|
676
|
+
supportedTypes: TYPES_WITH.hour,
|
|
677
|
+
roundTripSafe: true
|
|
678
|
+
},
|
|
679
|
+
h: {
|
|
680
|
+
meaning: "One- or two-digit hour, 12-hour clock (1-12, no padding). Requires `a` token on parse.",
|
|
681
|
+
formatCapable: true,
|
|
682
|
+
parseCapable: true,
|
|
683
|
+
localeSensitive: false,
|
|
684
|
+
calendarSensitive: false,
|
|
685
|
+
timezoneSensitive: false,
|
|
686
|
+
supportedTypes: TYPES_WITH.hour,
|
|
687
|
+
roundTripSafe: true
|
|
688
|
+
},
|
|
689
|
+
mm: {
|
|
690
|
+
meaning: "Two-digit minute (00-59, zero-padded).",
|
|
691
|
+
formatCapable: true,
|
|
692
|
+
parseCapable: true,
|
|
693
|
+
localeSensitive: false,
|
|
694
|
+
calendarSensitive: false,
|
|
695
|
+
timezoneSensitive: false,
|
|
696
|
+
supportedTypes: TYPES_WITH.minute,
|
|
697
|
+
roundTripSafe: true
|
|
698
|
+
},
|
|
699
|
+
m: {
|
|
700
|
+
meaning: "One- or two-digit minute (0-59, no padding).",
|
|
701
|
+
formatCapable: true,
|
|
702
|
+
parseCapable: true,
|
|
703
|
+
localeSensitive: false,
|
|
704
|
+
calendarSensitive: false,
|
|
705
|
+
timezoneSensitive: false,
|
|
706
|
+
supportedTypes: TYPES_WITH.minute,
|
|
707
|
+
roundTripSafe: true
|
|
708
|
+
},
|
|
709
|
+
ss: {
|
|
710
|
+
meaning: "Two-digit second (00-59, zero-padded).",
|
|
711
|
+
formatCapable: true,
|
|
712
|
+
parseCapable: true,
|
|
713
|
+
localeSensitive: false,
|
|
714
|
+
calendarSensitive: false,
|
|
715
|
+
timezoneSensitive: false,
|
|
716
|
+
supportedTypes: TYPES_WITH.second,
|
|
717
|
+
roundTripSafe: true
|
|
718
|
+
},
|
|
719
|
+
s: {
|
|
720
|
+
meaning: "One- or two-digit second (0-59, no padding).",
|
|
721
|
+
formatCapable: true,
|
|
722
|
+
parseCapable: true,
|
|
723
|
+
localeSensitive: false,
|
|
724
|
+
calendarSensitive: false,
|
|
725
|
+
timezoneSensitive: false,
|
|
726
|
+
supportedTypes: TYPES_WITH.second,
|
|
727
|
+
roundTripSafe: true
|
|
728
|
+
},
|
|
729
|
+
S: {
|
|
730
|
+
meaning: "Fractional second, 1 digit (tenths of a second).",
|
|
731
|
+
formatCapable: true,
|
|
732
|
+
parseCapable: true,
|
|
733
|
+
localeSensitive: false,
|
|
734
|
+
calendarSensitive: false,
|
|
735
|
+
timezoneSensitive: false,
|
|
736
|
+
supportedTypes: TYPES_WITH.millisecond,
|
|
737
|
+
roundTripSafe: true
|
|
738
|
+
},
|
|
739
|
+
SS: {
|
|
740
|
+
meaning: "Fractional second, 2 digits (hundredths of a second).",
|
|
741
|
+
formatCapable: true,
|
|
742
|
+
parseCapable: true,
|
|
743
|
+
localeSensitive: false,
|
|
744
|
+
calendarSensitive: false,
|
|
745
|
+
timezoneSensitive: false,
|
|
746
|
+
supportedTypes: TYPES_WITH.millisecond,
|
|
747
|
+
roundTripSafe: true
|
|
748
|
+
},
|
|
749
|
+
SSS: {
|
|
750
|
+
meaning: "Fractional second, 3 digits (milliseconds).",
|
|
751
|
+
formatCapable: true,
|
|
752
|
+
parseCapable: true,
|
|
753
|
+
localeSensitive: false,
|
|
754
|
+
calendarSensitive: false,
|
|
755
|
+
timezoneSensitive: false,
|
|
756
|
+
supportedTypes: TYPES_WITH.millisecond,
|
|
757
|
+
roundTripSafe: true
|
|
758
|
+
},
|
|
759
|
+
SSSS: {
|
|
760
|
+
meaning: "Fractional second, 4 digits (tens of microseconds).",
|
|
761
|
+
formatCapable: true,
|
|
762
|
+
parseCapable: true,
|
|
763
|
+
localeSensitive: false,
|
|
764
|
+
calendarSensitive: false,
|
|
765
|
+
timezoneSensitive: false,
|
|
766
|
+
supportedTypes: TYPES_WITH.millisecond,
|
|
767
|
+
roundTripSafe: true
|
|
768
|
+
},
|
|
769
|
+
SSSSS: {
|
|
770
|
+
meaning: "Fractional second, 5 digits (hundred-thousandths of a second).",
|
|
771
|
+
formatCapable: true,
|
|
772
|
+
parseCapable: true,
|
|
773
|
+
localeSensitive: false,
|
|
774
|
+
calendarSensitive: false,
|
|
775
|
+
timezoneSensitive: false,
|
|
776
|
+
supportedTypes: TYPES_WITH.millisecond,
|
|
777
|
+
roundTripSafe: true
|
|
778
|
+
},
|
|
779
|
+
SSSSSS: {
|
|
780
|
+
meaning: "Fractional second, 6 digits (microseconds).",
|
|
781
|
+
formatCapable: true,
|
|
782
|
+
parseCapable: true,
|
|
783
|
+
localeSensitive: false,
|
|
784
|
+
calendarSensitive: false,
|
|
785
|
+
timezoneSensitive: false,
|
|
786
|
+
supportedTypes: TYPES_WITH.millisecond,
|
|
787
|
+
roundTripSafe: true
|
|
788
|
+
},
|
|
789
|
+
SSSSSSS: {
|
|
790
|
+
meaning: "Fractional second, 7 digits (tens of nanoseconds).",
|
|
791
|
+
formatCapable: true,
|
|
792
|
+
parseCapable: true,
|
|
793
|
+
localeSensitive: false,
|
|
794
|
+
calendarSensitive: false,
|
|
795
|
+
timezoneSensitive: false,
|
|
796
|
+
supportedTypes: TYPES_WITH.millisecond,
|
|
797
|
+
roundTripSafe: true
|
|
798
|
+
},
|
|
799
|
+
SSSSSSSS: {
|
|
800
|
+
meaning: "Fractional second, 8 digits (hundred-millionths of a second).",
|
|
801
|
+
formatCapable: true,
|
|
802
|
+
parseCapable: true,
|
|
803
|
+
localeSensitive: false,
|
|
804
|
+
calendarSensitive: false,
|
|
805
|
+
timezoneSensitive: false,
|
|
806
|
+
supportedTypes: TYPES_WITH.millisecond,
|
|
807
|
+
roundTripSafe: true
|
|
808
|
+
},
|
|
809
|
+
SSSSSSSSS: {
|
|
810
|
+
meaning: "Fractional second, 9 digits (nanoseconds).",
|
|
811
|
+
formatCapable: true,
|
|
812
|
+
parseCapable: true,
|
|
813
|
+
localeSensitive: false,
|
|
814
|
+
calendarSensitive: false,
|
|
815
|
+
timezoneSensitive: false,
|
|
816
|
+
supportedTypes: TYPES_WITH.millisecond,
|
|
817
|
+
roundTripSafe: true
|
|
818
|
+
},
|
|
819
|
+
a: {
|
|
820
|
+
meaning: 'Day period (locale-aware: "AM"/"PM", "\u5348\u524D"/"\u5348\u5F8C", etc.). Required alongside 12-hour tokens on parse.',
|
|
821
|
+
formatCapable: true,
|
|
822
|
+
parseCapable: true,
|
|
823
|
+
localeSensitive: true,
|
|
824
|
+
calendarSensitive: false,
|
|
825
|
+
timezoneSensitive: false,
|
|
826
|
+
supportedTypes: TYPES_WITH.hour,
|
|
827
|
+
roundTripSafe: true
|
|
828
|
+
},
|
|
829
|
+
zzz: {
|
|
830
|
+
meaning: 'IANA time zone id (e.g. "America/New_York") or fixed offset ("+05:30"). Requires full date+time on parse.',
|
|
831
|
+
formatCapable: true,
|
|
832
|
+
parseCapable: true,
|
|
833
|
+
localeSensitive: false,
|
|
834
|
+
calendarSensitive: false,
|
|
835
|
+
timezoneSensitive: true,
|
|
836
|
+
supportedTypes: TYPES_WITH.timeZoneId,
|
|
837
|
+
roundTripSafe: true
|
|
838
|
+
},
|
|
839
|
+
X: {
|
|
840
|
+
meaning: "Numeric UTC offset, short (Z for UTC, \xB1HH[MM] otherwise). Minutes omitted when zero.",
|
|
841
|
+
formatCapable: true,
|
|
842
|
+
parseCapable: true,
|
|
843
|
+
localeSensitive: false,
|
|
844
|
+
calendarSensitive: false,
|
|
845
|
+
timezoneSensitive: true,
|
|
846
|
+
supportedTypes: TYPES_WITH.offset,
|
|
847
|
+
roundTripSafe: true
|
|
848
|
+
},
|
|
849
|
+
XX: {
|
|
850
|
+
meaning: "Numeric UTC offset, no colon (Z for UTC, \xB1HHMM otherwise).",
|
|
851
|
+
formatCapable: true,
|
|
852
|
+
parseCapable: true,
|
|
853
|
+
localeSensitive: false,
|
|
854
|
+
calendarSensitive: false,
|
|
855
|
+
timezoneSensitive: true,
|
|
856
|
+
supportedTypes: TYPES_WITH.offset,
|
|
857
|
+
roundTripSafe: true
|
|
858
|
+
},
|
|
859
|
+
XXX: {
|
|
860
|
+
meaning: "Numeric UTC offset, with colon (Z for UTC, \xB1HH:MM otherwise).",
|
|
861
|
+
formatCapable: true,
|
|
862
|
+
parseCapable: true,
|
|
863
|
+
localeSensitive: false,
|
|
864
|
+
calendarSensitive: false,
|
|
865
|
+
timezoneSensitive: true,
|
|
866
|
+
supportedTypes: TYPES_WITH.offset,
|
|
867
|
+
roundTripSafe: true
|
|
868
|
+
},
|
|
869
|
+
x: {
|
|
870
|
+
meaning: "Numeric UTC offset, short, never Z (always \xB1HH[MM]). Lowercase variant of X.",
|
|
871
|
+
formatCapable: true,
|
|
872
|
+
parseCapable: true,
|
|
873
|
+
localeSensitive: false,
|
|
874
|
+
calendarSensitive: false,
|
|
875
|
+
timezoneSensitive: true,
|
|
876
|
+
supportedTypes: TYPES_WITH.offset,
|
|
877
|
+
roundTripSafe: true
|
|
878
|
+
},
|
|
879
|
+
xx: {
|
|
880
|
+
meaning: "Numeric UTC offset, no colon, never Z (always \xB1HHMM). Lowercase variant of XX.",
|
|
881
|
+
formatCapable: true,
|
|
882
|
+
parseCapable: true,
|
|
883
|
+
localeSensitive: false,
|
|
884
|
+
calendarSensitive: false,
|
|
885
|
+
timezoneSensitive: true,
|
|
886
|
+
supportedTypes: TYPES_WITH.offset,
|
|
887
|
+
roundTripSafe: true
|
|
888
|
+
},
|
|
889
|
+
xxx: {
|
|
890
|
+
meaning: "Numeric UTC offset, with colon, never Z (always \xB1HH:MM). Lowercase variant of XXX.",
|
|
891
|
+
formatCapable: true,
|
|
892
|
+
parseCapable: true,
|
|
893
|
+
localeSensitive: false,
|
|
894
|
+
calendarSensitive: false,
|
|
895
|
+
timezoneSensitive: true,
|
|
896
|
+
supportedTypes: TYPES_WITH.offset,
|
|
897
|
+
roundTripSafe: true
|
|
898
|
+
},
|
|
899
|
+
do: {
|
|
900
|
+
meaning: 'Ordinal day-of-month with English suffix ("1st", "2nd", "3rd", "4th", ... 21st, 22nd, ...). Format-only \u2014 not parseable.',
|
|
901
|
+
formatCapable: true,
|
|
902
|
+
parseCapable: false,
|
|
903
|
+
localeSensitive: false,
|
|
904
|
+
calendarSensitive: true,
|
|
905
|
+
timezoneSensitive: false,
|
|
906
|
+
supportedTypes: TYPES_WITH.day,
|
|
907
|
+
roundTripSafe: false
|
|
908
|
+
},
|
|
909
|
+
Q: {
|
|
910
|
+
meaning: "Quarter as a digit (1-4). Derived from month.",
|
|
911
|
+
formatCapable: true,
|
|
912
|
+
parseCapable: true,
|
|
913
|
+
localeSensitive: false,
|
|
914
|
+
calendarSensitive: true,
|
|
915
|
+
timezoneSensitive: false,
|
|
916
|
+
supportedTypes: TYPES_WITH.month,
|
|
917
|
+
roundTripSafe: true
|
|
918
|
+
},
|
|
919
|
+
QQQ: {
|
|
920
|
+
meaning: 'Quarter with "Q" prefix ("Q1".."Q4"). Derived from month.',
|
|
921
|
+
formatCapable: true,
|
|
922
|
+
parseCapable: true,
|
|
923
|
+
localeSensitive: false,
|
|
924
|
+
calendarSensitive: true,
|
|
925
|
+
timezoneSensitive: false,
|
|
926
|
+
supportedTypes: TYPES_WITH.month,
|
|
927
|
+
roundTripSafe: true
|
|
928
|
+
},
|
|
929
|
+
ww: {
|
|
930
|
+
meaning: "ISO 8601 week number (01-53). Format-only \u2014 week alone can't reconstruct a date.",
|
|
931
|
+
formatCapable: true,
|
|
932
|
+
parseCapable: false,
|
|
933
|
+
localeSensitive: false,
|
|
934
|
+
calendarSensitive: true,
|
|
935
|
+
timezoneSensitive: false,
|
|
936
|
+
supportedTypes: TYPES_WITH.dayOfWeek,
|
|
937
|
+
roundTripSafe: false
|
|
938
|
+
},
|
|
939
|
+
RRRR: {
|
|
940
|
+
meaning: "ISO 8601 week-numbering year (4-digit, may differ from calendar year at year boundaries). Format-only.",
|
|
941
|
+
formatCapable: true,
|
|
942
|
+
parseCapable: false,
|
|
943
|
+
localeSensitive: false,
|
|
944
|
+
calendarSensitive: true,
|
|
945
|
+
timezoneSensitive: false,
|
|
946
|
+
supportedTypes: TYPES_WITH.dayOfWeek,
|
|
947
|
+
roundTripSafe: false
|
|
948
|
+
},
|
|
949
|
+
// Day-of-year is leap-adjusted, so it needs a YEAR — PlainMonthDay
|
|
950
|
+
// (month+day with no year) used to be listed as supported here while
|
|
951
|
+
// format() computed a non-leap day-of-year for it.
|
|
952
|
+
D: {
|
|
953
|
+
meaning: "Day of year, unpadded (1-366). Format-only \u2014 parsing requires resolving against a year.",
|
|
954
|
+
formatCapable: true,
|
|
955
|
+
parseCapable: false,
|
|
956
|
+
localeSensitive: false,
|
|
957
|
+
calendarSensitive: true,
|
|
958
|
+
timezoneSensitive: false,
|
|
959
|
+
supportedTypes: TYPES_WITH.day.filter((t) => t !== "PlainMonthDay"),
|
|
960
|
+
roundTripSafe: false
|
|
961
|
+
},
|
|
962
|
+
DD: {
|
|
963
|
+
meaning: "Day of year, 2-digit minimum (01-366). Format-only.",
|
|
964
|
+
formatCapable: true,
|
|
965
|
+
parseCapable: false,
|
|
966
|
+
localeSensitive: false,
|
|
967
|
+
calendarSensitive: true,
|
|
968
|
+
timezoneSensitive: false,
|
|
969
|
+
supportedTypes: TYPES_WITH.day.filter((t) => t !== "PlainMonthDay"),
|
|
970
|
+
roundTripSafe: false
|
|
971
|
+
},
|
|
972
|
+
DDD: {
|
|
973
|
+
meaning: "Day of year, 3-digit zero-padded (001-366). Format-only.",
|
|
974
|
+
formatCapable: true,
|
|
975
|
+
parseCapable: false,
|
|
976
|
+
localeSensitive: false,
|
|
977
|
+
calendarSensitive: true,
|
|
978
|
+
timezoneSensitive: false,
|
|
979
|
+
supportedTypes: TYPES_WITH.day.filter((t) => t !== "PlainMonthDay"),
|
|
980
|
+
roundTripSafe: false
|
|
981
|
+
},
|
|
982
|
+
LLLL: {
|
|
983
|
+
meaning: "Stand-alone long month name (nominative case in Slavic locales). Identical to MMMM in most locales.",
|
|
984
|
+
formatCapable: true,
|
|
985
|
+
parseCapable: false,
|
|
986
|
+
localeSensitive: true,
|
|
987
|
+
calendarSensitive: true,
|
|
988
|
+
timezoneSensitive: false,
|
|
989
|
+
supportedTypes: TYPES_WITH.month,
|
|
990
|
+
roundTripSafe: true
|
|
991
|
+
},
|
|
992
|
+
LLL: {
|
|
993
|
+
meaning: "Stand-alone short month name. Identical to MMM in most locales.",
|
|
994
|
+
formatCapable: true,
|
|
995
|
+
parseCapable: false,
|
|
996
|
+
localeSensitive: true,
|
|
997
|
+
calendarSensitive: true,
|
|
998
|
+
timezoneSensitive: false,
|
|
999
|
+
supportedTypes: TYPES_WITH.month,
|
|
1000
|
+
roundTripSafe: true
|
|
1001
|
+
},
|
|
1002
|
+
cccc: {
|
|
1003
|
+
meaning: "Stand-alone long weekday name. Identical to EEEE in most locales.",
|
|
1004
|
+
formatCapable: true,
|
|
1005
|
+
parseCapable: false,
|
|
1006
|
+
localeSensitive: true,
|
|
1007
|
+
calendarSensitive: true,
|
|
1008
|
+
timezoneSensitive: false,
|
|
1009
|
+
supportedTypes: TYPES_WITH.dayOfWeek,
|
|
1010
|
+
roundTripSafe: true
|
|
1011
|
+
},
|
|
1012
|
+
ccc: {
|
|
1013
|
+
meaning: "Stand-alone short weekday name. Identical to EEE in most locales.",
|
|
1014
|
+
formatCapable: true,
|
|
1015
|
+
parseCapable: false,
|
|
1016
|
+
localeSensitive: true,
|
|
1017
|
+
calendarSensitive: true,
|
|
1018
|
+
timezoneSensitive: false,
|
|
1019
|
+
supportedTypes: TYPES_WITH.dayOfWeek,
|
|
1020
|
+
roundTripSafe: true
|
|
1021
|
+
},
|
|
1022
|
+
GGGG: {
|
|
1023
|
+
meaning: 'Long era name (locale-aware, e.g. "Anno Domini"/"Before Christ"). Format-only.',
|
|
1024
|
+
formatCapable: true,
|
|
1025
|
+
parseCapable: false,
|
|
1026
|
+
localeSensitive: true,
|
|
1027
|
+
calendarSensitive: true,
|
|
1028
|
+
timezoneSensitive: false,
|
|
1029
|
+
supportedTypes: TYPES_WITH.year,
|
|
1030
|
+
roundTripSafe: false
|
|
1031
|
+
},
|
|
1032
|
+
G: {
|
|
1033
|
+
meaning: 'Short era name (locale-aware, e.g. "AD"/"BC"). Format-only.',
|
|
1034
|
+
formatCapable: true,
|
|
1035
|
+
parseCapable: false,
|
|
1036
|
+
localeSensitive: true,
|
|
1037
|
+
calendarSensitive: true,
|
|
1038
|
+
timezoneSensitive: false,
|
|
1039
|
+
supportedTypes: TYPES_WITH.year,
|
|
1040
|
+
roundTripSafe: false
|
|
1041
|
+
},
|
|
1042
|
+
zzzz: {
|
|
1043
|
+
meaning: 'Localized long timezone name (e.g. "Eastern Standard Time"). Format-only.',
|
|
1044
|
+
formatCapable: true,
|
|
1045
|
+
parseCapable: false,
|
|
1046
|
+
localeSensitive: true,
|
|
1047
|
+
calendarSensitive: false,
|
|
1048
|
+
timezoneSensitive: true,
|
|
1049
|
+
supportedTypes: TYPES_WITH.timeZoneId,
|
|
1050
|
+
roundTripSafe: false
|
|
1051
|
+
},
|
|
1052
|
+
z: {
|
|
1053
|
+
meaning: 'Localized short timezone name (e.g. "EST"). Format-only.',
|
|
1054
|
+
formatCapable: true,
|
|
1055
|
+
parseCapable: false,
|
|
1056
|
+
localeSensitive: true,
|
|
1057
|
+
calendarSensitive: false,
|
|
1058
|
+
timezoneSensitive: true,
|
|
1059
|
+
supportedTypes: TYPES_WITH.timeZoneId,
|
|
1060
|
+
roundTripSafe: false
|
|
657
1061
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
1062
|
+
};
|
|
1063
|
+
var ALL_TOKEN_NAMES = Object.keys(TOKEN_METADATA);
|
|
1064
|
+
|
|
1065
|
+
// src/analyze.ts
|
|
1066
|
+
function tokenizeFormat(formatStr) {
|
|
1067
|
+
return tokenize(formatStr);
|
|
1068
|
+
}
|
|
1069
|
+
function listTokens() {
|
|
1070
|
+
return TOKENS.map(([name]) => ({ name, metadata: TOKEN_METADATA[name] }));
|
|
1071
|
+
}
|
|
1072
|
+
function tokenInfo(name) {
|
|
1073
|
+
return TOKEN_METADATA[name];
|
|
1074
|
+
}
|
|
1075
|
+
function analyzeFormat(formatStr) {
|
|
1076
|
+
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
1077
|
+
throw new Error(
|
|
1078
|
+
`temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`
|
|
1079
|
+
);
|
|
1080
|
+
}
|
|
1081
|
+
const pieces = tokenizeWithSpans(formatStr);
|
|
1082
|
+
const tokens = [];
|
|
1083
|
+
const requiredFields = /* @__PURE__ */ new Set();
|
|
1084
|
+
const compatibleTypesSet = /* @__PURE__ */ new Set();
|
|
1085
|
+
let parseable = true;
|
|
1086
|
+
let localeSensitive = false;
|
|
1087
|
+
let calendarSensitive = false;
|
|
1088
|
+
let timezoneSensitive = false;
|
|
1089
|
+
let roundTripSafe = true;
|
|
1090
|
+
const warnings = [];
|
|
1091
|
+
const unpaddedRun = [];
|
|
1092
|
+
const flushRun = () => {
|
|
1093
|
+
if (unpaddedRun.length >= 2) {
|
|
1094
|
+
warnings.push({
|
|
1095
|
+
code: "AMBIGUOUS_NUMERIC_RUN",
|
|
1096
|
+
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").`
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
unpaddedRun.length = 0;
|
|
1100
|
+
};
|
|
1101
|
+
for (const piece of pieces) {
|
|
1102
|
+
if (piece.kind === "literal") {
|
|
1103
|
+
flushRun();
|
|
1104
|
+
continue;
|
|
1105
|
+
}
|
|
1106
|
+
const metadata = TOKEN_METADATA[piece.value];
|
|
1107
|
+
if (!metadata) {
|
|
1108
|
+
warnings.push({
|
|
1109
|
+
code: "UNKNOWN_TOKEN_NO_METADATA",
|
|
1110
|
+
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.`
|
|
1111
|
+
});
|
|
1112
|
+
continue;
|
|
1113
|
+
}
|
|
1114
|
+
tokens.push({ name: piece.value, position: piece.start, metadata });
|
|
1115
|
+
const handler = _handlerFor(piece.value);
|
|
1116
|
+
if (handler) {
|
|
1117
|
+
requiredFields.add(handler.field);
|
|
1118
|
+
}
|
|
1119
|
+
if (tokens.length === 1) {
|
|
1120
|
+
for (const t of metadata.supportedTypes) compatibleTypesSet.add(t);
|
|
662
1121
|
} else {
|
|
663
|
-
|
|
1122
|
+
const stillCompatible = /* @__PURE__ */ new Set();
|
|
1123
|
+
for (const t of compatibleTypesSet) {
|
|
1124
|
+
if (metadata.supportedTypes.includes(t)) stillCompatible.add(t);
|
|
1125
|
+
}
|
|
1126
|
+
compatibleTypesSet.clear();
|
|
1127
|
+
for (const t of stillCompatible) compatibleTypesSet.add(t);
|
|
1128
|
+
}
|
|
1129
|
+
if (!metadata.parseCapable) {
|
|
1130
|
+
parseable = false;
|
|
1131
|
+
warnings.push({
|
|
1132
|
+
code: "FORMAT_ONLY_TOKEN",
|
|
1133
|
+
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.`
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
if (metadata.localeSensitive) localeSensitive = true;
|
|
1137
|
+
if (metadata.calendarSensitive) calendarSensitive = true;
|
|
1138
|
+
if (metadata.timezoneSensitive) timezoneSensitive = true;
|
|
1139
|
+
if (!metadata.roundTripSafe) roundTripSafe = false;
|
|
1140
|
+
if (UNPADDED_NUMERIC_TOKENS.has(piece.value)) {
|
|
1141
|
+
unpaddedRun.push(piece.value);
|
|
1142
|
+
} else {
|
|
1143
|
+
flushRun();
|
|
664
1144
|
}
|
|
665
1145
|
}
|
|
666
|
-
|
|
667
|
-
const
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
1146
|
+
flushRun();
|
|
1147
|
+
const tokenNames = tokens.map((t) => t.name);
|
|
1148
|
+
const has12Hour = tokenNames.some((t) => t === "hh" || t === "h");
|
|
1149
|
+
const has24Hour = tokenNames.some((t) => t === "HH" || t === "H");
|
|
1150
|
+
const hasAPeriod = tokenNames.some((t) => t === "a");
|
|
1151
|
+
if (has12Hour && !hasAPeriod) {
|
|
1152
|
+
warnings.push({
|
|
1153
|
+
code: "TWELVE_HOUR_WITHOUT_A",
|
|
1154
|
+
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.`
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
if (has12Hour && has24Hour) {
|
|
1158
|
+
warnings.push({
|
|
1159
|
+
code: "MIXED_12_AND_24_HOUR",
|
|
1160
|
+
message: "Mixing 24-hour and 12-hour tokens \u2014 parse() refuses to guess which is authoritative and throws at runtime."
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
const hasOffset = tokenNames.some((t) => t === "X" || t === "XX" || t === "XXX" || t === "x" || t === "xx" || t === "xxx");
|
|
1164
|
+
const hasZzz = tokenNames.some((t) => t === "zzz");
|
|
1165
|
+
if (hasOffset && hasZzz) {
|
|
1166
|
+
warnings.push({
|
|
1167
|
+
code: "ZZZ_WITH_OFFSET_TOKEN",
|
|
1168
|
+
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.`
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
if (hasOffset && !requiredFields.has("year")) {
|
|
1172
|
+
warnings.push({
|
|
1173
|
+
code: "OFFSET_WITHOUT_FULL_DATE",
|
|
1174
|
+
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."
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
return {
|
|
1178
|
+
tokens,
|
|
1179
|
+
requiredFields: [...requiredFields].sort(),
|
|
1180
|
+
compatibleTypes: [...compatibleTypesSet].sort(),
|
|
1181
|
+
parseable,
|
|
1182
|
+
localeSensitive,
|
|
1183
|
+
calendarSensitive,
|
|
1184
|
+
timezoneSensitive,
|
|
1185
|
+
// Ambiguous iff at least one warning fired about an ambiguous run.
|
|
1186
|
+
ambiguous: warnings.some((w) => w.code === "AMBIGUOUS_NUMERIC_RUN"),
|
|
1187
|
+
roundTripSafe: roundTripSafe && parseable,
|
|
1188
|
+
warnings
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
function explainFormat(formatStr) {
|
|
1192
|
+
const analysis = analyzeFormat(formatStr);
|
|
1193
|
+
const lines = [];
|
|
1194
|
+
lines.push(`Format string: "${formatStr}"`);
|
|
1195
|
+
lines.push(`Tokens (${analysis.tokens.length}):`);
|
|
1196
|
+
for (const t of analysis.tokens) {
|
|
1197
|
+
lines.push(` ${t.name} @${t.position} \u2014 ${t.metadata.meaning}`);
|
|
1198
|
+
}
|
|
1199
|
+
if (analysis.requiredFields.length > 0) {
|
|
1200
|
+
lines.push(`Required fields: ${analysis.requiredFields.join(", ")}`);
|
|
1201
|
+
}
|
|
1202
|
+
if (analysis.compatibleTypes.length > 0) {
|
|
1203
|
+
lines.push(`Compatible Temporal types: ${analysis.compatibleTypes.join(", ")}`);
|
|
1204
|
+
}
|
|
1205
|
+
lines.push(`Parseable: ${analysis.parseable ? "yes" : "no"}`);
|
|
1206
|
+
lines.push(`Locale-sensitive: ${analysis.localeSensitive ? "yes" : "no"}`);
|
|
1207
|
+
lines.push(`Calendar-sensitive: ${analysis.calendarSensitive ? "yes" : "no"}`);
|
|
1208
|
+
lines.push(`Timezone-sensitive: ${analysis.timezoneSensitive ? "yes" : "no"}`);
|
|
1209
|
+
lines.push(`Ambiguous: ${analysis.ambiguous ? "yes" : "no"}`);
|
|
1210
|
+
lines.push(`Round-trip safe: ${analysis.roundTripSafe ? "yes" : "no"}`);
|
|
1211
|
+
if (analysis.warnings.length > 0) {
|
|
1212
|
+
lines.push("Warnings:");
|
|
1213
|
+
for (const w of analysis.warnings) {
|
|
1214
|
+
lines.push(` [${w.code}] ${w.message}`);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
return lines.join("\n");
|
|
1218
|
+
}
|
|
1219
|
+
function isValidFormat(formatStr) {
|
|
1220
|
+
if (formatStr.length > MAX_FORMAT_LENGTH) return false;
|
|
1221
|
+
try {
|
|
1222
|
+
tokenize(formatStr);
|
|
1223
|
+
return true;
|
|
1224
|
+
} catch {
|
|
1225
|
+
return false;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
function validateFormat(formatStr) {
|
|
1229
|
+
const analysis = analyzeFormat(formatStr);
|
|
1230
|
+
return analysis;
|
|
1231
|
+
}
|
|
1232
|
+
function fieldForToken(token) {
|
|
1233
|
+
return _handlerFor(token)?.field;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
// src/serialization.ts
|
|
1237
|
+
function parseISO(input) {
|
|
1238
|
+
const temporal = getTemporal();
|
|
1239
|
+
try {
|
|
1240
|
+
if (/^\d{4}-\d{2}-\d{2}T/.test(input) || /T\d{2}:\d{2}/.test(input)) {
|
|
1241
|
+
if (/[zZ]$/.test(input) || /[+-]\d{2}:?\d{2}$/.test(input)) {
|
|
1242
|
+
let iso = input;
|
|
1243
|
+
if (/[zZ]$/.test(iso)) {
|
|
1244
|
+
iso = iso.slice(0, -1) + "+00:00[UTC]";
|
|
1245
|
+
} else {
|
|
1246
|
+
const offsetMatch = /([+-]\d{2}:?\d{2})$/.exec(iso);
|
|
1247
|
+
if (offsetMatch) {
|
|
1248
|
+
iso = `${iso}[${offsetMatch[1]}]`;
|
|
693
1249
|
}
|
|
694
|
-
literal += formatStr[j];
|
|
695
|
-
j += 1;
|
|
696
|
-
}
|
|
697
|
-
if (!closed) throw new Error(`temporal-fmt: unterminated quote in format string "${formatStr}"`);
|
|
698
|
-
appendLiteral(pieces, literal);
|
|
699
|
-
i = j;
|
|
700
|
-
continue;
|
|
701
|
-
}
|
|
702
|
-
const match = sortedTokenStrings.find((tok) => formatStr.startsWith(tok, i));
|
|
703
|
-
if (match) {
|
|
704
|
-
const runChar = match[match.length - 1];
|
|
705
|
-
if (formatStr[i + match.length] === runChar) {
|
|
706
|
-
let end = i + match.length;
|
|
707
|
-
while (formatStr[end] === runChar) end += 1;
|
|
708
|
-
throw new UnknownTokenError({
|
|
709
|
-
token: formatStr.slice(i, end),
|
|
710
|
-
format: formatStr,
|
|
711
|
-
message: `temporal-fmt: "${formatStr.slice(i, end)}" in format string "${formatStr}" isn't a recognized token \u2014 did you mean "${match}"?`
|
|
712
|
-
});
|
|
713
1250
|
}
|
|
714
|
-
|
|
715
|
-
i += match.length;
|
|
716
|
-
continue;
|
|
1251
|
+
return temporal.ZonedDateTime.from(iso, { overflow: "reject" });
|
|
717
1252
|
}
|
|
718
|
-
|
|
719
|
-
i += 1;
|
|
1253
|
+
return temporal.PlainDateTime.from(input, { overflow: "reject" });
|
|
720
1254
|
}
|
|
721
|
-
|
|
1255
|
+
if (/^\d{4}-\d{2}-\d{2}/.test(input)) {
|
|
1256
|
+
return temporal.PlainDate.from(input, { overflow: "reject" });
|
|
1257
|
+
}
|
|
1258
|
+
if (/^\d{2}:\d{2}/.test(input)) {
|
|
1259
|
+
return temporal.PlainTime.from(input);
|
|
1260
|
+
}
|
|
1261
|
+
throw new Error(`temporal-fmt: parseISO("${input}") doesn't look like an ISO 8601 string.`);
|
|
1262
|
+
} catch (err) {
|
|
1263
|
+
throw new InvalidDateError({ input, reason: err.message });
|
|
722
1264
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
1265
|
+
}
|
|
1266
|
+
function formatISO(value) {
|
|
1267
|
+
const v = value;
|
|
1268
|
+
if (typeof v?.toString !== "function") {
|
|
1269
|
+
throw new FormatSyntaxError({ reason: `formatISO() expects a Temporal value with toString(), got ${typeof value}.` });
|
|
1270
|
+
}
|
|
1271
|
+
return v.toString();
|
|
1272
|
+
}
|
|
1273
|
+
function parseRFC3339(input) {
|
|
1274
|
+
const re = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(\.\d+)?([Zz]|[+-]\d{2}:\d{2})$/;
|
|
1275
|
+
const m = re.exec(input);
|
|
1276
|
+
if (!m) {
|
|
1277
|
+
throw new FormatSyntaxError({ input, reason: "does not match RFC 3339 date-time grammar" });
|
|
1278
|
+
}
|
|
1279
|
+
const iso = input.replace(/[tT]/, "T").replace(/[zZ]$/, "+00:00[UTC]");
|
|
1280
|
+
return parseISO(iso);
|
|
1281
|
+
}
|
|
1282
|
+
function formatRFC3339(value) {
|
|
1283
|
+
const s = formatISO(value);
|
|
1284
|
+
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)) {
|
|
1285
|
+
throw new FormatSyntaxError({ input: s, reason: "value did not produce RFC 3339-compliant output" });
|
|
1286
|
+
}
|
|
1287
|
+
return s;
|
|
1288
|
+
}
|
|
1289
|
+
function parseRFC2822(input) {
|
|
1290
|
+
const RFC2822_SHAPE = /^(?:(?: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})$/;
|
|
1291
|
+
if (!RFC2822_SHAPE.test(input.trim())) {
|
|
1292
|
+
throw new FormatSyntaxError({ input, reason: "not a valid RFC 2822 date" });
|
|
1293
|
+
}
|
|
1294
|
+
const ms = Date.parse(input);
|
|
1295
|
+
if (Number.isNaN(ms)) {
|
|
1296
|
+
throw new FormatSyntaxError({ input, reason: "not a valid RFC 2822 date" });
|
|
1297
|
+
}
|
|
1298
|
+
return requireInstant().fromEpochMilliseconds(ms);
|
|
1299
|
+
}
|
|
1300
|
+
function formatRFC2822(value) {
|
|
1301
|
+
const v = value;
|
|
1302
|
+
let ms;
|
|
1303
|
+
if (typeof v?.toEpochMilliseconds === "function") {
|
|
1304
|
+
ms = v.toEpochMilliseconds();
|
|
1305
|
+
} else if (typeof v?.epochMilliseconds === "number") {
|
|
1306
|
+
ms = v.epochMilliseconds;
|
|
1307
|
+
} else if (typeof v?.toInstant === "function") {
|
|
1308
|
+
const inst = v.toInstant();
|
|
1309
|
+
if (typeof inst.epochMilliseconds === "number") {
|
|
1310
|
+
ms = inst.epochMilliseconds;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
if (ms === void 0) {
|
|
1314
|
+
throw new FormatSyntaxError({ reason: `formatRFC2822() expects a value with epochMilliseconds, toEpochMilliseconds(), or toInstant(), got ${typeof value}.` });
|
|
1315
|
+
}
|
|
1316
|
+
return formatRFC2822FromMs(ms);
|
|
1317
|
+
}
|
|
1318
|
+
function formatRFC2822FromMs(ms) {
|
|
1319
|
+
try {
|
|
1320
|
+
const fmt = new Intl.DateTimeFormat("en-US", {
|
|
1321
|
+
weekday: "short",
|
|
1322
|
+
day: "2-digit",
|
|
1323
|
+
month: "short",
|
|
1324
|
+
year: "numeric",
|
|
1325
|
+
hour: "2-digit",
|
|
1326
|
+
minute: "2-digit",
|
|
1327
|
+
second: "2-digit",
|
|
1328
|
+
timeZone: "UTC",
|
|
1329
|
+
timeZoneName: "shortOffset",
|
|
1330
|
+
hour12: false
|
|
1331
|
+
});
|
|
1332
|
+
const parts = fmt.formatToParts(new Date(ms));
|
|
1333
|
+
const get = (t) => parts.find((p) => p.type === t)?.value ?? "";
|
|
1334
|
+
const tzRaw = get("timeZoneName");
|
|
1335
|
+
const tzMatch = tzRaw?.match(/GMT([+-])(\d+)(?::(\d+))?/);
|
|
1336
|
+
let tz;
|
|
1337
|
+
if (tzMatch) {
|
|
1338
|
+
const sign = tzMatch[1];
|
|
1339
|
+
const hours = tzMatch[2].padStart(2, "0");
|
|
1340
|
+
const minutes = (tzMatch[3] ?? "0").padStart(2, "0");
|
|
1341
|
+
tz = `${sign}${hours}${minutes}`;
|
|
1342
|
+
/* c8 ignore start @preserve -- timeZone is hardcoded to 'UTC' above,
|
|
1343
|
+
which always resolves cleanly, so shortOffset always returns a
|
|
1344
|
+
parseable "GMT+0"-shaped string in this environment's ICU. This
|
|
1345
|
+
branch only guards against an ICU build whose shortOffset output
|
|
1346
|
+
doesn't match the regex; can't trigger it without mocking Intl.
|
|
1347
|
+
The ignore starts before the closing brace of the if-block so it
|
|
1348
|
+
covers the whole else-branch node c8 tracks as a single unit. */
|
|
727
1349
|
} else {
|
|
728
|
-
|
|
1350
|
+
tz = "+0000";
|
|
729
1351
|
}
|
|
1352
|
+
/* c8 ignore stop @preserve */
|
|
1353
|
+
let hour = get("hour");
|
|
1354
|
+
/* c8 ignore start @preserve -- hour12:false with a fixed UTC zone
|
|
1355
|
+
never yields "24" in this environment's ICU (midnight formats as
|
|
1356
|
+
"00"). Some ICU versions/locales are documented to emit "24" for
|
|
1357
|
+
hour12:false, so this stays as a defensive normalization; not
|
|
1358
|
+
reachable here without mocking Intl.DateTimeFormat's output. */
|
|
1359
|
+
if (hour === "24") hour = "00";
|
|
1360
|
+
/* c8 ignore stop @preserve */
|
|
1361
|
+
return `${get("weekday")}, ${get("day")} ${get("month")} ${get("year")} ${hour}:${get("minute")}:${get("second")} ${tz}`;
|
|
1362
|
+
/* c8 ignore start @preserve -- Intl.DateTimeFormat is constructed
|
|
1363
|
+
above with a literal, always-valid timeZone: 'UTC' and no other
|
|
1364
|
+
user input reaches the constructor or formatToParts call, so this
|
|
1365
|
+
catch can't be triggered through the public API in a normal Intl
|
|
1366
|
+
environment (e.g. Node with full-icu). Kept as a genuine fallback
|
|
1367
|
+
for runtimes with a broken or absent Intl implementation. */
|
|
1368
|
+
} catch {
|
|
1369
|
+
const d = new Date(ms);
|
|
1370
|
+
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
1371
|
+
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
1372
|
+
const wd = days[d.getUTCDay()];
|
|
1373
|
+
const dd = String(d.getUTCDate()).padStart(2, "0");
|
|
1374
|
+
const mon = months[d.getUTCMonth()];
|
|
1375
|
+
const yyyy = d.getUTCFullYear();
|
|
1376
|
+
const hh = String(d.getUTCHours()).padStart(2, "0");
|
|
1377
|
+
const mm = String(d.getUTCMinutes()).padStart(2, "0");
|
|
1378
|
+
const ss = String(d.getUTCSeconds()).padStart(2, "0");
|
|
1379
|
+
return `${wd}, ${dd} ${mon} ${yyyy} ${hh}:${mm}:${ss} +0000`;
|
|
730
1380
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
1381
|
+
/* c8 ignore stop @preserve */
|
|
1382
|
+
}
|
|
1383
|
+
function parseHTTPDate(input) {
|
|
1384
|
+
const trimmed = input.trim();
|
|
1385
|
+
const ms = Date.parse(trimmed);
|
|
1386
|
+
if (Number.isNaN(ms)) {
|
|
1387
|
+
throw new FormatSyntaxError({ input, reason: "not a valid HTTP-date" });
|
|
1388
|
+
}
|
|
1389
|
+
return requireInstant().fromEpochMilliseconds(ms);
|
|
1390
|
+
}
|
|
1391
|
+
function formatHTTPDate(value) {
|
|
1392
|
+
const instant = value?.toInstant?.() ?? value;
|
|
1393
|
+
const ms = typeof instant === "object" && instant !== null && "epochMilliseconds" in instant ? instant.epochMilliseconds : (() => {
|
|
1394
|
+
throw new FormatSyntaxError({ reason: `formatHTTPDate() expects an Instant or ZonedDateTime, got ${typeof value}.` });
|
|
1395
|
+
})();
|
|
1396
|
+
const d = new Date(ms);
|
|
1397
|
+
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
1398
|
+
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
1399
|
+
const wd = days[d.getUTCDay()];
|
|
1400
|
+
const dd = String(d.getUTCDate()).padStart(2, "0");
|
|
1401
|
+
const mon = months[d.getUTCMonth()];
|
|
1402
|
+
const yyyy = d.getUTCFullYear();
|
|
1403
|
+
const hh = String(d.getUTCHours()).padStart(2, "0");
|
|
1404
|
+
const mm = String(d.getUTCMinutes()).padStart(2, "0");
|
|
1405
|
+
const ss = String(d.getUTCSeconds()).padStart(2, "0");
|
|
1406
|
+
return `${wd}, ${dd} ${mon} ${yyyy} ${hh}:${mm}:${ss} GMT`;
|
|
1407
|
+
}
|
|
1408
|
+
function getInstant(value) {
|
|
1409
|
+
const v = value;
|
|
1410
|
+
if (typeof v?.toInstant === "function") {
|
|
1411
|
+
const inst = v.toInstant();
|
|
1412
|
+
if (typeof inst.epochNanoseconds === "bigint") {
|
|
1413
|
+
return { epochMilliseconds: inst.epochMilliseconds, epochNanoseconds: inst.epochNanoseconds };
|
|
1414
|
+
}
|
|
1415
|
+
return { epochMilliseconds: inst.epochMilliseconds, epochNanoseconds: BigInt(inst.epochMilliseconds) * 1000000n };
|
|
1416
|
+
}
|
|
1417
|
+
if (typeof v?.epochNanoseconds === "bigint") {
|
|
1418
|
+
return { epochMilliseconds: Number(v.epochNanoseconds / 1000000n), epochNanoseconds: v.epochNanoseconds };
|
|
1419
|
+
}
|
|
1420
|
+
if (typeof v?.epochMilliseconds === "number") {
|
|
1421
|
+
return { epochMilliseconds: v.epochMilliseconds, epochNanoseconds: BigInt(v.epochMilliseconds) * 1000000n };
|
|
1422
|
+
}
|
|
1423
|
+
throw new FormatSyntaxError({ reason: `expected an Instant or ZonedDateTime, got ${typeof value}.` });
|
|
1424
|
+
}
|
|
1425
|
+
function requireInstant() {
|
|
1426
|
+
const t = getTemporal().Instant;
|
|
1427
|
+
if (!t) throw new Error("temporal-fmt: Temporal.Instant is not available in this implementation.");
|
|
1428
|
+
return t;
|
|
1429
|
+
}
|
|
1430
|
+
function toUnixSeconds(value) {
|
|
1431
|
+
return getInstant(value).epochMilliseconds / 1e3;
|
|
1432
|
+
}
|
|
1433
|
+
function fromUnixSeconds(seconds) {
|
|
1434
|
+
return requireInstant().fromEpochMilliseconds(seconds * 1e3);
|
|
1435
|
+
}
|
|
1436
|
+
function fromUnixMilliseconds(ms) {
|
|
1437
|
+
return requireInstant().fromEpochMilliseconds(ms);
|
|
1438
|
+
}
|
|
1439
|
+
function fromUnixMicroseconds(\u00B5s) {
|
|
1440
|
+
return requireInstant().fromEpochNanoseconds(BigInt(\u00B5s) * 1000n);
|
|
1441
|
+
}
|
|
1442
|
+
function fromUnixNanoseconds(ns) {
|
|
1443
|
+
return requireInstant().fromEpochNanoseconds(ns);
|
|
1444
|
+
}
|
|
1445
|
+
function toUnixMilliseconds(value) {
|
|
1446
|
+
return getInstant(value).epochMilliseconds;
|
|
1447
|
+
}
|
|
1448
|
+
function toUnixMicroseconds(value) {
|
|
1449
|
+
const { epochNanoseconds } = getInstant(value);
|
|
1450
|
+
return Number(epochNanoseconds / 1000n);
|
|
1451
|
+
}
|
|
1452
|
+
function toUnixNanoseconds(value) {
|
|
1453
|
+
return getInstant(value).epochNanoseconds;
|
|
1454
|
+
}
|
|
1455
|
+
function parseSQL(input) {
|
|
1456
|
+
const trimmed = input.trim();
|
|
1457
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(trimmed)) {
|
|
1458
|
+
return parse("yyyy-MM-dd", trimmed);
|
|
1459
|
+
}
|
|
1460
|
+
if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(trimmed)) {
|
|
1461
|
+
return parse("yyyy-MM-dd HH:mm:ss", trimmed);
|
|
1462
|
+
}
|
|
1463
|
+
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(trimmed)) {
|
|
1464
|
+
return parseISO(trimmed);
|
|
1465
|
+
}
|
|
1466
|
+
throw new FormatSyntaxError({ input, reason: "not a recognized SQL date/time format" });
|
|
1467
|
+
}
|
|
1468
|
+
function formatSQL(value) {
|
|
1469
|
+
const v = value;
|
|
1470
|
+
if (typeof v?.hour === "number") {
|
|
1471
|
+
return format(value, "yyyy-MM-dd HH:mm:ss");
|
|
1472
|
+
}
|
|
1473
|
+
return format(value, "yyyy-MM-dd");
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
// src/relativeGrammar.ts
|
|
1477
|
+
var MAX_REGISTERED_GRAMMARS = 100;
|
|
1478
|
+
var registeredGrammars = [];
|
|
1479
|
+
function registerRelativeGrammar(grammar) {
|
|
1480
|
+
if (typeof grammar.language !== "string" || grammar.language.length === 0) {
|
|
1481
|
+
throw new Error("temporal-fmt: registerRelativeGrammar requires a non-empty language string.");
|
|
1482
|
+
}
|
|
1483
|
+
if (grammar.language.length > 35) {
|
|
1484
|
+
throw new RangeError(`temporal-fmt: registerRelativeGrammar language tags must be at most 35 characters (got ${grammar.language.length}).`);
|
|
1485
|
+
}
|
|
1486
|
+
if (!Array.isArray(grammar.matchers) || grammar.matchers.length === 0) {
|
|
1487
|
+
throw new Error("temporal-fmt: registerRelativeGrammar requires at least one matcher.");
|
|
1488
|
+
}
|
|
1489
|
+
if (grammar.matchers.length > 1e3) {
|
|
1490
|
+
throw new RangeError(`temporal-fmt: registerRelativeGrammar accepts at most 1000 matchers (got ${grammar.matchers.length}).`);
|
|
1491
|
+
}
|
|
1492
|
+
if (!grammar.matchers.every((m) => typeof m === "function")) {
|
|
1493
|
+
throw new Error("temporal-fmt: registerRelativeGrammar matchers must all be functions.");
|
|
1494
|
+
}
|
|
1495
|
+
const existingIdx = registeredGrammars.findIndex((g) => g.language === grammar.language);
|
|
1496
|
+
if (existingIdx >= 0) {
|
|
1497
|
+
registeredGrammars[existingIdx] = grammar;
|
|
1498
|
+
} else {
|
|
1499
|
+
if (registeredGrammars.length >= MAX_REGISTERED_GRAMMARS) {
|
|
1500
|
+
throw new RangeError(`temporal-fmt: registerRelativeGrammar reached the ${MAX_REGISTERED_GRAMMARS}-grammar limit.`);
|
|
1501
|
+
}
|
|
1502
|
+
registeredGrammars.push(grammar);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
function tryRegisteredGrammar(language, input, reference) {
|
|
1506
|
+
for (const grammar of registeredGrammars) {
|
|
1507
|
+
if (grammar.language !== language) continue;
|
|
1508
|
+
for (const matcher of grammar.matchers) {
|
|
1509
|
+
let match;
|
|
1510
|
+
try {
|
|
1511
|
+
match = matcher(input);
|
|
1512
|
+
} catch {
|
|
1513
|
+
continue;
|
|
1514
|
+
}
|
|
1515
|
+
if (match === null) continue;
|
|
1516
|
+
const temporal = getTemporal();
|
|
1517
|
+
if (match.resolve) {
|
|
1518
|
+
const fields = match.resolve(reference);
|
|
1519
|
+
return temporal.PlainDate.from(fields, { overflow: "reject" });
|
|
1520
|
+
}
|
|
1521
|
+
return temporal.PlainDate.from(
|
|
1522
|
+
{ year: match.year ?? reference.year, month: match.month ?? reference.month, day: match.day ?? reference.day },
|
|
1523
|
+
{ overflow: "reject" }
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
return null;
|
|
1528
|
+
}
|
|
1529
|
+
function listRegisteredGrammars() {
|
|
1530
|
+
return registeredGrammars.map((g) => g.language);
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
// src/parseRelative.ts
|
|
1534
|
+
function normalizeForMatch(s) {
|
|
1535
|
+
return s.toLowerCase().replace(/ä/g, "ae").replace(/ö/g, "oe").replace(/ü/g, "ue").replace(/ß/g, "ss").normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
1536
|
+
}
|
|
1537
|
+
function levenshtein(a, b) {
|
|
1538
|
+
/* c8 ignore start @preserve -- unreachable through the only call
|
|
1539
|
+
* site (fuzzyCorrectEnglish): `a` is always a word that already
|
|
1540
|
+
* failed the `vocabulary.includes(word)` exact-match check, so
|
|
1541
|
+
* a === b never holds against any `b` drawn from that same
|
|
1542
|
+
* vocabulary; and neither `a` (split from a non-empty normalized
|
|
1543
|
+
* string) nor `b` (a vocabulary entry) is ever empty. Kept as
|
|
1544
|
+
* general-purpose guards in case levenshtein() gets a second caller
|
|
1545
|
+
* later. */
|
|
1546
|
+
if (a === b) return 0;
|
|
1547
|
+
if (a.length === 0) return b.length;
|
|
1548
|
+
if (b.length === 0) return a.length;
|
|
1549
|
+
/* c8 ignore stop @preserve */
|
|
1550
|
+
let prev = new Array(b.length + 1);
|
|
1551
|
+
let curr = new Array(b.length + 1);
|
|
1552
|
+
for (let j = 0; j <= b.length; j++) prev[j] = j;
|
|
1553
|
+
for (let i = 1; i <= a.length; i++) {
|
|
1554
|
+
curr[0] = i;
|
|
1555
|
+
for (let j = 1; j <= b.length; j++) {
|
|
1556
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
1557
|
+
curr[j] = Math.min(
|
|
1558
|
+
prev[j] + 1,
|
|
1559
|
+
// deletion
|
|
1560
|
+
curr[j - 1] + 1,
|
|
1561
|
+
// insertion
|
|
1562
|
+
prev[j - 1] + cost
|
|
1563
|
+
// substitution
|
|
1564
|
+
);
|
|
1565
|
+
}
|
|
1566
|
+
[prev, curr] = [curr, prev];
|
|
1567
|
+
}
|
|
1568
|
+
return prev[b.length];
|
|
1569
|
+
}
|
|
1570
|
+
var FUZZY_MAX_DISTANCE = 2;
|
|
1571
|
+
var MAX_RELATIVE_INPUT_LENGTH = 4096;
|
|
1572
|
+
var MAX_RELATIVE_WORDS = 32;
|
|
1573
|
+
function buildEnglishFuzzyVocabulary() {
|
|
1574
|
+
return [
|
|
1575
|
+
...ENGLISH_WEEKDAYS,
|
|
1576
|
+
...ENGLISH_MONTHS,
|
|
1577
|
+
...ENGLISH_MONTH_SHORT,
|
|
1578
|
+
"today",
|
|
1579
|
+
"tomorrow",
|
|
1580
|
+
"yesterday",
|
|
1581
|
+
"next",
|
|
1582
|
+
"last",
|
|
1583
|
+
"this",
|
|
1584
|
+
"in",
|
|
1585
|
+
"ago",
|
|
1586
|
+
"day",
|
|
1587
|
+
"days",
|
|
1588
|
+
"week",
|
|
1589
|
+
"weeks",
|
|
1590
|
+
"month",
|
|
1591
|
+
"months",
|
|
1592
|
+
"year",
|
|
1593
|
+
"years"
|
|
1594
|
+
].map(normalizeForMatch);
|
|
1595
|
+
}
|
|
1596
|
+
var englishFuzzyVocabulary;
|
|
1597
|
+
function getEnglishFuzzyVocabulary() {
|
|
1598
|
+
if (!englishFuzzyVocabulary) englishFuzzyVocabulary = Object.freeze(buildEnglishFuzzyVocabulary());
|
|
1599
|
+
return englishFuzzyVocabulary;
|
|
1600
|
+
}
|
|
1601
|
+
function fuzzyCorrectEnglish(normalized) {
|
|
1602
|
+
const vocabulary = getEnglishFuzzyVocabulary();
|
|
1603
|
+
const words = normalized.split(" ");
|
|
1604
|
+
if (normalized.length > MAX_RELATIVE_INPUT_LENGTH || words.length > MAX_RELATIVE_WORDS) {
|
|
1605
|
+
throw new RangeError(
|
|
1606
|
+
`temporal-fmt: parseRelative fuzzy input is too large (maximum ${MAX_RELATIVE_INPUT_LENGTH} characters and ${MAX_RELATIVE_WORDS} words).`
|
|
1607
|
+
);
|
|
1608
|
+
}
|
|
1609
|
+
let changed = false;
|
|
1610
|
+
const corrected = words.map((word) => {
|
|
1611
|
+
if (/^\d+(?:st|nd|rd|th)?$/.test(word)) return word;
|
|
1612
|
+
if (vocabulary.includes(word)) return word;
|
|
1613
|
+
let best;
|
|
1614
|
+
let bestDist = FUZZY_MAX_DISTANCE + 1;
|
|
1615
|
+
for (const candidate of vocabulary) {
|
|
1616
|
+
const dist = levenshtein(word, candidate);
|
|
1617
|
+
if (dist < bestDist) {
|
|
1618
|
+
bestDist = dist;
|
|
1619
|
+
best = candidate;
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
if (best !== void 0 && bestDist <= FUZZY_MAX_DISTANCE) {
|
|
1623
|
+
changed = true;
|
|
1624
|
+
return best;
|
|
1625
|
+
}
|
|
1626
|
+
return word;
|
|
1627
|
+
});
|
|
1628
|
+
return changed ? corrected.join(" ") : void 0;
|
|
1629
|
+
}
|
|
1630
|
+
function readYear(reference) {
|
|
1631
|
+
if (typeof reference.year !== "number") {
|
|
1632
|
+
throw new Error("temporal-fmt: parseRelative reference date is missing year.");
|
|
1633
|
+
}
|
|
1634
|
+
return reference.year;
|
|
1635
|
+
}
|
|
1636
|
+
function readMonth(reference) {
|
|
1637
|
+
if (typeof reference.month !== "number") {
|
|
1638
|
+
throw new Error("temporal-fmt: parseRelative reference date is missing month.");
|
|
1639
|
+
}
|
|
1640
|
+
return reference.month;
|
|
1641
|
+
}
|
|
1642
|
+
function readDay(reference) {
|
|
1643
|
+
if (typeof reference.day !== "number") {
|
|
1644
|
+
throw new Error("temporal-fmt: parseRelative reference date is missing day.");
|
|
1645
|
+
}
|
|
1646
|
+
return reference.day;
|
|
1647
|
+
}
|
|
1648
|
+
function extractDayOfWeek(reference) {
|
|
1649
|
+
const dow = reference.dayOfWeek;
|
|
1650
|
+
if (typeof dow !== "number") {
|
|
1651
|
+
throw new Error(
|
|
1652
|
+
"temporal-fmt: parseRelative needs a reference date exposing dayOfWeek (a Temporal.PlainDate / PlainDateTime / ZonedDateTime)."
|
|
1653
|
+
);
|
|
1654
|
+
}
|
|
1655
|
+
return dow;
|
|
1656
|
+
}
|
|
1657
|
+
function nameAlternation(names) {
|
|
1658
|
+
const normalized = names.map(normalizeForMatch);
|
|
1659
|
+
const sorted = [...normalized].sort((a, b) => b.length - a.length);
|
|
1660
|
+
return sorted.map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
1661
|
+
}
|
|
1662
|
+
function buildPlainDate(temporal, year, month, day) {
|
|
1663
|
+
return temporal.PlainDate.from({ year, month, day }, { overflow: "reject" });
|
|
1664
|
+
}
|
|
1665
|
+
function addDays2(temporal, reference, days) {
|
|
1666
|
+
const refDate = temporal.PlainDate.from({
|
|
1667
|
+
year: readYear(reference),
|
|
1668
|
+
month: readMonth(reference),
|
|
1669
|
+
day: readDay(reference)
|
|
1670
|
+
});
|
|
1671
|
+
return refDate.add({ days });
|
|
1672
|
+
}
|
|
1673
|
+
function addUnits(temporal, reference, count, unit) {
|
|
1674
|
+
const refDate = temporal.PlainDate.from({
|
|
1675
|
+
year: readYear(reference),
|
|
1676
|
+
month: readMonth(reference),
|
|
1677
|
+
day: readDay(reference)
|
|
1678
|
+
});
|
|
1679
|
+
const duration = {};
|
|
1680
|
+
if (unit === "day") duration.days = count;
|
|
1681
|
+
if (unit === "week") duration.weeks = count;
|
|
1682
|
+
if (unit === "month") duration.months = count;
|
|
1683
|
+
if (unit === "year") duration.years = count;
|
|
1684
|
+
return refDate.add(duration);
|
|
1685
|
+
}
|
|
1686
|
+
function weekdayOffset(rel, refDow, targetDow) {
|
|
1687
|
+
if (rel === "next") {
|
|
1688
|
+
let diff = targetDow - refDow;
|
|
1689
|
+
if (diff <= 0) diff += 7;
|
|
1690
|
+
return diff;
|
|
1691
|
+
}
|
|
1692
|
+
if (rel === "last") {
|
|
1693
|
+
let diff = targetDow - refDow;
|
|
1694
|
+
if (diff >= 0) diff -= 7;
|
|
1695
|
+
return diff;
|
|
1696
|
+
}
|
|
1697
|
+
return targetDow - refDow;
|
|
1698
|
+
}
|
|
1699
|
+
function resolveToNextOccurrence(temporal, reference, month, day) {
|
|
1700
|
+
const refYear = readYear(reference);
|
|
1701
|
+
const refDate = temporal.PlainDate.from({
|
|
1702
|
+
year: refYear,
|
|
1703
|
+
month: readMonth(reference),
|
|
1704
|
+
day: readDay(reference)
|
|
1705
|
+
});
|
|
1706
|
+
if (!temporal.PlainDate.compare) {
|
|
1707
|
+
throw new Error("temporal-fmt: parseRelative needs Temporal.PlainDate.compare to resolve month-day phrases; the active implementation does not expose it.");
|
|
1708
|
+
}
|
|
1709
|
+
try {
|
|
1710
|
+
const thisYear = temporal.PlainDate.from({ year: refYear, month, day }, { overflow: "reject" });
|
|
1711
|
+
if (temporal.PlainDate.compare(thisYear, refDate) >= 0) {
|
|
1712
|
+
return thisYear;
|
|
1713
|
+
}
|
|
1714
|
+
return temporal.PlainDate.from({ year: refYear + 1, month, day }, { overflow: "reject" });
|
|
1715
|
+
} catch (err) {
|
|
1716
|
+
try {
|
|
1717
|
+
return temporal.PlainDate.from({ year: refYear + 1, month, day }, { overflow: "reject" });
|
|
1718
|
+
} catch {
|
|
1719
|
+
throw new Error(
|
|
1720
|
+
`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}`
|
|
1721
|
+
);
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
function weekdayIndexFromName(name, names) {
|
|
1726
|
+
const normalized = normalizeForMatch(name);
|
|
1727
|
+
const idx = names.findIndex((n) => normalizeForMatch(n) === normalized);
|
|
1728
|
+
/* c8 ignore start @preserve -- unreachable: every caller passes a
|
|
1729
|
+
* name captured by nameAlternation(names), which builds its regex
|
|
1730
|
+
* alternation from this same list under the same normalizeForMatch
|
|
1731
|
+
* transform. The regex can't match anything findIndex() wouldn't
|
|
1732
|
+
* also find here. Defensive throw kept for the type checker and as
|
|
1733
|
+
* a tripwire if that invariant ever breaks. Ignore comment sits on
|
|
1734
|
+
* the `if` itself, not just the throw inside it — c8 tracks the
|
|
1735
|
+
* branch outcome (was the true side ever taken) separately from the
|
|
1736
|
+
* statements inside, so excluding only the inner throw still leaves
|
|
1737
|
+
* the branch itself flagged as uncovered. */
|
|
1738
|
+
if (idx < 0) {
|
|
1739
|
+
throw new Error(`temporal-fmt: parseRelative internal error \u2014 weekday "${name}" not in names list.`);
|
|
1740
|
+
}
|
|
1741
|
+
/* c8 ignore stop @preserve */
|
|
1742
|
+
return idx + 1;
|
|
1743
|
+
}
|
|
1744
|
+
function monthIndexFromName(name, longNames, shortNames = []) {
|
|
1745
|
+
const normalized = normalizeForMatch(name);
|
|
1746
|
+
const longIdx = longNames.findIndex((n) => normalizeForMatch(n) === normalized);
|
|
1747
|
+
if (longIdx >= 0) return longIdx + 1;
|
|
1748
|
+
const shortIdx = shortNames.findIndex((n) => normalizeForMatch(n) === normalized);
|
|
1749
|
+
if (shortIdx >= 0) return shortIdx + 1;
|
|
1750
|
+
/* c8 ignore start @preserve -- unreachable: every caller passes a name
|
|
1751
|
+
* captured by nameAlternation([...longNames, ...shortNames]), so the
|
|
1752
|
+
* regex alternation and these two findIndex() scans are built from
|
|
1753
|
+
* the same lists under the same normalizeForMatch transform. Kept as
|
|
1754
|
+
* a tripwire for the type checker in case that invariant ever breaks. */
|
|
1755
|
+
throw new Error(`temporal-fmt: parseRelative internal error \u2014 month "${name}" not in names list.`);
|
|
1756
|
+
/* c8 ignore stop @preserve */
|
|
1757
|
+
}
|
|
1758
|
+
var ENGLISH_WEEKDAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
|
1759
|
+
var ENGLISH_MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
1760
|
+
var ENGLISH_MONTH_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
1761
|
+
var ENGLISH_GRAMMAR = {
|
|
1762
|
+
supportedHint: 'Supported: weekday refs ("next Tuesday"), day offsets ("today"/"tomorrow"/"yesterday"), unit offsets ("in 3 days", "2 weeks ago"), and month-day ("March 5th").',
|
|
1763
|
+
matchers: [
|
|
1764
|
+
// today / tomorrow / yesterday — exact match, most rigid shape.
|
|
1765
|
+
// Checked first because they're the most common phrase class.
|
|
1766
|
+
{
|
|
1767
|
+
pattern: /^today$/i,
|
|
1768
|
+
resolve: (_m, ctx) => buildPlainDate(ctx.temporal, readYear(ctx.reference), readMonth(ctx.reference), readDay(ctx.reference))
|
|
1769
|
+
},
|
|
1770
|
+
{
|
|
1771
|
+
pattern: /^tomorrow$/i,
|
|
1772
|
+
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, 1)
|
|
1773
|
+
},
|
|
1774
|
+
{
|
|
1775
|
+
pattern: /^yesterday$/i,
|
|
1776
|
+
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, -1)
|
|
1777
|
+
},
|
|
1778
|
+
// weekday references: "next/last/this Tuesday". Capture the relative
|
|
1779
|
+
// word and the weekday name separately, then resolve via +7 / -7.
|
|
1780
|
+
{
|
|
1781
|
+
pattern: new RegExp(`^(next|last|this)\\s+(${nameAlternation(ENGLISH_WEEKDAYS)})$`, "i"),
|
|
1782
|
+
resolve: (m, ctx) => {
|
|
1783
|
+
const rel = m[1].toLowerCase();
|
|
1784
|
+
const targetDow = weekdayIndexFromName(m[2], ENGLISH_WEEKDAYS);
|
|
1785
|
+
const refDow = extractDayOfWeek(ctx.reference);
|
|
1786
|
+
return addDays2(ctx.temporal, ctx.reference, weekdayOffset(rel, refDow, targetDow));
|
|
1787
|
+
}
|
|
1788
|
+
},
|
|
1789
|
+
// unit offsets: "in 3 days", "2 weeks ago", "in 1 month", "1 year ago".
|
|
1790
|
+
// Two shapes share this matcher — leading "in" (future) or trailing
|
|
1791
|
+
// "ago" (past). Both lead with <number> <unit>.
|
|
1792
|
+
{
|
|
1793
|
+
pattern: /^(in\s+)?(\d+)\s+(day|week|month|year)s?(?:\s+ago)?$/i,
|
|
1794
|
+
resolve: (m, ctx) => {
|
|
1795
|
+
const inPrefix = m[1];
|
|
1796
|
+
const count = m[2];
|
|
1797
|
+
const unitName = m[3].toLowerCase();
|
|
1798
|
+
const hasIn = !!inPrefix;
|
|
1799
|
+
const hasAgo = /\bago\b/i.test(m[0]);
|
|
1800
|
+
if (!hasIn && !hasAgo) {
|
|
1801
|
+
throw new Error(
|
|
1802
|
+
`temporal-fmt: parseRelative can't tell whether "${m[0]}" is past or future \u2014 use "in ${count} ${unitName}s" or "${count} ${unitName}s ago".`
|
|
1803
|
+
);
|
|
1804
|
+
}
|
|
1805
|
+
if (hasIn && hasAgo) {
|
|
1806
|
+
throw new Error(
|
|
1807
|
+
`temporal-fmt: parseRelative got contradictory direction markers in "${m[0]}" \u2014 "in N ${unitName}s" is future and "N ${unitName}s ago" is past; use one or the other.`
|
|
1808
|
+
);
|
|
1809
|
+
}
|
|
1810
|
+
const sign = hasIn ? 1 : -1;
|
|
1811
|
+
return addUnits(ctx.temporal, ctx.reference, sign * Number(count), unitName);
|
|
1812
|
+
}
|
|
1813
|
+
},
|
|
1814
|
+
// month-day without year, e.g. "March 5th", "March 5", "March 5, 2026"
|
|
1815
|
+
// (year is ignored if present). The ordinal suffix is decorative —
|
|
1816
|
+
// strip it. The day-of-month is a 1- or 2-digit number.
|
|
1817
|
+
{
|
|
1818
|
+
pattern: new RegExp(`^(${nameAlternation([...ENGLISH_MONTHS, ...ENGLISH_MONTH_SHORT])})\\s+(\\d{1,2})(?:st|nd|rd|th)?(?:,?\\s*(\\d{4}))?$`, "i"),
|
|
1819
|
+
resolve: (m, ctx) => {
|
|
1820
|
+
const month = monthIndexFromName(m[1], ENGLISH_MONTHS, ENGLISH_MONTH_SHORT);
|
|
1821
|
+
const day = Number(m[2]);
|
|
1822
|
+
return resolveToNextOccurrence(ctx.temporal, ctx.reference, month, day);
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
]
|
|
1826
|
+
};
|
|
1827
|
+
var SPANISH_WEEKDAYS = ["lunes", "martes", "mi\xE9rcoles", "jueves", "viernes", "s\xE1bado", "domingo"];
|
|
1828
|
+
var SPANISH_MONTHS = ["enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"];
|
|
1829
|
+
var SPANISH_MONTH_SHORT = ["ene", "feb", "mar", "abr", "may", "jun", "jul", "ago", "sept", "oct", "nov", "dic"];
|
|
1830
|
+
var SPANISH_GRAMMAR = {
|
|
1831
|
+
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").',
|
|
1832
|
+
matchers: [
|
|
1833
|
+
{
|
|
1834
|
+
pattern: /^hoy$/i,
|
|
1835
|
+
resolve: (_m, ctx) => buildPlainDate(ctx.temporal, readYear(ctx.reference), readMonth(ctx.reference), readDay(ctx.reference))
|
|
1836
|
+
},
|
|
1837
|
+
{
|
|
1838
|
+
pattern: /^ma[ñn]ana$/i,
|
|
1839
|
+
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, 1)
|
|
1840
|
+
},
|
|
1841
|
+
{
|
|
1842
|
+
pattern: /^ayer$/i,
|
|
1843
|
+
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, -1)
|
|
1844
|
+
},
|
|
1845
|
+
// weekday references. Spanish has three common shapes, all meaning
|
|
1846
|
+
// the same thing per rel word:
|
|
1847
|
+
// "el próximo lunes" / "próximo lunes" → next
|
|
1848
|
+
// "el lunes próximo" → next (suffix variant)
|
|
1849
|
+
// "el lunes pasado" / "lunes pasado" → last
|
|
1850
|
+
// "este lunes" → this
|
|
1851
|
+
// Capture the rel word from whichever shape matched, then resolve
|
|
1852
|
+
// the same way English does.
|
|
1853
|
+
{
|
|
1854
|
+
pattern: new RegExp(
|
|
1855
|
+
`^(?: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)}))$`,
|
|
1856
|
+
"i"
|
|
1857
|
+
),
|
|
1858
|
+
resolve: (m, ctx) => {
|
|
1859
|
+
let relWord;
|
|
1860
|
+
let weekdayName;
|
|
1861
|
+
if (m[1] && m[2]) {
|
|
1862
|
+
relWord = m[1];
|
|
1863
|
+
weekdayName = m[2];
|
|
1864
|
+
} else if (m[3] && m[4]) {
|
|
1865
|
+
weekdayName = m[3];
|
|
1866
|
+
relWord = m[4];
|
|
1867
|
+
} else {
|
|
1868
|
+
relWord = "este";
|
|
1869
|
+
weekdayName = m[5];
|
|
1870
|
+
}
|
|
1871
|
+
const rel = normalizeForMatch(relWord) === "proximo" ? "next" : relWord.toLowerCase() === "este" ? "this" : "last";
|
|
1872
|
+
const targetDow = weekdayIndexFromName(weekdayName, SPANISH_WEEKDAYS);
|
|
1873
|
+
const refDow = extractDayOfWeek(ctx.reference);
|
|
1874
|
+
return addDays2(ctx.temporal, ctx.reference, weekdayOffset(rel, refDow, targetDow));
|
|
1875
|
+
}
|
|
1876
|
+
},
|
|
1877
|
+
// unit offsets. Spanish uses distinct markers:
|
|
1878
|
+
// "en 3 días" / "dentro de 3 días" → future
|
|
1879
|
+
// "hace 2 semanas" → past
|
|
1880
|
+
// Both shapes lead with the marker, unlike English where one
|
|
1881
|
+
// shape leads and the other trails.
|
|
1882
|
+
{
|
|
1883
|
+
pattern: new RegExp(
|
|
1884
|
+
`^(?:(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))$`,
|
|
1885
|
+
"i"
|
|
1886
|
+
),
|
|
1887
|
+
resolve: (m, ctx) => {
|
|
1888
|
+
let count;
|
|
1889
|
+
let unitWord;
|
|
1890
|
+
let sign;
|
|
1891
|
+
if (m[1] && m[2] && m[3]) {
|
|
1892
|
+
count = m[2];
|
|
1893
|
+
unitWord = m[3];
|
|
1894
|
+
sign = 1;
|
|
1895
|
+
} else {
|
|
1896
|
+
count = m[4];
|
|
1897
|
+
unitWord = m[5];
|
|
1898
|
+
sign = -1;
|
|
1899
|
+
}
|
|
1900
|
+
const unit = unitWordToEnglish(unitWord);
|
|
1901
|
+
return addUnits(ctx.temporal, ctx.reference, sign * Number(count), unit);
|
|
1902
|
+
}
|
|
1903
|
+
},
|
|
1904
|
+
// "hace 2 semanas" — the primary past-offset shape. Matcher kept
|
|
1905
|
+
// separate from the future "en/dentro de" matcher above because
|
|
1906
|
+
// Spanish word order differs between the two (marker-first for
|
|
1907
|
+
// past, marker-first for future too, but with different markers).
|
|
1908
|
+
{
|
|
1909
|
+
pattern: new RegExp(`^hace\\s+(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?$`, "i"),
|
|
1910
|
+
resolve: (m, ctx) => {
|
|
1911
|
+
const count = Number(m[1]);
|
|
1912
|
+
const unit = unitWordToEnglish(m[2]);
|
|
1913
|
+
return addUnits(ctx.temporal, ctx.reference, -count, unit);
|
|
1914
|
+
}
|
|
1915
|
+
},
|
|
1916
|
+
// bare "N <unit>" without "en" / "hace" — throw, since direction
|
|
1917
|
+
// is ambiguous. Matched AFTER the directional shapes so the
|
|
1918
|
+
// directional ones win when their marker is present.
|
|
1919
|
+
{
|
|
1920
|
+
pattern: new RegExp(`^(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?$`, "i"),
|
|
1921
|
+
resolve: (m, _ctx) => {
|
|
1922
|
+
throw new Error(
|
|
1923
|
+
`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".`
|
|
1924
|
+
);
|
|
1925
|
+
}
|
|
1926
|
+
},
|
|
1927
|
+
// month-day: "5 de marzo" (day first), "5 de marzo de 2026" (year
|
|
1928
|
+
// ignored if present). Day is 1-2 digits, with optional trailing
|
|
1929
|
+
// "." (rare in Spanish but tolerated).
|
|
1930
|
+
{
|
|
1931
|
+
pattern: new RegExp(
|
|
1932
|
+
`^(\\d{1,2})\\.?\\s+de\\s+(${nameAlternation([...SPANISH_MONTHS, ...SPANISH_MONTH_SHORT])})(?:\\s+de\\s+(\\d{4}))?$`,
|
|
1933
|
+
"i"
|
|
1934
|
+
),
|
|
1935
|
+
resolve: (m, ctx) => {
|
|
1936
|
+
const day = Number(m[1]);
|
|
1937
|
+
const month = monthIndexFromName(m[2], SPANISH_MONTHS, SPANISH_MONTH_SHORT);
|
|
1938
|
+
return resolveToNextOccurrence(ctx.temporal, ctx.reference, month, day);
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
]
|
|
1942
|
+
};
|
|
1943
|
+
var FRENCH_WEEKDAYS = ["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"];
|
|
1944
|
+
var FRENCH_MONTHS = ["janvier", "f\xE9vrier", "mars", "avril", "mai", "juin", "juillet", "ao\xFBt", "septembre", "octobre", "novembre", "d\xE9cembre"];
|
|
1945
|
+
var FRENCH_MONTH_SHORT = ["janv.", "f\xE9vr.", "mars", "avr.", "mai", "juin", "juil.", "ao\xFBt", "sept.", "oct.", "nov.", "d\xE9c."];
|
|
1946
|
+
var FRENCH_GRAMMAR = {
|
|
1947
|
+
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").`,
|
|
1948
|
+
matchers: [
|
|
1949
|
+
{
|
|
1950
|
+
pattern: /^aujourd'hui$/i,
|
|
1951
|
+
resolve: (_m, ctx) => buildPlainDate(ctx.temporal, readYear(ctx.reference), readMonth(ctx.reference), readDay(ctx.reference))
|
|
1952
|
+
},
|
|
1953
|
+
{
|
|
1954
|
+
pattern: /^demain$/i,
|
|
1955
|
+
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, 1)
|
|
1956
|
+
},
|
|
1957
|
+
{
|
|
1958
|
+
pattern: /^hier$/i,
|
|
1959
|
+
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, -1)
|
|
1960
|
+
},
|
|
1961
|
+
// weekday references: "lundi prochain" (next), "lundi dernier"
|
|
1962
|
+
// (last), "ce lundi" (this). The relative word follows the
|
|
1963
|
+
// weekday for next/last, precedes it for this.
|
|
1964
|
+
{
|
|
1965
|
+
pattern: new RegExp(
|
|
1966
|
+
`^(?:(${nameAlternation(FRENCH_WEEKDAYS)})\\s+(prochain|dernier)|ce\\s+(${nameAlternation(FRENCH_WEEKDAYS)}))$`,
|
|
1967
|
+
"i"
|
|
1968
|
+
),
|
|
1969
|
+
resolve: (m, ctx) => {
|
|
1970
|
+
let rel;
|
|
1971
|
+
let weekdayName;
|
|
1972
|
+
if (m[1] && m[2]) {
|
|
1973
|
+
weekdayName = m[1];
|
|
1974
|
+
rel = m[2].toLowerCase() === "prochain" ? "next" : "last";
|
|
1975
|
+
} else {
|
|
1976
|
+
rel = "this";
|
|
1977
|
+
weekdayName = m[3];
|
|
1978
|
+
}
|
|
1979
|
+
const targetDow = weekdayIndexFromName(weekdayName, FRENCH_WEEKDAYS);
|
|
1980
|
+
const refDow = extractDayOfWeek(ctx.reference);
|
|
1981
|
+
return addDays2(ctx.temporal, ctx.reference, weekdayOffset(rel, refDow, targetDow));
|
|
1982
|
+
}
|
|
1983
|
+
},
|
|
1984
|
+
// past: "il y a 2 semaines" — multi-word marker.
|
|
1985
|
+
{
|
|
1986
|
+
pattern: new RegExp(`^il\\s+y\\s+a\\s+(\\d+)\\s+(jour|semaine|mois|an|ann[e\xE9e]e)s?$`, "i"),
|
|
1987
|
+
resolve: (m, ctx) => {
|
|
1988
|
+
const count = Number(m[1]);
|
|
1989
|
+
const unit = unitWordToEnglish(m[2]);
|
|
1990
|
+
return addUnits(ctx.temporal, ctx.reference, -count, unit);
|
|
1991
|
+
}
|
|
1992
|
+
},
|
|
1993
|
+
// future: "dans 3 jours"
|
|
1994
|
+
{
|
|
1995
|
+
pattern: new RegExp(`^dans\\s+(\\d+)\\s+(jour|semaine|mois|an|ann[e\xE9e]e)s?$`, "i"),
|
|
1996
|
+
resolve: (m, ctx) => {
|
|
1997
|
+
const count = Number(m[1]);
|
|
1998
|
+
const unit = unitWordToEnglish(m[2]);
|
|
1999
|
+
return addUnits(ctx.temporal, ctx.reference, count, unit);
|
|
2000
|
+
}
|
|
2001
|
+
},
|
|
2002
|
+
// bare "N <unit>" without marker — throw.
|
|
2003
|
+
{
|
|
2004
|
+
pattern: new RegExp(`^(\\d+)\\s+(jour|semaine|mois|an|ann[e\xE9e]e)s?$`, "i"),
|
|
2005
|
+
resolve: (m, _ctx) => {
|
|
2006
|
+
throw new Error(
|
|
2007
|
+
`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".`
|
|
2008
|
+
);
|
|
2009
|
+
}
|
|
2010
|
+
},
|
|
2011
|
+
// month-day: "5 mars" (day first, no separator word). Year ignored.
|
|
2012
|
+
{
|
|
2013
|
+
pattern: new RegExp(
|
|
2014
|
+
`^(\\d{1,2})\\s+(${nameAlternation([...FRENCH_MONTHS, ...FRENCH_MONTH_SHORT])})(?:\\s+(\\d{4}))?$`,
|
|
2015
|
+
"i"
|
|
2016
|
+
),
|
|
2017
|
+
resolve: (m, ctx) => {
|
|
2018
|
+
const day = Number(m[1]);
|
|
2019
|
+
const month = monthIndexFromName(m[2], FRENCH_MONTHS, FRENCH_MONTH_SHORT);
|
|
2020
|
+
return resolveToNextOccurrence(ctx.temporal, ctx.reference, month, day);
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
]
|
|
2024
|
+
};
|
|
2025
|
+
var GERMAN_WEEKDAYS = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"];
|
|
2026
|
+
var GERMAN_MONTHS = ["Januar", "Februar", "M\xE4rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"];
|
|
2027
|
+
var GERMAN_MONTH_SHORT = ["Jan", "Feb", "M\xE4r", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"];
|
|
2028
|
+
var GERMAN_GRAMMAR = {
|
|
2029
|
+
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").',
|
|
2030
|
+
matchers: [
|
|
2031
|
+
{
|
|
2032
|
+
pattern: /^heute$/i,
|
|
2033
|
+
resolve: (_m, ctx) => buildPlainDate(ctx.temporal, readYear(ctx.reference), readMonth(ctx.reference), readDay(ctx.reference))
|
|
2034
|
+
},
|
|
2035
|
+
{
|
|
2036
|
+
pattern: /^morgen$/i,
|
|
2037
|
+
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, 1)
|
|
2038
|
+
},
|
|
2039
|
+
{
|
|
2040
|
+
pattern: /^gestern$/i,
|
|
2041
|
+
resolve: (_m, ctx) => addDays2(ctx.temporal, ctx.reference, -1)
|
|
2042
|
+
},
|
|
2043
|
+
// weekday references: "nächsten Dienstag" (next), "letzten
|
|
2044
|
+
// Dienstag" (last), "diesen Dienstag" (this). Adjective precedes
|
|
2045
|
+
// the weekday; case varies (nächsten/letzten/diesen all take the
|
|
2046
|
+
// weak-declension -en/-en/-en ending when no article, which is
|
|
2047
|
+
// convenient — one regex alternation covers all three.
|
|
2048
|
+
{
|
|
2049
|
+
pattern: new RegExp(`^(n(?:ae|a|\xE4)chsten|letzten|diesen)\\s+(${nameAlternation(GERMAN_WEEKDAYS)})$`, "i"),
|
|
2050
|
+
resolve: (m, ctx) => {
|
|
2051
|
+
const adj = normalizeForMatch(m[1]);
|
|
2052
|
+
const rel = adj === "nachsten" || adj === "naechsten" ? "next" : adj === "diesen" ? "this" : "last";
|
|
2053
|
+
const targetDow = weekdayIndexFromName(m[2], GERMAN_WEEKDAYS);
|
|
2054
|
+
const refDow = extractDayOfWeek(ctx.reference);
|
|
2055
|
+
return addDays2(ctx.temporal, ctx.reference, weekdayOffset(rel, refDow, targetDow));
|
|
2056
|
+
}
|
|
2057
|
+
},
|
|
2058
|
+
// past: "vor 2 Wochen"
|
|
2059
|
+
{
|
|
2060
|
+
pattern: new RegExp(`^vor\\s+(\\d+)\\s+(Tag(?:e|n|en)?|Woche(?:n)?|Monat(?:e|n|en)?|Jahr(?:e|n|en)?)$`, "i"),
|
|
2061
|
+
resolve: (m, ctx) => {
|
|
2062
|
+
const count = Number(m[1]);
|
|
2063
|
+
const unit = unitWordToEnglish(m[2]);
|
|
2064
|
+
return addUnits(ctx.temporal, ctx.reference, -count, unit);
|
|
2065
|
+
}
|
|
2066
|
+
},
|
|
2067
|
+
// future: "in 3 Tagen"
|
|
2068
|
+
{
|
|
2069
|
+
pattern: new RegExp(`^in\\s+(\\d+)\\s+(Tag(?:e|n|en)?|Woche(?:n)?|Monat(?:e|n|en)?|Jahr(?:e|n|en)?)$`, "i"),
|
|
2070
|
+
resolve: (m, ctx) => {
|
|
2071
|
+
const count = Number(m[1]);
|
|
2072
|
+
const unit = unitWordToEnglish(m[2]);
|
|
2073
|
+
return addUnits(ctx.temporal, ctx.reference, count, unit);
|
|
2074
|
+
}
|
|
2075
|
+
},
|
|
2076
|
+
// bare "N <unit>" without "in" or "vor" — throw.
|
|
2077
|
+
{
|
|
2078
|
+
pattern: new RegExp(`^(\\d+)\\s+(Tag(?:e|n|en)?|Woche(?:n)?|Monat(?:e|n|en)?|Jahr(?:e|n|en)?)$`, "i"),
|
|
2079
|
+
resolve: (m, _ctx) => {
|
|
2080
|
+
throw new Error(
|
|
2081
|
+
`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]}".`
|
|
2082
|
+
);
|
|
2083
|
+
}
|
|
2084
|
+
},
|
|
2085
|
+
// month-day: "5. März" (day-first with period). Year ignored.
|
|
2086
|
+
{
|
|
2087
|
+
pattern: new RegExp(
|
|
2088
|
+
`^(\\d{1,2})\\.?\\s+(${nameAlternation([...GERMAN_MONTHS, ...GERMAN_MONTH_SHORT, "Maerz", "Maer"])})(?:\\s+(\\d{4}))?$`,
|
|
2089
|
+
"i"
|
|
2090
|
+
),
|
|
2091
|
+
resolve: (m, ctx) => {
|
|
2092
|
+
const day = Number(m[1]);
|
|
2093
|
+
const month = monthIndexFromName(m[2], GERMAN_MONTHS, GERMAN_MONTH_SHORT);
|
|
2094
|
+
return resolveToNextOccurrence(ctx.temporal, ctx.reference, month, day);
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
]
|
|
2098
|
+
};
|
|
2099
|
+
var GRAMMARS = {
|
|
2100
|
+
en: ENGLISH_GRAMMAR,
|
|
2101
|
+
es: SPANISH_GRAMMAR,
|
|
2102
|
+
fr: FRENCH_GRAMMAR,
|
|
2103
|
+
de: GERMAN_GRAMMAR
|
|
2104
|
+
};
|
|
2105
|
+
function grammarForLocale(locale) {
|
|
2106
|
+
if (!locale) return ENGLISH_GRAMMAR;
|
|
2107
|
+
try {
|
|
2108
|
+
const tag = new Intl.Locale(locale.replace(/_/g, "-"));
|
|
2109
|
+
const lang = tag.language.toLowerCase();
|
|
2110
|
+
return GRAMMARS[lang] ?? ENGLISH_GRAMMAR;
|
|
2111
|
+
} catch {
|
|
2112
|
+
return ENGLISH_GRAMMAR;
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
function languageOf(locale) {
|
|
2116
|
+
if (!locale) return "en";
|
|
2117
|
+
try {
|
|
2118
|
+
return new Intl.Locale(locale.replace(/_/g, "-")).language.toLowerCase();
|
|
2119
|
+
} catch {
|
|
2120
|
+
return "en";
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
function unitWordToEnglish(word) {
|
|
2124
|
+
const w = normalizeForMatch(word);
|
|
2125
|
+
if (w === "day" || w === "week" || w === "month" || w === "year") return w;
|
|
2126
|
+
if (w === "dia") return "day";
|
|
2127
|
+
if (w === "semana") return "week";
|
|
2128
|
+
if (w === "mes") return "month";
|
|
2129
|
+
if (w === "ano" || w === "a\xF1o") return "year";
|
|
2130
|
+
if (w === "jour") return "day";
|
|
2131
|
+
if (w === "semaine") return "week";
|
|
2132
|
+
if (w === "mois") return "month";
|
|
2133
|
+
if (w === "an" || w === "annee") return "year";
|
|
2134
|
+
if (w === "tag" || w === "tagen") return "day";
|
|
2135
|
+
if (w === "woche" || w === "wochen") return "week";
|
|
2136
|
+
if (w === "monat" || w === "monaten") return "month";
|
|
2137
|
+
if (w === "jahr" || w === "jahren") return "year";
|
|
2138
|
+
/* c8 ignore start @preserve -- unreachable: every caller passes a word
|
|
2139
|
+
* captured by a regex alternation built from exactly these unit-word
|
|
2140
|
+
* forms (day/week/month/year across en/es/fr/de), so the branches
|
|
2141
|
+
* above already cover every string that can reach this function.
|
|
2142
|
+
* Kept as a tripwire for the type checker in case a grammar adds a
|
|
2143
|
+
* unit word here without a matching regex update. */
|
|
2144
|
+
throw new Error(`temporal-fmt: parseRelative internal error \u2014 unrecognized unit word "${word}".`);
|
|
2145
|
+
/* c8 ignore stop @preserve */
|
|
2146
|
+
}
|
|
2147
|
+
function parseRelative(input, referenceDate, options = {}) {
|
|
2148
|
+
const reference = referenceDate;
|
|
2149
|
+
const temporal = getTemporal();
|
|
2150
|
+
const trimmed = (input ?? "").trim().replace(/\s+/g, " ");
|
|
2151
|
+
if (trimmed.length === 0) {
|
|
2152
|
+
throw new Error("temporal-fmt: parseRelative got an empty input string.");
|
|
2153
|
+
}
|
|
2154
|
+
if (trimmed.length > MAX_RELATIVE_INPUT_LENGTH) {
|
|
2155
|
+
throw new RangeError(
|
|
2156
|
+
`temporal-fmt: parseRelative input is too large (maximum ${MAX_RELATIVE_INPUT_LENGTH} characters).`
|
|
2157
|
+
);
|
|
2158
|
+
}
|
|
2159
|
+
const normalized = normalizeForMatch(trimmed);
|
|
2160
|
+
const grammar = grammarForLocale(options.locale);
|
|
2161
|
+
const ctx = { temporal, reference };
|
|
2162
|
+
const registered = tryRegisteredGrammar(languageOf(options.locale), trimmed, {
|
|
2163
|
+
year: reference.year,
|
|
2164
|
+
month: reference.month,
|
|
2165
|
+
day: reference.day,
|
|
2166
|
+
dayOfWeek: reference.dayOfWeek
|
|
2167
|
+
});
|
|
2168
|
+
if (registered !== null) {
|
|
2169
|
+
return registered;
|
|
2170
|
+
}
|
|
2171
|
+
const tryMatch = (text) => {
|
|
2172
|
+
for (const matcher of grammar.matchers) {
|
|
2173
|
+
const match = text.match(matcher.pattern);
|
|
2174
|
+
if (match) {
|
|
2175
|
+
return matcher.resolve(match, ctx);
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
return NO_MATCH;
|
|
2179
|
+
};
|
|
2180
|
+
const exactResult = tryMatch(normalized);
|
|
2181
|
+
if (exactResult !== NO_MATCH) {
|
|
2182
|
+
return exactResult;
|
|
2183
|
+
}
|
|
2184
|
+
if (options.fuzzy) {
|
|
2185
|
+
if (grammar !== ENGLISH_GRAMMAR) {
|
|
2186
|
+
throw new Error(
|
|
2187
|
+
`temporal-fmt: parseRelative's { fuzzy: true } option currently only supports English. Pass no locale (or locale: 'en'), or omit { fuzzy: true } for this locale.`
|
|
2188
|
+
);
|
|
2189
|
+
}
|
|
2190
|
+
const corrected = fuzzyCorrectEnglish(normalized);
|
|
2191
|
+
if (corrected !== void 0) {
|
|
2192
|
+
const fuzzyResult = tryMatch(corrected);
|
|
2193
|
+
if (fuzzyResult !== NO_MATCH) {
|
|
2194
|
+
return fuzzyResult;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
throw new Error(
|
|
2199
|
+
`temporal-fmt: parseRelative doesn't recognize "${trimmed}". ` + grammar.supportedHint
|
|
2200
|
+
);
|
|
2201
|
+
}
|
|
2202
|
+
var NO_MATCH = /* @__PURE__ */ Symbol("temporal-fmt: parseRelative no match");
|
|
2203
|
+
|
|
2204
|
+
// src/config.ts
|
|
2205
|
+
var DEFAULT_CONFIG = Object.freeze({
|
|
2206
|
+
locale: DEFAULT_LOCALE,
|
|
2207
|
+
numberingSystem: "latn",
|
|
2208
|
+
firstDayOfWeek: 1,
|
|
2209
|
+
roundingMode: "nearest",
|
|
2210
|
+
disambiguation: "compatible",
|
|
2211
|
+
overflow: "reject",
|
|
2212
|
+
parseLenient: false,
|
|
2213
|
+
durationShowZeroValues: false
|
|
2214
|
+
});
|
|
2215
|
+
function createConfig(overrides = {}) {
|
|
2216
|
+
const merged = { ...DEFAULT_CONFIG, ...overrides };
|
|
2217
|
+
if (typeof merged.locale !== "string" || merged.locale.length === 0) {
|
|
2218
|
+
throw new Error(`temporal-fmt: config.locale must be a non-empty string (got ${String(merged.locale)}).`);
|
|
2219
|
+
}
|
|
2220
|
+
if (merged.numberingSystem !== void 0 && typeof merged.numberingSystem !== "string") {
|
|
2221
|
+
throw new Error(`temporal-fmt: config.numberingSystem must be a string (got ${String(merged.numberingSystem)}).`);
|
|
2222
|
+
}
|
|
2223
|
+
if (merged.firstDayOfWeek !== 1 && merged.firstDayOfWeek !== 7) {
|
|
2224
|
+
throw new Error(`temporal-fmt: config.firstDayOfWeek must be 1 (Monday) or 7 (Sunday) (got ${merged.firstDayOfWeek}).`);
|
|
2225
|
+
}
|
|
2226
|
+
if (!["nearest", "floor", "ceil", "trunc"].includes(merged.roundingMode)) {
|
|
2227
|
+
throw new Error(`temporal-fmt: config.roundingMode "${merged.roundingMode}" is not recognized.`);
|
|
2228
|
+
}
|
|
2229
|
+
if (!["compatible", "earlier", "later", "reject"].includes(merged.disambiguation)) {
|
|
2230
|
+
throw new Error(`temporal-fmt: config.disambiguation "${merged.disambiguation}" is not recognized.`);
|
|
2231
|
+
}
|
|
2232
|
+
if (!["constrain", "reject"].includes(merged.overflow)) {
|
|
2233
|
+
throw new Error(`temporal-fmt: config.overflow "${merged.overflow}" is not recognized.`);
|
|
2234
|
+
}
|
|
2235
|
+
return Object.freeze(merged);
|
|
2236
|
+
}
|
|
2237
|
+
function mergeWithConfig(config, perCall) {
|
|
2238
|
+
if (!config) return perCall;
|
|
2239
|
+
const extras = {};
|
|
2240
|
+
if (perCall.locale === void 0) extras.locale = config.locale;
|
|
2241
|
+
if (perCall.calendar === void 0 && config.calendar !== void 0) extras.calendar = config.calendar;
|
|
2242
|
+
if (perCall.timezone === void 0 && config.timezone !== void 0) extras.timezone = config.timezone;
|
|
2243
|
+
if (perCall.numberingSystem === void 0) extras.numberingSystem = config.numberingSystem;
|
|
2244
|
+
if (perCall.lenient === void 0 && config.parseLenient) extras.lenient = true;
|
|
2245
|
+
return { ...perCall, ...extras };
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
// src/businessCalendar.ts
|
|
2249
|
+
function createBusinessCalendar(options = {}) {
|
|
2250
|
+
const weekend = new Set(options.weekend ?? [6, 7]);
|
|
2251
|
+
const workingHours = { ...options.workingHours ?? {} };
|
|
2252
|
+
for (let i = 1; i <= 7; i++) {
|
|
2253
|
+
if (workingHours[i] === void 0) {
|
|
2254
|
+
workingHours[i] = weekend.has(i) ? 0 : 8;
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
return {
|
|
2258
|
+
weekend,
|
|
2259
|
+
holidays: options.holidays,
|
|
2260
|
+
workingHours,
|
|
2261
|
+
halfDays: new Set(options.halfDays ?? [])
|
|
2262
|
+
};
|
|
2263
|
+
}
|
|
2264
|
+
function isBusinessDay(cal, value) {
|
|
2265
|
+
const v = value;
|
|
2266
|
+
let dow = v.dayOfWeek;
|
|
2267
|
+
if (typeof v.year === "number" && typeof v.month === "number" && typeof v.day === "number") {
|
|
2268
|
+
dow = dayOfWeekFromCivil(v.year, v.month, v.day);
|
|
2269
|
+
}
|
|
2270
|
+
if (typeof dow !== "number") {
|
|
2271
|
+
throw new Error("temporal-fmt: isBusinessDay() needs a value with dayOfWeek (or year/month/day to compute it).");
|
|
2272
|
+
}
|
|
2273
|
+
if (cal.weekend.has(dow)) return false;
|
|
2274
|
+
if (cal.holidays && cal.holidays.isHoliday(value)) return false;
|
|
2275
|
+
return true;
|
|
2276
|
+
}
|
|
2277
|
+
function nextBusinessDay(cal, value) {
|
|
2278
|
+
let candidate = add(value, 1, "days");
|
|
2279
|
+
for (let i = 0; i < 14; i++) {
|
|
2280
|
+
if (isBusinessDay(cal, candidate)) return candidate;
|
|
2281
|
+
candidate = add(candidate, 1, "days");
|
|
2282
|
+
}
|
|
2283
|
+
throw new Error("temporal-fmt: nextBusinessDay() gave up after 14 days \u2014 likely a misconfigured calendar (e.g. all days are weekends or holidays).");
|
|
2284
|
+
}
|
|
2285
|
+
function previousBusinessDay(cal, value) {
|
|
2286
|
+
let candidate = add(value, -1, "days");
|
|
2287
|
+
for (let i = 0; i < 14; i++) {
|
|
2288
|
+
if (isBusinessDay(cal, candidate)) return candidate;
|
|
2289
|
+
candidate = add(candidate, -1, "days");
|
|
2290
|
+
}
|
|
2291
|
+
throw new Error("temporal-fmt: previousBusinessDay() gave up after 14 days \u2014 likely a misconfigured calendar.");
|
|
2292
|
+
}
|
|
2293
|
+
var MAX_BUSINESS_DAY_TRAVERSAL = 1e5;
|
|
2294
|
+
function assertBusinessDayCount(days) {
|
|
2295
|
+
if (!Number.isSafeInteger(days)) {
|
|
2296
|
+
throw new RangeError(
|
|
2297
|
+
`temporal-fmt: business-day count must be a finite safe integer (got ${days}).`
|
|
2298
|
+
);
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
function compareDateFields(a, b) {
|
|
2302
|
+
const av = a;
|
|
2303
|
+
const bv = b;
|
|
2304
|
+
const ay = av.year * 1e4 + av.month * 100 + av.day;
|
|
2305
|
+
const by = bv.year * 1e4 + bv.month * 100 + bv.day;
|
|
2306
|
+
return ay - by;
|
|
2307
|
+
}
|
|
2308
|
+
function addBusinessDays(cal, value, days) {
|
|
2309
|
+
assertBusinessDayCount(days);
|
|
2310
|
+
if (days === 0) return value;
|
|
2311
|
+
const sign = days > 0 ? 1 : -1;
|
|
2312
|
+
const absDays = Math.abs(days);
|
|
2313
|
+
if (absDays > MAX_BUSINESS_DAY_TRAVERSAL) {
|
|
2314
|
+
throw new RangeError(
|
|
2315
|
+
`temporal-fmt: addBusinessDays() exceeded the ${MAX_BUSINESS_DAY_TRAVERSAL}-day limit.`
|
|
2316
|
+
);
|
|
2317
|
+
}
|
|
2318
|
+
let candidate = value;
|
|
2319
|
+
for (let i = 0; i < absDays; i++) {
|
|
2320
|
+
candidate = sign > 0 ? nextBusinessDay(cal, candidate) : previousBusinessDay(cal, candidate);
|
|
2321
|
+
}
|
|
2322
|
+
return candidate;
|
|
2323
|
+
}
|
|
2324
|
+
function subtractBusinessDays(cal, value, days) {
|
|
2325
|
+
assertBusinessDayCount(days);
|
|
2326
|
+
return addBusinessDays(cal, value, -days);
|
|
2327
|
+
}
|
|
2328
|
+
function differenceInBusinessDays(cal, a, b) {
|
|
2329
|
+
const rawDirection = compareDateFields(b, a);
|
|
2330
|
+
if (rawDirection === 0) return 0;
|
|
2331
|
+
const direction = rawDirection > 0 ? 1 : -1;
|
|
2332
|
+
let candidate = a;
|
|
2333
|
+
let count = 0;
|
|
2334
|
+
let traversedDays = 0;
|
|
2335
|
+
while (compareDateFields(candidate, b) !== 0) {
|
|
2336
|
+
candidate = add(candidate, direction, "days");
|
|
2337
|
+
traversedDays++;
|
|
2338
|
+
if (traversedDays > MAX_BUSINESS_DAY_TRAVERSAL) {
|
|
2339
|
+
throw new RangeError(
|
|
2340
|
+
`temporal-fmt: differenceInBusinessDays() exceeded the ${MAX_BUSINESS_DAY_TRAVERSAL}-day traversal limit.`
|
|
2341
|
+
);
|
|
2342
|
+
}
|
|
2343
|
+
if (isBusinessDay(cal, candidate)) count += direction;
|
|
2344
|
+
}
|
|
2345
|
+
return count;
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2348
|
+
// src/holidays.ts
|
|
2349
|
+
var MAX_HOLIDAY_YEAR_RANGE = 5e3;
|
|
2350
|
+
function createHolidayCalendar(specs) {
|
|
2351
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2352
|
+
const MAX_CACHE_YEARS = 1e3;
|
|
2353
|
+
function forYear(year) {
|
|
2354
|
+
let list = cache.get(year);
|
|
2355
|
+
if (list) return list;
|
|
2356
|
+
if (cache.size >= MAX_CACHE_YEARS) {
|
|
2357
|
+
const oldest = cache.keys().next().value;
|
|
2358
|
+
if (oldest !== void 0) cache.delete(oldest);
|
|
2359
|
+
}
|
|
2360
|
+
list = specs.map((s) => {
|
|
2361
|
+
let md;
|
|
2362
|
+
if (s.compute) {
|
|
2363
|
+
md = s.compute(year);
|
|
2364
|
+
} else {
|
|
2365
|
+
md = { month: s.month, day: s.day };
|
|
2366
|
+
}
|
|
2367
|
+
return { ...md, name: s.name };
|
|
2368
|
+
});
|
|
2369
|
+
cache.set(year, list);
|
|
2370
|
+
return list;
|
|
2371
|
+
}
|
|
2372
|
+
return {
|
|
2373
|
+
isHoliday(value) {
|
|
2374
|
+
const v = value;
|
|
2375
|
+
if (typeof v.year !== "number" || typeof v.month !== "number" || typeof v.day !== "number") {
|
|
2376
|
+
throw new Error("temporal-fmt: isHoliday() needs a value with year/month/day.");
|
|
2377
|
+
}
|
|
2378
|
+
const list = forYear(v.year);
|
|
2379
|
+
return list.some((h) => h.month === v.month && h.day === v.day);
|
|
2380
|
+
},
|
|
2381
|
+
holidaysBetween(start, end) {
|
|
2382
|
+
const sv = start;
|
|
2383
|
+
const ev = end;
|
|
2384
|
+
if (typeof sv?.year !== "number" || typeof ev?.year !== "number") {
|
|
2385
|
+
throw new Error("temporal-fmt: holidaysBetween() needs start/end values with year/month/day.");
|
|
2386
|
+
}
|
|
2387
|
+
if (ev.year - sv.year > MAX_HOLIDAY_YEAR_RANGE) {
|
|
2388
|
+
throw new RangeError(
|
|
2389
|
+
`temporal-fmt: holidaysBetween() year range (${sv.year}\u2013${ev.year}) exceeds the ${MAX_HOLIDAY_YEAR_RANGE}-year limit. Split the query into smaller ranges.`
|
|
2390
|
+
);
|
|
2391
|
+
}
|
|
2392
|
+
const result = [];
|
|
2393
|
+
for (let y = sv.year; y <= ev.year; y++) {
|
|
2394
|
+
const list = forYear(y);
|
|
2395
|
+
for (const h of list) {
|
|
2396
|
+
const date = { year: y, month: h.month, day: h.day };
|
|
2397
|
+
if (compare(date, sv) >= 0 && compare(date, ev) <= 0) {
|
|
2398
|
+
result.push({ year: y, month: h.month, day: h.day });
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
return result;
|
|
2403
|
+
}
|
|
2404
|
+
};
|
|
2405
|
+
}
|
|
2406
|
+
function nextHoliday(cal, value) {
|
|
2407
|
+
let candidate = add(value, 1, "days");
|
|
2408
|
+
for (let i = 0; i < 365 * 5; i++) {
|
|
2409
|
+
if (cal.isHoliday(candidate)) return candidate;
|
|
2410
|
+
candidate = add(candidate, 1, "days");
|
|
2411
|
+
}
|
|
2412
|
+
return void 0;
|
|
2413
|
+
}
|
|
2414
|
+
function previousHoliday(cal, value) {
|
|
2415
|
+
let candidate = add(value, -1, "days");
|
|
2416
|
+
for (let i = 0; i < 365 * 5; i++) {
|
|
2417
|
+
if (cal.isHoliday(candidate)) return candidate;
|
|
2418
|
+
candidate = add(candidate, -1, "days");
|
|
2419
|
+
}
|
|
2420
|
+
return void 0;
|
|
2421
|
+
}
|
|
2422
|
+
function holidaysBetween(cal, start, end) {
|
|
2423
|
+
return cal.holidaysBetween(start, end);
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
// src/extensibility.ts
|
|
2427
|
+
function createFormatter(options = {}) {
|
|
2428
|
+
const mergedTokens = [...TOKENS];
|
|
2429
|
+
const customTokenNames = /* @__PURE__ */ new Set();
|
|
2430
|
+
for (const custom of options.tokens ?? []) {
|
|
2431
|
+
customTokenNames.add(custom.name);
|
|
2432
|
+
}
|
|
2433
|
+
for (const custom of options.tokens ?? []) {
|
|
2434
|
+
const existingIdx = mergedTokens.findIndex(([name]) => name === custom.name);
|
|
2435
|
+
if (existingIdx >= 0) {
|
|
2436
|
+
mergedTokens[existingIdx] = [custom.name, custom.handler, custom.field];
|
|
2437
|
+
} else {
|
|
2438
|
+
mergedTokens.push([custom.name, custom.handler, custom.field]);
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
mergedTokens.sort((a, b) => b[0].length - a[0].length);
|
|
2442
|
+
const handlerByToken = new Map(mergedTokens.map(([name, handler, field]) => [name, { handler, field }]));
|
|
2443
|
+
const sortedTokenStrings = mergedTokens.map(([name]) => name);
|
|
2444
|
+
function customTokenize(formatStr) {
|
|
2445
|
+
const pieces = [];
|
|
2446
|
+
let i = 0;
|
|
2447
|
+
while (i < formatStr.length) {
|
|
2448
|
+
const ch = formatStr[i];
|
|
2449
|
+
if (ch === "'") {
|
|
2450
|
+
if (formatStr[i + 1] === "'") {
|
|
2451
|
+
appendLiteral(pieces, "'");
|
|
2452
|
+
i += 2;
|
|
2453
|
+
continue;
|
|
2454
|
+
}
|
|
2455
|
+
let j = i + 1;
|
|
2456
|
+
let literal = "";
|
|
2457
|
+
let closed = false;
|
|
2458
|
+
while (j < formatStr.length) {
|
|
2459
|
+
if (formatStr[j] === "'") {
|
|
2460
|
+
if (formatStr[j + 1] === "'") {
|
|
2461
|
+
literal += "'";
|
|
2462
|
+
j += 2;
|
|
2463
|
+
continue;
|
|
2464
|
+
}
|
|
2465
|
+
closed = true;
|
|
2466
|
+
j += 1;
|
|
2467
|
+
break;
|
|
2468
|
+
}
|
|
2469
|
+
literal += formatStr[j];
|
|
2470
|
+
j += 1;
|
|
2471
|
+
}
|
|
2472
|
+
if (!closed) throw new Error(`temporal-fmt: unterminated quote in format string "${formatStr}"`);
|
|
2473
|
+
appendLiteral(pieces, literal);
|
|
2474
|
+
i = j;
|
|
2475
|
+
continue;
|
|
2476
|
+
}
|
|
2477
|
+
const match = sortedTokenStrings.find((tok) => formatStr.startsWith(tok, i));
|
|
2478
|
+
if (match) {
|
|
2479
|
+
const runChar = match[match.length - 1];
|
|
2480
|
+
if (formatStr[i + match.length] === runChar) {
|
|
2481
|
+
let end = i + match.length;
|
|
2482
|
+
while (formatStr[end] === runChar) end += 1;
|
|
2483
|
+
throw new UnknownTokenError({
|
|
2484
|
+
token: formatStr.slice(i, end),
|
|
2485
|
+
format: formatStr,
|
|
2486
|
+
message: `temporal-fmt: "${formatStr.slice(i, end)}" in format string "${formatStr}" isn't a recognized token \u2014 did you mean "${match}"?`
|
|
2487
|
+
});
|
|
2488
|
+
}
|
|
2489
|
+
pieces.push({ kind: "token", value: match });
|
|
2490
|
+
i += match.length;
|
|
2491
|
+
continue;
|
|
2492
|
+
}
|
|
2493
|
+
appendLiteral(pieces, ch);
|
|
2494
|
+
i += 1;
|
|
2495
|
+
}
|
|
2496
|
+
return pieces;
|
|
2497
|
+
}
|
|
2498
|
+
function appendLiteral(pieces, value) {
|
|
2499
|
+
const last = pieces[pieces.length - 1];
|
|
2500
|
+
if (last && last.kind === "literal") {
|
|
2501
|
+
last.value += value;
|
|
2502
|
+
} else {
|
|
2503
|
+
pieces.push({ kind: "literal", value });
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
const defaultLocale = options.defaultLocale ?? DEFAULT_LOCALE;
|
|
2507
|
+
return {
|
|
2508
|
+
format(temporal, formatStr, opts = {}) {
|
|
2509
|
+
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
2510
|
+
throw new Error(`temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`);
|
|
2511
|
+
}
|
|
2512
|
+
const locale = opts.locale ?? defaultLocale;
|
|
2513
|
+
const pieces = customTokenize(formatStr);
|
|
2514
|
+
let result = "";
|
|
2515
|
+
for (const piece of pieces) {
|
|
2516
|
+
if (piece.kind === "literal") {
|
|
2517
|
+
result += piece.value;
|
|
2518
|
+
continue;
|
|
2519
|
+
}
|
|
2520
|
+
const handler = handlerByToken.get(piece.value);
|
|
2521
|
+
/* c8 ignore start @preserve -- unreachable: customTokenize only ever produces a
|
|
2522
|
+
`kind: 'token'` piece via sortedTokenStrings.find(...), and
|
|
2523
|
+
handlerByToken is built from that same mergedTokens array, so
|
|
2524
|
+
every token piece is guaranteed a handler entry. Guards against a
|
|
2525
|
+
future customTokenize change that decouples the two lookups. */
|
|
2526
|
+
if (!handler) throw new Error(`temporal-fmt: unknown token "${piece.value}"`);
|
|
2527
|
+
/* c8 ignore stop @preserve */
|
|
2528
|
+
if (temporal[handler.field] === void 0) {
|
|
2529
|
+
throw new Error(
|
|
755
2530
|
`temporal-fmt: token "${piece.value}" requires "${String(handler.field)}", which this Temporal object doesn't have.`
|
|
756
2531
|
);
|
|
757
2532
|
}
|
|
@@ -849,539 +2624,330 @@ function createFormatter(options = {}) {
|
|
|
849
2624
|
};
|
|
850
2625
|
}
|
|
851
2626
|
|
|
852
|
-
// src/
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
return
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
2627
|
+
// src/ideData.ts
|
|
2628
|
+
function tokenFamily(name) {
|
|
2629
|
+
if (/^y+$/.test(name)) return "Year";
|
|
2630
|
+
if (/^[ML]+$/.test(name)) return "Month";
|
|
2631
|
+
if (/^[decD]+$/.test(name)) return "Day";
|
|
2632
|
+
if (/^[Ec]+$/.test(name)) return "Weekday";
|
|
2633
|
+
if (/^[Qq]+$/.test(name)) return "Quarter";
|
|
2634
|
+
if (/^[Gg]+$/.test(name)) return "Era";
|
|
2635
|
+
if (/^[Hh]+$/.test(name)) return "Hour";
|
|
2636
|
+
if (/^m+$/.test(name)) return "Minute";
|
|
2637
|
+
if (/^s+$/.test(name)) return "Second";
|
|
2638
|
+
if (/^S+$/.test(name)) return "Fractional Second";
|
|
2639
|
+
if (name === "a") return "Day Period";
|
|
2640
|
+
if (name === "z" || name === "zzz" || name === "zzzz") return "Time Zone";
|
|
2641
|
+
if (/^[Xx]+$/.test(name)) return "UTC Offset";
|
|
2642
|
+
if (name === "do") return "Ordinal Day";
|
|
2643
|
+
/* c8 ignore next 3 @preserve */
|
|
2644
|
+
if (name === "ww" || name === "RRRR") return "ISO Week";
|
|
2645
|
+
return "Other";
|
|
2646
|
+
}
|
|
2647
|
+
function getAutocompleteData() {
|
|
2648
|
+
return ALL_TOKEN_NAMES.map((name) => {
|
|
2649
|
+
const meta = TOKEN_METADATA[name];
|
|
2650
|
+
return {
|
|
2651
|
+
label: name,
|
|
2652
|
+
detail: meta.meaning,
|
|
2653
|
+
documentation: [
|
|
2654
|
+
meta.meaning,
|
|
2655
|
+
``,
|
|
2656
|
+
`Format-capable: ${meta.formatCapable}`,
|
|
2657
|
+
`Parse-capable: ${meta.parseCapable}`,
|
|
2658
|
+
`Locale-sensitive: ${meta.localeSensitive}`,
|
|
2659
|
+
`Calendar-sensitive: ${meta.calendarSensitive}`,
|
|
2660
|
+
`Timezone-sensitive: ${meta.timezoneSensitive}`,
|
|
2661
|
+
`Round-trip safe: ${meta.roundTripSafe}`,
|
|
2662
|
+
`Supported types: ${meta.supportedTypes.join(", ")}`
|
|
2663
|
+
].join("\n"),
|
|
2664
|
+
family: tokenFamily(name)
|
|
2665
|
+
};
|
|
2666
|
+
});
|
|
2667
|
+
}
|
|
2668
|
+
function getHoverDocs() {
|
|
2669
|
+
const result = {};
|
|
2670
|
+
for (const name of ALL_TOKEN_NAMES) {
|
|
2671
|
+
const meta = TOKEN_METADATA[name];
|
|
2672
|
+
result[name] = {
|
|
2673
|
+
signature: name,
|
|
2674
|
+
summary: meta.meaning,
|
|
2675
|
+
details: [
|
|
2676
|
+
// every entry in TOKEN_METADATA currently has formatCapable:
|
|
2677
|
+
// true (verified: 51/51). The 'no' branch reflects real,
|
|
2678
|
+
// intended behavior for a future format-incapable token —
|
|
2679
|
+
// there's no such token today, so this isn't reachable data,
|
|
2680
|
+
// not dead logic. Every other field on this line has real
|
|
2681
|
+
// true/false variance across the token table and is exercised
|
|
2682
|
+
// by this same loop running over ALL_TOKEN_NAMES.
|
|
2683
|
+
/* c8 ignore next */
|
|
2684
|
+
`Format-capable: ${meta.formatCapable ? "yes" : "no"}`,
|
|
2685
|
+
`Parse-capable: ${meta.parseCapable ? "yes" : "no"}`,
|
|
2686
|
+
`Locale-sensitive: ${meta.localeSensitive ? "yes" : "no"}`,
|
|
2687
|
+
`Calendar-sensitive: ${meta.calendarSensitive ? "yes" : "no"}`,
|
|
2688
|
+
`Timezone-sensitive: ${meta.timezoneSensitive ? "yes" : "no"}`,
|
|
2689
|
+
`Round-trip safe: ${meta.roundTripSafe ? "yes" : "no"}`,
|
|
2690
|
+
`Supported types: ${meta.supportedTypes.join(", ")}`
|
|
2691
|
+
].join("\n")
|
|
2692
|
+
};
|
|
2693
|
+
}
|
|
2694
|
+
return result;
|
|
2695
|
+
}
|
|
2696
|
+
function getInlineDiagnostics(formatStr) {
|
|
2697
|
+
const analysis = analyzeFormat(formatStr);
|
|
2698
|
+
const diagnostics = [];
|
|
2699
|
+
for (const warning of analysis.warnings) {
|
|
2700
|
+
let message = warning.message;
|
|
2701
|
+
let suggestion;
|
|
2702
|
+
if (warning.code === "TWELVE_HOUR_WITHOUT_A") {
|
|
2703
|
+
suggestion = 'Add an "a" token (e.g. "h:mm a") or use "H:mm" for 24-hour.';
|
|
2704
|
+
} else if (warning.code === "MIXED_12_AND_24_HOUR") {
|
|
2705
|
+
suggestion = 'Pick one form: "HH:mm" for 24-hour or "h:mm a" for 12-hour.';
|
|
2706
|
+
} else if (warning.code === "AMBIGUOUS_NUMERIC_RUN") {
|
|
2707
|
+
suggestion = 'Add a separator or use padded forms (e.g. "MM" instead of "M").';
|
|
2708
|
+
} else if (warning.code === "FORMAT_ONLY_TOKEN") {
|
|
2709
|
+
suggestion = 'Use a parse-capable variant (e.g. "d" instead of "do").';
|
|
2710
|
+
}
|
|
2711
|
+
diagnostics.push({
|
|
2712
|
+
startColumn: 0,
|
|
2713
|
+
endColumn: formatStr.length,
|
|
2714
|
+
severity: "warning",
|
|
2715
|
+
message,
|
|
2716
|
+
code: warning.code,
|
|
2717
|
+
suggestion
|
|
2718
|
+
});
|
|
2719
|
+
}
|
|
2720
|
+
return diagnostics;
|
|
2721
|
+
}
|
|
2722
|
+
var DAYJS_TO_TEMPORAL_FMT = [
|
|
2723
|
+
{ from: "YYYY", to: "yyyy" },
|
|
2724
|
+
{ from: "YY", to: "yy" },
|
|
2725
|
+
{ from: "MMMM", to: "MMMM" },
|
|
2726
|
+
{ from: "MMM", to: "MMM" },
|
|
2727
|
+
{ from: "MM", to: "MM" },
|
|
2728
|
+
{ from: "M", to: "M" },
|
|
2729
|
+
{ from: "DD", to: "dd" },
|
|
2730
|
+
{ from: "D", to: "d" },
|
|
2731
|
+
{ from: "Do", to: null, notes: `Ordinal day (AdvancedFormat) \u2014 use temporal-fmt's own "do" token instead.` },
|
|
2732
|
+
{ from: "dddd", to: "EEEE" },
|
|
2733
|
+
{ from: "ddd", to: "EEE" },
|
|
2734
|
+
{ from: "dd", to: null, notes: 'Min-name weekday (e.g. "Tu") \u2014 temporal-fmt has no equivalent width.' },
|
|
2735
|
+
{ 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.' },
|
|
2736
|
+
{ from: "HH", to: "HH" },
|
|
2737
|
+
{ from: "H", to: "H" },
|
|
2738
|
+
{ from: "hh", to: "hh" },
|
|
2739
|
+
{ from: "h", to: "h" },
|
|
2740
|
+
{ from: "kk", to: null, notes: "Hour 1-24 (AdvancedFormat) \u2014 no temporal-fmt equivalent." },
|
|
2741
|
+
{ from: "k", to: null, notes: "Hour 1-24 (AdvancedFormat) \u2014 no temporal-fmt equivalent." },
|
|
2742
|
+
{ from: "mm", to: "mm" },
|
|
2743
|
+
{ from: "m", to: "m" },
|
|
2744
|
+
{ from: "ss", to: "ss" },
|
|
2745
|
+
{ from: "s", to: "s" },
|
|
2746
|
+
// Fractional seconds: Day.js S/SS/SSS are 1/2/3-digit milliseconds,
|
|
2747
|
+
// the same widths temporal-fmt's own S/SS/SSS use. These used to be
|
|
2748
|
+
// missing from the table entirely, so "S"/"SS" silently translated
|
|
2749
|
+
// to quoted LITERAL text (translateDayjs('S') → "'S'") instead of
|
|
2750
|
+
// a token.
|
|
2751
|
+
{ from: "SSS", to: "SSS" },
|
|
2752
|
+
{ from: "SS", to: "SS" },
|
|
2753
|
+
{ from: "S", to: "S" },
|
|
2754
|
+
{ from: "A", to: "a", notes: "Uppercase AM/PM in Day.js \u2014 temporal-fmt is always lowercase." },
|
|
2755
|
+
{ from: "a", to: "a" },
|
|
2756
|
+
{ from: "ZZ", to: "XX", notes: "Numeric UTC offset, no colon." },
|
|
2757
|
+
{ from: "Z", to: "XXX", notes: "Numeric UTC offset with colon." },
|
|
2758
|
+
{ from: "X", to: null, notes: "Unix timestamp (seconds) \u2014 use fromUnixSeconds() instead." },
|
|
2759
|
+
{ from: "x", to: null, notes: "Unix timestamp (ms) \u2014 use fromUnixMilliseconds() instead." },
|
|
2760
|
+
{ from: "Qo", to: null, notes: "Ordinal quarter (AdvancedFormat) \u2014 no temporal-fmt equivalent." },
|
|
2761
|
+
{ from: "Q", to: "Q" },
|
|
2762
|
+
{ from: "Mo", to: null, notes: "Ordinal month (AdvancedFormat) \u2014 no temporal-fmt equivalent." },
|
|
2763
|
+
// Day.js w/ww are LOCALE-aware weeks (default en locale: week starts
|
|
2764
|
+
// Sunday, week 1 contains Jan 1) — not the ISO weeks temporal-fmt's
|
|
2765
|
+
// ww computes. Mapping silently would print different week numbers
|
|
2766
|
+
// than the source library for the same date (e.g. 2016-01-01: Day.js
|
|
2767
|
+
// "1" vs temporal-fmt "53"), so refuse with a note instead.
|
|
2768
|
+
{ from: "ww", to: null, notes: `Locale-aware week of year \u2014 temporal-fmt's "ww" is a strict ISO week number and disagrees with Day.js's locale week for the same date. Compute locale weeks separately if needed.` },
|
|
2769
|
+
{ from: "wo", to: null, notes: "Ordinal locale week (AdvancedFormat) \u2014 no temporal-fmt equivalent." },
|
|
2770
|
+
{ from: "w", to: null, notes: 'Unpadded locale week of year \u2014 see the "ww" note; temporal-fmt has only ISO weeks.' },
|
|
2771
|
+
{ from: "gg", to: null, notes: "Two-digit locale week-numbering year \u2014 no temporal-fmt equivalent (RRRR is 4-digit ISO)." },
|
|
2772
|
+
{ from: "gggg", to: "RRRR", notes: "Week-numbering year \u2014 mapped, but Day.js's is locale-week-based while RRRR is strict ISO; values can differ at year boundaries." },
|
|
2773
|
+
{ from: "L", to: null, notes: "Localized date format (AdvancedFormat) \u2014 write the format string out explicitly." },
|
|
2774
|
+
{ from: "LL", to: null, notes: "Localized date format (AdvancedFormat) \u2014 write the format string out explicitly." },
|
|
2775
|
+
{ from: "LLL", to: null, notes: "Localized date format (AdvancedFormat) \u2014 write the format string out explicitly." },
|
|
2776
|
+
{ from: "LLLL", to: null, notes: "Localized date format (AdvancedFormat) \u2014 write the format string out explicitly." },
|
|
2777
|
+
{ from: "LT", to: null, notes: "Localized time format (AdvancedFormat) \u2014 write the format string out explicitly." },
|
|
2778
|
+
{ from: "LTS", to: null, notes: "Localized time format (AdvancedFormat) \u2014 write the format string out explicitly." }
|
|
2779
|
+
];
|
|
2780
|
+
var DATE_FNS_TO_TEMPORAL_FMT = [
|
|
2781
|
+
{ from: "yyyy", to: "yyyy" },
|
|
2782
|
+
{ from: "yy", to: "yy" },
|
|
2783
|
+
// temporal-fmt HAS an unpadded-year token ("y", same as date-fns);
|
|
2784
|
+
// this used to map to null and throw even though the token passes
|
|
2785
|
+
// straight through.
|
|
2786
|
+
{ from: "y", to: "y", notes: 'Unpadded calendar year, opt-in via useAdditionalWeekYearTokens \u2014 temporal-fmt has the same "y" token.' },
|
|
2787
|
+
{ from: "MMMM", to: "MMMM" },
|
|
2788
|
+
{ from: "MMM", to: "MMM" },
|
|
2789
|
+
{ from: "MM", to: "MM" },
|
|
2790
|
+
{ from: "M", to: "M" },
|
|
2791
|
+
{ from: "LLLL", to: "LLLL" },
|
|
2792
|
+
{ from: "LLL", to: "LLL" },
|
|
2793
|
+
{ from: "dd", to: "dd" },
|
|
2794
|
+
{ from: "d", to: "d" },
|
|
2795
|
+
{ from: "do", to: "do" },
|
|
2796
|
+
{ from: "DDD", to: "DDD" },
|
|
2797
|
+
{ from: "DD", to: "DD" },
|
|
2798
|
+
{ from: "D", to: "D", notes: `Day-of-year, opt-in via useAdditionalDayOfYearTokens \u2014 matches temporal-fmt's own "D" already.` },
|
|
2799
|
+
{ from: "EEEE", to: "EEEE" },
|
|
2800
|
+
{ from: "EEE", to: "EEE" },
|
|
2801
|
+
{ from: "eeee", to: null, notes: "Locale-aware numeric weekday \u2014 no temporal-fmt equivalent." },
|
|
2802
|
+
{ from: "cccc", to: "cccc" },
|
|
2803
|
+
{ from: "ccc", to: "ccc" },
|
|
2804
|
+
{ from: "HH", to: "HH" },
|
|
2805
|
+
{ from: "H", to: "H" },
|
|
2806
|
+
{ from: "hh", to: "hh" },
|
|
2807
|
+
{ from: "h", to: "h" },
|
|
2808
|
+
{ from: "mm", to: "mm" },
|
|
2809
|
+
{ from: "m", to: "m" },
|
|
2810
|
+
{ from: "ss", to: "ss" },
|
|
2811
|
+
{ from: "s", to: "s" },
|
|
2812
|
+
// Fractional seconds, same widths as temporal-fmt's own tokens —
|
|
2813
|
+
// used to be missing, silently literalizing "S"/"SS".
|
|
2814
|
+
{ from: "SSS", to: "SSS" },
|
|
2815
|
+
{ from: "SS", to: "SS" },
|
|
2816
|
+
{ from: "S", to: "S" },
|
|
2817
|
+
{ from: "a", to: "a" },
|
|
2818
|
+
{ from: "aaa", to: "a" },
|
|
2819
|
+
{ from: "XXX", to: "XXX" },
|
|
2820
|
+
{ from: "XX", to: "XX" },
|
|
2821
|
+
{ from: "X", to: "X", notes: `Opt-in via useAdditionalDayOfYearTokens-adjacent rules in date-fns v3+; matches temporal-fmt's own "X" already.` },
|
|
2822
|
+
{ from: "xxx", to: "xxx" },
|
|
2823
|
+
{ from: "xx", to: "xx" },
|
|
2824
|
+
{ from: "x", to: "x" },
|
|
2825
|
+
{ from: "zzzz", to: "zzzz" },
|
|
2826
|
+
{ from: "zzz", to: "zzz" },
|
|
2827
|
+
{ from: "z", to: "z" },
|
|
2828
|
+
{ from: "QQQ", to: "QQQ" },
|
|
2829
|
+
{ from: "Q", to: "Q" },
|
|
2830
|
+
{ from: "QQQQ", to: null, notes: 'Long quarter name \u2014 temporal-fmt has Q (numeric) and QQQ ("Q1"-style) only.' },
|
|
2831
|
+
{ from: "Qo", to: null, notes: "Ordinal quarter \u2014 no temporal-fmt equivalent." },
|
|
2832
|
+
{ from: "GGGG", to: "GGGG" },
|
|
2833
|
+
{ from: "GGG", to: null, notes: 'Abbreviated era \u2014 temporal-fmt only has "G" (short) and "GGGG" (long).' },
|
|
2834
|
+
{ from: "GG", to: null, notes: 'Abbreviated era \u2014 temporal-fmt only has "G" (short) and "GGGG" (long).' },
|
|
2835
|
+
{ from: "G", to: "G" },
|
|
2836
|
+
// date-fns w/ww are LOCAL week rules (en-US: week starts Sunday, week
|
|
2837
|
+
// 1 contains Jan 1) — temporal-fmt's ww is strict ISO. Silently
|
|
2838
|
+
// mapping prints different numbers than the source library (2016-01-01:
|
|
2839
|
+
// date-fns "01" vs temporal-fmt "53"), so refuse with a note.
|
|
2840
|
+
{ from: "ww", to: null, notes: `Local week of year \u2014 temporal-fmt's "ww" is a strict ISO week number and disagrees with date-fns's locale week for the same date. Compute locale weeks separately if needed.` },
|
|
2841
|
+
{ from: "w", to: null, notes: `Unpadded local week number \u2014 temporal-fmt's "ww" is ISO-week and always 2-digit.` },
|
|
2842
|
+
{ from: "RRRR", to: "RRRR" },
|
|
2843
|
+
{ from: "R", to: null, notes: `Unpadded ISO week-numbering year \u2014 temporal-fmt's "RRRR" is always 4-digit.` },
|
|
2844
|
+
{ 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.' },
|
|
2845
|
+
{ from: "PPPP", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2846
|
+
{ from: "PPP", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2847
|
+
{ from: "PP", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2848
|
+
{ from: "P", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2849
|
+
{ from: "pppp", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2850
|
+
{ from: "ppp", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2851
|
+
{ from: "pp", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." },
|
|
2852
|
+
{ from: "p", to: null, notes: "Localized composite format \u2014 write the format string out explicitly." }
|
|
2853
|
+
];
|
|
2854
|
+
function previewFormat(formatStr, sample) {
|
|
2855
|
+
let value = sample;
|
|
2856
|
+
if (value === void 0) {
|
|
2857
|
+
const temporal = getTemporal();
|
|
2858
|
+
value = temporal.PlainDateTime.from({
|
|
2859
|
+
year: 2026,
|
|
2860
|
+
month: 8,
|
|
2861
|
+
day: 4,
|
|
2862
|
+
hour: 15,
|
|
2863
|
+
minute: 45,
|
|
2864
|
+
second: 30,
|
|
2865
|
+
millisecond: 123
|
|
2866
|
+
});
|
|
2867
|
+
}
|
|
2868
|
+
return format(value, formatStr, { locale: "en-US" });
|
|
2869
|
+
}
|
|
2870
|
+
function getDocUrl(tokenName) {
|
|
2871
|
+
void tokenName;
|
|
2872
|
+
return "README.md#token-reference";
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2875
|
+
// src/codemod.ts
|
|
2876
|
+
function splitOnBrackets(source) {
|
|
2877
|
+
const pieces = [];
|
|
2878
|
+
let i = 0;
|
|
2879
|
+
while (i < source.length) {
|
|
2880
|
+
if (source[i] === "[") {
|
|
2881
|
+
const end = source.indexOf("]", i + 1);
|
|
2882
|
+
if (end === -1) {
|
|
2883
|
+
pieces.push({ kind: "token", value: source.slice(i) });
|
|
2884
|
+
break;
|
|
894
2885
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
const original = getCompileFormatImpl();
|
|
903
|
-
setCompileFormatOverride((...args) => impl(original, ...args), modName);
|
|
904
|
-
},
|
|
905
|
-
overrideCompileParser(impl) {
|
|
906
|
-
const original = getCompileParserImpl();
|
|
907
|
-
setCompileParserOverride((...args) => impl(original, ...args), modName);
|
|
908
|
-
},
|
|
909
|
-
overrideParseRelative(impl) {
|
|
910
|
-
const original = getParseRelativeImpl();
|
|
911
|
-
setParseRelativeOverride((...args) => impl(original, ...args), modName);
|
|
912
|
-
},
|
|
913
|
-
overrideExplainFormat(impl) {
|
|
914
|
-
const original = getExplainFormatImpl();
|
|
915
|
-
setExplainFormatOverride((...args) => impl(original, ...args), modName);
|
|
916
|
-
},
|
|
917
|
-
overrideTokenizeFormat(impl) {
|
|
918
|
-
const original = getTokenizeFormatImpl();
|
|
919
|
-
setTokenizeFormatOverride((...args) => impl(original, ...args), modName);
|
|
920
|
-
},
|
|
921
|
-
overrideListTokens(impl) {
|
|
922
|
-
const original = getListTokensImpl();
|
|
923
|
-
setListTokensOverride((...args) => impl(original, ...args), modName);
|
|
924
|
-
},
|
|
925
|
-
overrideTokenInfo(impl) {
|
|
926
|
-
const original = getTokenInfoImpl();
|
|
927
|
-
setTokenInfoOverride((...args) => impl(original, ...args), modName);
|
|
928
|
-
},
|
|
929
|
-
overrideIsValidFormat(impl) {
|
|
930
|
-
const original = getIsValidFormatImpl();
|
|
931
|
-
setIsValidFormatOverride((...args) => impl(original, ...args), modName);
|
|
932
|
-
},
|
|
933
|
-
overrideValidateFormat(impl) {
|
|
934
|
-
const original = getValidateFormatImpl();
|
|
935
|
-
setValidateFormatOverride((...args) => impl(original, ...args), modName);
|
|
936
|
-
},
|
|
937
|
-
overrideFieldForToken(impl) {
|
|
938
|
-
const original = getFieldForTokenImpl();
|
|
939
|
-
setFieldForTokenOverride((...args) => impl(original, ...args), modName);
|
|
940
|
-
},
|
|
941
|
-
overrideMonthsInYear(impl) {
|
|
942
|
-
const original = getMonthsInYearImpl();
|
|
943
|
-
setMonthsInYearOverride((...args) => impl(original, ...args), modName);
|
|
944
|
-
},
|
|
945
|
-
overrideIsLeapYear(impl) {
|
|
946
|
-
const original = getIsLeapYearImpl();
|
|
947
|
-
setIsLeapYearOverride((...args) => impl(original, ...args), modName);
|
|
948
|
-
},
|
|
949
|
-
overrideIsLeapMonth(impl) {
|
|
950
|
-
const original = getIsLeapMonthImpl();
|
|
951
|
-
setIsLeapMonthOverride((...args) => impl(original, ...args), modName);
|
|
952
|
-
},
|
|
953
|
-
overrideWeekOfYear(impl) {
|
|
954
|
-
const original = getWeekOfYearImpl();
|
|
955
|
-
setWeekOfYearOverride((...args) => impl(original, ...args), modName);
|
|
956
|
-
},
|
|
957
|
-
overrideWeekYear(impl) {
|
|
958
|
-
const original = getWeekYearImpl();
|
|
959
|
-
setWeekYearOverride((...args) => impl(original, ...args), modName);
|
|
960
|
-
},
|
|
961
|
-
overrideGetMonth(impl) {
|
|
962
|
-
const original = getGetMonthImpl();
|
|
963
|
-
setGetMonthOverride((...args) => impl(original, ...args), modName);
|
|
964
|
-
},
|
|
965
|
-
overrideGetWeekday(impl) {
|
|
966
|
-
const original = getGetWeekdayImpl();
|
|
967
|
-
setGetWeekdayOverride((...args) => impl(original, ...args), modName);
|
|
968
|
-
},
|
|
969
|
-
overrideIsEqual(impl) {
|
|
970
|
-
const original = getIsEqualImpl();
|
|
971
|
-
setIsEqualOverride((...args) => impl(original, ...args), modName);
|
|
972
|
-
},
|
|
973
|
-
overrideIsBefore(impl) {
|
|
974
|
-
const original = getIsBeforeImpl();
|
|
975
|
-
setIsBeforeOverride((...args) => impl(original, ...args), modName);
|
|
976
|
-
},
|
|
977
|
-
overrideIsAfter(impl) {
|
|
978
|
-
const original = getIsAfterImpl();
|
|
979
|
-
setIsAfterOverride((...args) => impl(original, ...args), modName);
|
|
980
|
-
},
|
|
981
|
-
overrideClamp(impl) {
|
|
982
|
-
const original = getClampImpl();
|
|
983
|
-
setClampOverride((...args) => impl(original, ...args), modName);
|
|
984
|
-
},
|
|
985
|
-
overrideIsBetween(impl) {
|
|
986
|
-
const original = getIsBetweenImpl();
|
|
987
|
-
setIsBetweenOverride((...args) => impl(original, ...args), modName);
|
|
988
|
-
},
|
|
989
|
-
overrideIsToday(impl) {
|
|
990
|
-
const original = getIsTodayImpl();
|
|
991
|
-
setIsTodayOverride((...args) => impl(original, ...args), modName);
|
|
992
|
-
},
|
|
993
|
-
overrideIsTomorrow(impl) {
|
|
994
|
-
const original = getIsTomorrowImpl();
|
|
995
|
-
setIsTomorrowOverride((...args) => impl(original, ...args), modName);
|
|
996
|
-
},
|
|
997
|
-
overrideIsYesterday(impl) {
|
|
998
|
-
const original = getIsYesterdayImpl();
|
|
999
|
-
setIsYesterdayOverride((...args) => impl(original, ...args), modName);
|
|
1000
|
-
},
|
|
1001
|
-
overrideIsSameDay(impl) {
|
|
1002
|
-
const original = getIsSameDayImpl();
|
|
1003
|
-
setIsSameDayOverride((...args) => impl(original, ...args), modName);
|
|
1004
|
-
},
|
|
1005
|
-
overrideIsSameWeek(impl) {
|
|
1006
|
-
const original = getIsSameWeekImpl();
|
|
1007
|
-
setIsSameWeekOverride((...args) => impl(original, ...args), modName);
|
|
1008
|
-
},
|
|
1009
|
-
overrideIsSameMonth(impl) {
|
|
1010
|
-
const original = getIsSameMonthImpl();
|
|
1011
|
-
setIsSameMonthOverride((...args) => impl(original, ...args), modName);
|
|
1012
|
-
},
|
|
1013
|
-
overrideIsSameQuarter(impl) {
|
|
1014
|
-
const original = getIsSameQuarterImpl();
|
|
1015
|
-
setIsSameQuarterOverride((...args) => impl(original, ...args), modName);
|
|
1016
|
-
},
|
|
1017
|
-
overrideIsSameYear(impl) {
|
|
1018
|
-
const original = getIsSameYearImpl();
|
|
1019
|
-
setIsSameYearOverride((...args) => impl(original, ...args), modName);
|
|
1020
|
-
},
|
|
1021
|
-
overrideIsWeekday(impl) {
|
|
1022
|
-
const original = getIsWeekdayImpl();
|
|
1023
|
-
setIsWeekdayOverride((...args) => impl(original, ...args), modName);
|
|
1024
|
-
},
|
|
1025
|
-
overrideFloor(impl) {
|
|
1026
|
-
const original = getFloorImpl();
|
|
1027
|
-
setFloorOverride((...args) => impl(original, ...args), modName);
|
|
1028
|
-
},
|
|
1029
|
-
overrideCeil(impl) {
|
|
1030
|
-
const original = getCeilImpl();
|
|
1031
|
-
setCeilOverride((...args) => impl(original, ...args), modName);
|
|
1032
|
-
},
|
|
1033
|
-
overrideTruncate(impl) {
|
|
1034
|
-
const original = getTruncateImpl();
|
|
1035
|
-
setTruncateOverride((...args) => impl(original, ...args), modName);
|
|
1036
|
-
},
|
|
1037
|
-
overrideParseRFC3339(impl) {
|
|
1038
|
-
const original = getParseRFC3339Impl();
|
|
1039
|
-
setParseRFC3339Override((...args) => impl(original, ...args), modName);
|
|
1040
|
-
},
|
|
1041
|
-
overrideFormatRFC3339(impl) {
|
|
1042
|
-
const original = getFormatRFC3339Impl();
|
|
1043
|
-
setFormatRFC3339Override((...args) => impl(original, ...args), modName);
|
|
1044
|
-
},
|
|
1045
|
-
overrideParseRFC2822(impl) {
|
|
1046
|
-
const original = getParseRFC2822Impl();
|
|
1047
|
-
setParseRFC2822Override((...args) => impl(original, ...args), modName);
|
|
1048
|
-
},
|
|
1049
|
-
overrideParseHTTPDate(impl) {
|
|
1050
|
-
const original = getParseHTTPDateImpl();
|
|
1051
|
-
setParseHTTPDateOverride((...args) => impl(original, ...args), modName);
|
|
1052
|
-
},
|
|
1053
|
-
overrideFromUnixMicroseconds(impl) {
|
|
1054
|
-
const original = getFromUnixMicrosecondsImpl();
|
|
1055
|
-
setFromUnixMicrosecondsOverride((...args) => impl(original, ...args), modName);
|
|
1056
|
-
},
|
|
1057
|
-
overrideFromUnixNanoseconds(impl) {
|
|
1058
|
-
const original = getFromUnixNanosecondsImpl();
|
|
1059
|
-
setFromUnixNanosecondsOverride((...args) => impl(original, ...args), modName);
|
|
1060
|
-
},
|
|
1061
|
-
overrideToUnixSeconds(impl) {
|
|
1062
|
-
const original = getToUnixSecondsImpl();
|
|
1063
|
-
setToUnixSecondsOverride((...args) => impl(original, ...args), modName);
|
|
1064
|
-
},
|
|
1065
|
-
overrideToUnixMilliseconds(impl) {
|
|
1066
|
-
const original = getToUnixMillisecondsImpl();
|
|
1067
|
-
setToUnixMillisecondsOverride((...args) => impl(original, ...args), modName);
|
|
1068
|
-
},
|
|
1069
|
-
overrideToUnixMicroseconds(impl) {
|
|
1070
|
-
const original = getToUnixMicrosecondsImpl();
|
|
1071
|
-
setToUnixMicrosecondsOverride((...args) => impl(original, ...args), modName);
|
|
1072
|
-
},
|
|
1073
|
-
overrideToUnixNanoseconds(impl) {
|
|
1074
|
-
const original = getToUnixNanosecondsImpl();
|
|
1075
|
-
setToUnixNanosecondsOverride((...args) => impl(original, ...args), modName);
|
|
1076
|
-
},
|
|
1077
|
-
overrideParseSQL(impl) {
|
|
1078
|
-
const original = getParseSQLImpl();
|
|
1079
|
-
setParseSQLOverride((...args) => impl(original, ...args), modName);
|
|
1080
|
-
},
|
|
1081
|
-
overrideFormatSQL(impl) {
|
|
1082
|
-
const original = getFormatSQLImpl();
|
|
1083
|
-
setFormatSQLOverride((...args) => impl(original, ...args), modName);
|
|
1084
|
-
},
|
|
1085
|
-
overrideFormatDurationToParts(impl) {
|
|
1086
|
-
const original = getFormatDurationToPartsImpl();
|
|
1087
|
-
setFormatDurationToPartsOverride((...args) => impl(original, ...args), modName);
|
|
1088
|
-
},
|
|
1089
|
-
overrideParseDuration(impl) {
|
|
1090
|
-
const original = getParseDurationImpl();
|
|
1091
|
-
setParseDurationOverride((...args) => impl(original, ...args), modName);
|
|
1092
|
-
},
|
|
1093
|
-
overrideParseISODuration(impl) {
|
|
1094
|
-
const original = getParseISODurationImpl();
|
|
1095
|
-
setParseISODurationOverride((...args) => impl(original, ...args), modName);
|
|
1096
|
-
},
|
|
1097
|
-
overrideFormatISODuration(impl) {
|
|
1098
|
-
const original = getFormatISODurationImpl();
|
|
1099
|
-
setFormatISODurationOverride((...args) => impl(original, ...args), modName);
|
|
1100
|
-
},
|
|
1101
|
-
overrideBalanceDuration(impl) {
|
|
1102
|
-
const original = getBalanceDurationImpl();
|
|
1103
|
-
setBalanceDurationOverride((...args) => impl(original, ...args), modName);
|
|
1104
|
-
},
|
|
1105
|
-
overrideCompareDuration(impl) {
|
|
1106
|
-
const original = getCompareDurationImpl();
|
|
1107
|
-
setCompareDurationOverride((...args) => impl(original, ...args), modName);
|
|
1108
|
-
},
|
|
1109
|
-
overrideSubtractDuration(impl) {
|
|
1110
|
-
const original = getSubtractDurationImpl();
|
|
1111
|
-
setSubtractDurationOverride((...args) => impl(original, ...args), modName);
|
|
1112
|
-
},
|
|
1113
|
-
overrideGetLocale(impl) {
|
|
1114
|
-
const original = getGetLocaleImpl();
|
|
1115
|
-
setGetLocaleOverride((...args) => impl(original, ...args), modName);
|
|
1116
|
-
},
|
|
1117
|
-
overrideHasLocale(impl) {
|
|
1118
|
-
const original = getHasLocaleImpl();
|
|
1119
|
-
setHasLocaleOverride((...args) => impl(original, ...args), modName);
|
|
1120
|
-
},
|
|
1121
|
-
overrideCreateConfig(impl) {
|
|
1122
|
-
const original = getCreateConfigImpl();
|
|
1123
|
-
setCreateConfigOverride((...args) => impl(original, ...args), modName);
|
|
1124
|
-
},
|
|
1125
|
-
overrideMergeWithConfig(impl) {
|
|
1126
|
-
const original = getMergeWithConfigImpl();
|
|
1127
|
-
setMergeWithConfigOverride((...args) => impl(original, ...args), modName);
|
|
1128
|
-
},
|
|
1129
|
-
overrideListRegisteredGrammars(impl) {
|
|
1130
|
-
const original = getListRegisteredGrammarsImpl();
|
|
1131
|
-
setListRegisteredGrammarsOverride((...args) => impl(original, ...args), modName);
|
|
1132
|
-
},
|
|
1133
|
-
overrideInterval(impl) {
|
|
1134
|
-
const original = getIntervalImpl();
|
|
1135
|
-
setIntervalOverride((...args) => impl(original, ...args), modName);
|
|
1136
|
-
},
|
|
1137
|
-
overrideOverlaps(impl) {
|
|
1138
|
-
const original = getOverlapsImpl();
|
|
1139
|
-
setOverlapsOverride((...args) => impl(original, ...args), modName);
|
|
1140
|
-
},
|
|
1141
|
-
overrideIntersection(impl) {
|
|
1142
|
-
const original = getIntersectionImpl();
|
|
1143
|
-
setIntersectionOverride((...args) => impl(original, ...args), modName);
|
|
1144
|
-
},
|
|
1145
|
-
overrideUnion(impl) {
|
|
1146
|
-
const original = getUnionImpl();
|
|
1147
|
-
setUnionOverride((...args) => impl(original, ...args), modName);
|
|
1148
|
-
},
|
|
1149
|
-
overrideMergeIntervals(impl) {
|
|
1150
|
-
const original = getMergeIntervalsImpl();
|
|
1151
|
-
setMergeIntervalsOverride((...args) => impl(original, ...args), modName);
|
|
1152
|
-
},
|
|
1153
|
-
overrideFormatRangeToParts(impl) {
|
|
1154
|
-
const original = getFormatRangeToPartsImpl();
|
|
1155
|
-
setFormatRangeToPartsOverride((...args) => impl(original, ...args), modName);
|
|
1156
|
-
},
|
|
1157
|
-
overrideBetween(impl) {
|
|
1158
|
-
const original = getBetweenImpl();
|
|
1159
|
-
setBetweenOverride((...args) => impl(original, ...args), modName);
|
|
1160
|
-
},
|
|
1161
|
-
overrideParseRRule(impl) {
|
|
1162
|
-
const original = getParseRRuleImpl();
|
|
1163
|
-
setParseRRuleOverride((...args) => impl(original, ...args), modName);
|
|
1164
|
-
},
|
|
1165
|
-
overrideFormatRRule(impl) {
|
|
1166
|
-
const original = getFormatRRuleImpl();
|
|
1167
|
-
setFormatRRuleOverride((...args) => impl(original, ...args), modName);
|
|
1168
|
-
},
|
|
1169
|
-
overrideCreateBusinessCalendar(impl) {
|
|
1170
|
-
const original = getCreateBusinessCalendarImpl();
|
|
1171
|
-
setCreateBusinessCalendarOverride((...args) => impl(original, ...args), modName);
|
|
1172
|
-
},
|
|
1173
|
-
overrideSubtractBusinessDays(impl) {
|
|
1174
|
-
const original = getSubtractBusinessDaysImpl();
|
|
1175
|
-
setSubtractBusinessDaysOverride((...args) => impl(original, ...args), modName);
|
|
1176
|
-
},
|
|
1177
|
-
overrideNextHoliday(impl) {
|
|
1178
|
-
const original = getNextHolidayImpl();
|
|
1179
|
-
setNextHolidayOverride((...args) => impl(original, ...args), modName);
|
|
1180
|
-
},
|
|
1181
|
-
overridePreviousHoliday(impl) {
|
|
1182
|
-
const original = getPreviousHolidayImpl();
|
|
1183
|
-
setPreviousHolidayOverride((...args) => impl(original, ...args), modName);
|
|
1184
|
-
},
|
|
1185
|
-
overrideResolveZoned(impl) {
|
|
1186
|
-
const original = getResolveZonedImpl();
|
|
1187
|
-
setResolveZonedOverride((...args) => impl(original, ...args), modName);
|
|
1188
|
-
},
|
|
1189
|
-
overrideGetNextTransition(impl) {
|
|
1190
|
-
const original = getGetNextTransitionImpl();
|
|
1191
|
-
setGetNextTransitionOverride((...args) => impl(original, ...args), modName);
|
|
1192
|
-
},
|
|
1193
|
-
overrideGetPreviousTransition(impl) {
|
|
1194
|
-
const original = getGetPreviousTransitionImpl();
|
|
1195
|
-
setGetPreviousTransitionOverride((...args) => impl(original, ...args), modName);
|
|
1196
|
-
},
|
|
1197
|
-
overridePossibleInstantsFor(impl) {
|
|
1198
|
-
const original = getPossibleInstantsForImpl();
|
|
1199
|
-
setPossibleInstantsForOverride((...args) => impl(original, ...args), modName);
|
|
1200
|
-
},
|
|
1201
|
-
overrideGetAutocompleteData(impl) {
|
|
1202
|
-
const original = getGetAutocompleteDataImpl();
|
|
1203
|
-
setGetAutocompleteDataOverride((...args) => impl(original, ...args), modName);
|
|
1204
|
-
},
|
|
1205
|
-
overrideGetHoverDocs(impl) {
|
|
1206
|
-
const original = getGetHoverDocsImpl();
|
|
1207
|
-
setGetHoverDocsOverride((...args) => impl(original, ...args), modName);
|
|
1208
|
-
},
|
|
1209
|
-
overrideGetInlineDiagnostics(impl) {
|
|
1210
|
-
const original = getGetInlineDiagnosticsImpl();
|
|
1211
|
-
setGetInlineDiagnosticsOverride((...args) => impl(original, ...args), modName);
|
|
1212
|
-
},
|
|
1213
|
-
overridePreviewFormat(impl) {
|
|
1214
|
-
const original = getPreviewFormatImpl();
|
|
1215
|
-
setPreviewFormatOverride((...args) => impl(original, ...args), modName);
|
|
1216
|
-
},
|
|
1217
|
-
overrideGetDocUrl(impl) {
|
|
1218
|
-
const original = getGetDocUrlImpl();
|
|
1219
|
-
setGetDocUrlOverride((...args) => impl(original, ...args), modName);
|
|
1220
|
-
},
|
|
1221
|
-
overrideTranslateDateFnsFormatString(impl) {
|
|
1222
|
-
const original = getTranslateDateFnsFormatStringImpl();
|
|
1223
|
-
setTranslateDateFnsFormatStringOverride((...args) => impl(original, ...args), modName);
|
|
2886
|
+
pieces.push({ kind: "literal", value: source.slice(i + 1, end) });
|
|
2887
|
+
i = end + 1;
|
|
2888
|
+
} else {
|
|
2889
|
+
let j = i;
|
|
2890
|
+
while (j < source.length && source[j] !== "[") j += 1;
|
|
2891
|
+
pieces.push({ kind: "token", value: source.slice(i, j) });
|
|
2892
|
+
i = j;
|
|
1224
2893
|
}
|
|
1225
|
-
}
|
|
2894
|
+
}
|
|
2895
|
+
return pieces;
|
|
1226
2896
|
}
|
|
1227
|
-
function
|
|
1228
|
-
|
|
2897
|
+
function splitIntoRuns(span, sortedFrom) {
|
|
2898
|
+
const pieces = [];
|
|
2899
|
+
let i = 0;
|
|
2900
|
+
while (i < span.length) {
|
|
2901
|
+
const match = sortedFrom.find((tok) => span.startsWith(tok, i));
|
|
2902
|
+
if (match) {
|
|
2903
|
+
pieces.push({ kind: "token", value: match });
|
|
2904
|
+
i += match.length;
|
|
2905
|
+
continue;
|
|
2906
|
+
}
|
|
2907
|
+
const last = pieces[pieces.length - 1];
|
|
2908
|
+
if (last && last.kind === "literal") {
|
|
2909
|
+
last.value += span[i];
|
|
2910
|
+
} else {
|
|
2911
|
+
pieces.push({ kind: "literal", value: span[i] });
|
|
2912
|
+
}
|
|
2913
|
+
i += 1;
|
|
2914
|
+
}
|
|
2915
|
+
return pieces;
|
|
1229
2916
|
}
|
|
1230
|
-
function
|
|
1231
|
-
|
|
1232
|
-
const
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
});
|
|
1254
|
-
base.reportIssue(issue);
|
|
1255
|
-
},
|
|
1256
|
-
registerLocale(locale, vocab) {
|
|
1257
|
-
onRegister({ kind: "locale", key: locale });
|
|
1258
|
-
base.registerLocale(locale, vocab);
|
|
1259
|
-
},
|
|
1260
|
-
registerLocaleVocab(locale, vocab) {
|
|
1261
|
-
onRegister({ kind: "localeVocab", key: locale });
|
|
1262
|
-
base.registerLocaleVocab(locale, vocab);
|
|
1263
|
-
},
|
|
1264
|
-
registerRelativeGrammar(grammar) {
|
|
1265
|
-
onRegister({ kind: "relativeGrammar", key: grammar.language });
|
|
1266
|
-
base.registerRelativeGrammar(grammar);
|
|
1267
|
-
},
|
|
1268
|
-
createFormatter(options) {
|
|
1269
|
-
for (const token of options?.tokens ?? []) {
|
|
1270
|
-
onRegister({ kind: "formatterTokens", key: token.name });
|
|
2917
|
+
function translate(source, table, sourceLibLabel) {
|
|
2918
|
+
const byFrom = new Map(table.map((hint) => [hint.from, hint.to]));
|
|
2919
|
+
const sortedFrom = [...byFrom.keys()].sort((a, b) => b.length - a.length);
|
|
2920
|
+
const bracketPieces = splitOnBrackets(source);
|
|
2921
|
+
let out = "";
|
|
2922
|
+
for (const piece of bracketPieces) {
|
|
2923
|
+
if (piece.kind === "literal") {
|
|
2924
|
+
out += `'${piece.value.replace(/'/g, "''")}'`;
|
|
2925
|
+
continue;
|
|
2926
|
+
}
|
|
2927
|
+
for (const run of splitIntoRuns(piece.value, sortedFrom)) {
|
|
2928
|
+
if (run.kind === "token") {
|
|
2929
|
+
const mapped = byFrom.get(run.value);
|
|
2930
|
+
if (mapped === void 0 || mapped === null) {
|
|
2931
|
+
throw new Error(
|
|
2932
|
+
`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.`
|
|
2933
|
+
);
|
|
2934
|
+
}
|
|
2935
|
+
out += mapped;
|
|
2936
|
+
} else if (/[a-zA-Z]/.test(run.value)) {
|
|
2937
|
+
out += `'${run.value.replace(/'/g, "''")}'`;
|
|
2938
|
+
} else {
|
|
2939
|
+
out += run.value;
|
|
1271
2940
|
}
|
|
1272
|
-
return base.createFormatter(options);
|
|
1273
|
-
},
|
|
1274
|
-
registerFormatToken(token) {
|
|
1275
|
-
onRegister({ kind: "formatToken", key: token.name });
|
|
1276
|
-
base.registerFormatToken(token);
|
|
1277
|
-
},
|
|
1278
|
-
createHolidayCalendar(specs) {
|
|
1279
|
-
return base.createHolidayCalendar(specs);
|
|
1280
|
-
},
|
|
1281
|
-
overrideFormat(impl) {
|
|
1282
|
-
base.overrideFormat(impl);
|
|
1283
|
-
onRegister({ kind: "overrideFormat", key: "format" });
|
|
1284
|
-
},
|
|
1285
|
-
overrideParse(impl) {
|
|
1286
|
-
base.overrideParse(impl);
|
|
1287
|
-
onRegister({ kind: "overrideParse", key: "parse" });
|
|
1288
2941
|
}
|
|
1289
|
-
}
|
|
2942
|
+
}
|
|
2943
|
+
return out;
|
|
1290
2944
|
}
|
|
1291
|
-
function
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
if (v.requires !== void 0 && !(Array.isArray(v.requires) && v.requires.every((r) => typeof r === "string"))) return false;
|
|
1297
|
-
if (v.priority !== void 0 && typeof v.priority !== "number") return false;
|
|
1298
|
-
return true;
|
|
2945
|
+
function translateDayjsFormatString(formatStr) {
|
|
2946
|
+
return translate(formatStr, DAYJS_TO_TEMPORAL_FMT, "Day.js");
|
|
2947
|
+
}
|
|
2948
|
+
function translateDateFnsFormatString(formatStr) {
|
|
2949
|
+
return translate(formatStr, DATE_FNS_TO_TEMPORAL_FMT, "date-fns");
|
|
1299
2950
|
}
|
|
1300
|
-
|
|
1301
|
-
// src/index.ts
|
|
1302
|
-
var format = (...args) => getFormatImpl()(...args);
|
|
1303
|
-
var parse = (...args) => getParseImpl()(...args);
|
|
1304
|
-
var compileFormat = (...args) => getCompileFormatImpl()(...args);
|
|
1305
|
-
var compileParser = (...args) => getCompileParserImpl()(...args);
|
|
1306
|
-
var parseRelative = (...args) => getParseRelativeImpl()(...args);
|
|
1307
|
-
var explainFormat = (...args) => getExplainFormatImpl()(...args);
|
|
1308
|
-
var tokenizeFormat = (...args) => getTokenizeFormatImpl()(...args);
|
|
1309
|
-
var listTokens = (...args) => getListTokensImpl()(...args);
|
|
1310
|
-
var tokenInfo = (...args) => getTokenInfoImpl()(...args);
|
|
1311
|
-
var isValidFormat = (...args) => getIsValidFormatImpl()(...args);
|
|
1312
|
-
var validateFormat = (...args) => getValidateFormatImpl()(...args);
|
|
1313
|
-
var fieldForToken = (...args) => getFieldForTokenImpl()(...args);
|
|
1314
|
-
var monthsInYear = (...args) => getMonthsInYearImpl()(...args);
|
|
1315
|
-
var isLeapYear = (...args) => getIsLeapYearImpl()(...args);
|
|
1316
|
-
var isLeapMonth = (...args) => getIsLeapMonthImpl()(...args);
|
|
1317
|
-
var weekOfYear = (...args) => getWeekOfYearImpl()(...args);
|
|
1318
|
-
var weekYear = (...args) => getWeekYearImpl()(...args);
|
|
1319
|
-
var getMonth = (...args) => getGetMonthImpl()(...args);
|
|
1320
|
-
var getWeekday = (...args) => getGetWeekdayImpl()(...args);
|
|
1321
|
-
var isEqual = (...args) => getIsEqualImpl()(...args);
|
|
1322
|
-
var isBefore2 = (...args) => getIsBeforeImpl()(...args);
|
|
1323
|
-
var isAfter2 = (...args) => getIsAfterImpl()(...args);
|
|
1324
|
-
var clamp = (...args) => getClampImpl()(...args);
|
|
1325
|
-
var isBetween = (...args) => getIsBetweenImpl()(...args);
|
|
1326
|
-
var isToday = (...args) => getIsTodayImpl()(...args);
|
|
1327
|
-
var isTomorrow = (...args) => getIsTomorrowImpl()(...args);
|
|
1328
|
-
var isYesterday = (...args) => getIsYesterdayImpl()(...args);
|
|
1329
|
-
var isSameDay = (...args) => getIsSameDayImpl()(...args);
|
|
1330
|
-
var isSameWeek = (...args) => getIsSameWeekImpl()(...args);
|
|
1331
|
-
var isSameMonth = (...args) => getIsSameMonthImpl()(...args);
|
|
1332
|
-
var isSameQuarter = (...args) => getIsSameQuarterImpl()(...args);
|
|
1333
|
-
var isSameYear = (...args) => getIsSameYearImpl()(...args);
|
|
1334
|
-
var isWeekday = (...args) => getIsWeekdayImpl()(...args);
|
|
1335
|
-
var floor = (...args) => getFloorImpl()(...args);
|
|
1336
|
-
var ceil = (...args) => getCeilImpl()(...args);
|
|
1337
|
-
var truncate = (...args) => getTruncateImpl()(...args);
|
|
1338
|
-
var parseRFC3339 = (...args) => getParseRFC3339Impl()(...args);
|
|
1339
|
-
var formatRFC3339 = (...args) => getFormatRFC3339Impl()(...args);
|
|
1340
|
-
var parseRFC2822 = (...args) => getParseRFC2822Impl()(...args);
|
|
1341
|
-
var parseHTTPDate = (...args) => getParseHTTPDateImpl()(...args);
|
|
1342
|
-
var fromUnixMicroseconds = (...args) => getFromUnixMicrosecondsImpl()(...args);
|
|
1343
|
-
var fromUnixNanoseconds = (...args) => getFromUnixNanosecondsImpl()(...args);
|
|
1344
|
-
var toUnixSeconds = (...args) => getToUnixSecondsImpl()(...args);
|
|
1345
|
-
var toUnixMilliseconds = (...args) => getToUnixMillisecondsImpl()(...args);
|
|
1346
|
-
var toUnixMicroseconds = (...args) => getToUnixMicrosecondsImpl()(...args);
|
|
1347
|
-
var toUnixNanoseconds = (...args) => getToUnixNanosecondsImpl()(...args);
|
|
1348
|
-
var parseSQL = (...args) => getParseSQLImpl()(...args);
|
|
1349
|
-
var formatSQL = (...args) => getFormatSQLImpl()(...args);
|
|
1350
|
-
var formatDurationToParts = (...args) => getFormatDurationToPartsImpl()(...args);
|
|
1351
|
-
var parseDuration = (...args) => getParseDurationImpl()(...args);
|
|
1352
|
-
var parseISODuration = (...args) => getParseISODurationImpl()(...args);
|
|
1353
|
-
var formatISODuration = (...args) => getFormatISODurationImpl()(...args);
|
|
1354
|
-
var balanceDuration = (...args) => getBalanceDurationImpl()(...args);
|
|
1355
|
-
var compareDuration = (...args) => getCompareDurationImpl()(...args);
|
|
1356
|
-
var subtractDuration = (...args) => getSubtractDurationImpl()(...args);
|
|
1357
|
-
var getLocale = (...args) => getGetLocaleImpl()(...args);
|
|
1358
|
-
var hasLocale = (...args) => getHasLocaleImpl()(...args);
|
|
1359
|
-
var createConfig = (...args) => getCreateConfigImpl()(...args);
|
|
1360
|
-
var mergeWithConfig = (...args) => getMergeWithConfigImpl()(...args);
|
|
1361
|
-
var listRegisteredGrammars = (...args) => getListRegisteredGrammarsImpl()(...args);
|
|
1362
|
-
var interval = (...args) => getIntervalImpl()(...args);
|
|
1363
|
-
var overlaps = (...args) => getOverlapsImpl()(...args);
|
|
1364
|
-
var intersection = (...args) => getIntersectionImpl()(...args);
|
|
1365
|
-
var union = (...args) => getUnionImpl()(...args);
|
|
1366
|
-
var mergeIntervals = (...args) => getMergeIntervalsImpl()(...args);
|
|
1367
|
-
var formatRangeToParts = (...args) => getFormatRangeToPartsImpl()(...args);
|
|
1368
|
-
var between = (...args) => getBetweenImpl()(...args);
|
|
1369
|
-
var parseRRule = (...args) => getParseRRuleImpl()(...args);
|
|
1370
|
-
var formatRRule = (...args) => getFormatRRuleImpl()(...args);
|
|
1371
|
-
var createBusinessCalendar = (...args) => getCreateBusinessCalendarImpl()(...args);
|
|
1372
|
-
var subtractBusinessDays = (...args) => getSubtractBusinessDaysImpl()(...args);
|
|
1373
|
-
var nextHoliday = (...args) => getNextHolidayImpl()(...args);
|
|
1374
|
-
var previousHoliday = (...args) => getPreviousHolidayImpl()(...args);
|
|
1375
|
-
var resolveZoned = (...args) => getResolveZonedImpl()(...args);
|
|
1376
|
-
var getNextTransition = (...args) => getGetNextTransitionImpl()(...args);
|
|
1377
|
-
var getPreviousTransition = (...args) => getGetPreviousTransitionImpl()(...args);
|
|
1378
|
-
var possibleInstantsFor = (...args) => getPossibleInstantsForImpl()(...args);
|
|
1379
|
-
var getAutocompleteData = (...args) => getGetAutocompleteDataImpl()(...args);
|
|
1380
|
-
var getHoverDocs = (...args) => getGetHoverDocsImpl()(...args);
|
|
1381
|
-
var getInlineDiagnostics = (...args) => getGetInlineDiagnosticsImpl()(...args);
|
|
1382
|
-
var previewFormat = (...args) => getPreviewFormatImpl()(...args);
|
|
1383
|
-
var getDocUrl = (...args) => getGetDocUrlImpl()(...args);
|
|
1384
|
-
var translateDateFnsFormatString = (...args) => getTranslateDateFnsFormatStringImpl()(...args);
|
|
1385
2951
|
export {
|
|
1386
2952
|
ALL_TOKEN_NAMES,
|
|
1387
2953
|
AmbiguousInputError,
|
|
@@ -1390,7 +2956,6 @@ export {
|
|
|
1390
2956
|
DEFAULT_CONFIG,
|
|
1391
2957
|
FORMAT_ONLY_TOKENS,
|
|
1392
2958
|
FormatSyntaxError,
|
|
1393
|
-
GRANTABLE_PERMISSIONS,
|
|
1394
2959
|
InvalidCalendarError,
|
|
1395
2960
|
InvalidDateError,
|
|
1396
2961
|
InvalidDurationError,
|
|
@@ -1398,7 +2963,6 @@ export {
|
|
|
1398
2963
|
InvalidOffsetError,
|
|
1399
2964
|
InvalidTimeError,
|
|
1400
2965
|
InvalidTimeZoneError,
|
|
1401
|
-
OverrideConflictError,
|
|
1402
2966
|
ParseMismatchError,
|
|
1403
2967
|
SUPPORTED_NUMBERING_SYSTEMS,
|
|
1404
2968
|
TOKEN_METADATA,
|
|
@@ -1430,9 +2994,6 @@ export {
|
|
|
1430
2994
|
assertZonedDateTime,
|
|
1431
2995
|
balanceDuration,
|
|
1432
2996
|
between,
|
|
1433
|
-
buildModContext,
|
|
1434
|
-
buildModContextFor,
|
|
1435
|
-
buildTrackedModContext,
|
|
1436
2997
|
ceil,
|
|
1437
2998
|
clamp,
|
|
1438
2999
|
compare,
|
|
@@ -1448,7 +3009,7 @@ export {
|
|
|
1448
3009
|
dayOfYearHelper as dayOfYear,
|
|
1449
3010
|
daysInMonth,
|
|
1450
3011
|
daysInYear,
|
|
1451
|
-
|
|
3012
|
+
difference,
|
|
1452
3013
|
differenceInBusinessDays,
|
|
1453
3014
|
differenceInDays,
|
|
1454
3015
|
differenceInHours,
|
|
@@ -1503,12 +3064,12 @@ export {
|
|
|
1503
3064
|
intersects,
|
|
1504
3065
|
interval,
|
|
1505
3066
|
contains as intervalContains,
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
3067
|
+
difference2 as intervalDifference,
|
|
3068
|
+
isAfter2 as intervalIsAfter,
|
|
3069
|
+
isBefore2 as intervalIsBefore,
|
|
3070
|
+
subtract2 as intervalSubtract,
|
|
3071
|
+
isAfter,
|
|
3072
|
+
isBefore,
|
|
1512
3073
|
isBetween,
|
|
1513
3074
|
isBusinessDay,
|
|
1514
3075
|
isDST,
|
|
@@ -1517,7 +3078,6 @@ export {
|
|
|
1517
3078
|
isInstant,
|
|
1518
3079
|
isLeapMonth,
|
|
1519
3080
|
isLeapYear,
|
|
1520
|
-
isMod,
|
|
1521
3081
|
isPlainDate,
|
|
1522
3082
|
isPlainDateTime,
|
|
1523
3083
|
isPlainMonthDay,
|
|
@@ -1574,7 +3134,7 @@ export {
|
|
|
1574
3134
|
skip,
|
|
1575
3135
|
splitInterval,
|
|
1576
3136
|
startOf,
|
|
1577
|
-
|
|
3137
|
+
subtract,
|
|
1578
3138
|
subtractBusinessDays,
|
|
1579
3139
|
subtractDays,
|
|
1580
3140
|
subtractDuration,
|