temporal-fmt 0.8.5 → 0.8.7
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 +82 -12
- package/dist/formatDistance.d.cts +18 -0
- package/dist/formatDistance.d.ts +18 -0
- package/dist/formatDuration.d.cts +11 -2
- package/dist/formatDuration.d.ts +11 -2
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/parseRelative.d.cts +27 -15
- package/dist/parseRelative.d.ts +27 -15
- package/dist/tokens.d.cts +1 -0
- package/dist/tokens.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -196,6 +196,12 @@ yourself.
|
|
|
196
196
|
| ww | ISO 8601 week (01-53), format-only | 32 |
|
|
197
197
|
| RRRR | ISO 8601 week-numbering year, format-only | 2026 |
|
|
198
198
|
| zzz | IANA time zone id | America/New_York |
|
|
199
|
+
| X | UTC offset, hours only (or `Z` for UTC); minutes appended when non-zero, no colon | `+05` / `+0530` / `Z` |
|
|
200
|
+
| XX | UTC offset, hours+minutes, no colon (or `Z`) | `+0500` / `Z` |
|
|
201
|
+
| XXX | UTC offset, hours+minutes with colon (or `Z`) | `+05:00` / `Z` |
|
|
202
|
+
| x | same widths as `X` but never `Z` — always numeric, even for UTC | `+05` / `+0530` / `+00` |
|
|
203
|
+
| xx | same as `XX` but never `Z` | `+0500` / `+0000` |
|
|
204
|
+
| xxx | same as `XXX` but never `Z` | `+05:00` / `+00:00` |
|
|
199
205
|
|
|
200
206
|
`do` is format-only (parse() rejects it — the "st"/"nd"/"rd"/"th" suffix isn't structurally distinguishable from adjacent literal text in a parse context). The English-only suffix rule is on purpose — locale-aware ordinals are out of scope; `Intl.DateTimeFormat` has no part type for ordinals, and the rest of this library routes locale-specific names through it.
|
|
201
207
|
|
|
@@ -205,6 +211,10 @@ yourself.
|
|
|
205
211
|
|
|
206
212
|
`RRRR` is the **ISO week-numbering year**, not the calendar year — they can differ at year boundaries. Dec 29-31 often belong to week 1 of the *next* year; Jan 1-3 often belong to week 52/53 of the *previous* year. Examples: `format(PlainDate.from('2026-12-31'), 'ww RRRR')` → `"53 2026"`; `format(PlainDate.from('2027-01-01'), 'ww RRRR')` → `"53 2026"` (Friday in ISO year 2026's week 53); `format(PlainDate.from('2027-01-04'), 'ww RRRR')` → `"01 2027"` (Monday starting ISO week 1 of 2027).
|
|
207
213
|
|
|
214
|
+
The six offset tokens (`X`/`XX`/`XXX`/`x`/`xx`/`xxx`) are the standard date-fns/Unicode-LDML UTC offset family. They only work on `ZonedDateTime`; on a `PlainDate`/`PlainTime`/`PlainDateTime` they throw the same "requires offset, which this Temporal object doesn't have" error the other field-typed tokens throw when their field is missing. Uppercase variants (`X`/`XX`/`XXX`) collapse `+00:00` to `Z` for UTC; lowercase variants (`x`/`xx`/`xxx`) always emit a numeric offset, even for UTC (`+00`, `+0000`, `+00:00`). `X` and `x` (single-letter) drop minutes when zero (`+05` rather than `+0500`) and append them with no colon when non-zero (`+0530`) — matches the LDML spec's "hours required, minutes optional when zero" rule.
|
|
215
|
+
|
|
216
|
+
On parse, an offset token requires a full date and time (year, month, day, and at least one time token) to anchor the instant, same rule `zzz` already enforces. A pattern with an offset token but no `zzz` produces a `ZonedDateTime` whose `timeZoneId` is the offset string itself (e.g. `"+09:00"`). A pattern with **both** `zzz` and an offset token is a cross-check: `zzz` wins for the result's `timeZoneId` (the IANA name is the meaningful label; the offset is a derived fact about that zone at this instant), and the offset token's value must match the zone's actual offset at the parsed wall-clock instant. If they disagree — e.g. `yyyy-MM-dd HH:mm zzz XXX` against `2026-08-04 15:45 America/New_York +09:00` (August in New York is `-04:00`, not `+09:00`) — parse() throws rather than silently picking one, same contract as the EEEE-vs-date and Q-vs-month cross-checks elsewhere in this library. Range checks: `-12:00` to `+14:00` (the IANA-supported range). Out-of-range values throw a descriptive error naming the bound, not a generic "no valid pattern matches".
|
|
217
|
+
|
|
208
218
|
Try to use a token your input type doesn't support — `HH` on a `PlainDate`,
|
|
209
219
|
say — and you'll get a real error telling you so, not a silent `undefined`
|
|
210
220
|
sitting in your output waiting to confuse someone in three weeks.
|
|
@@ -238,7 +248,18 @@ formatDuration({ hours: 2, minutes: 30 }, 'h:mm') // "2:30"
|
|
|
238
248
|
|
|
239
249
|
**Zero-value handling**: by default, zero-value units are omitted from the output. `formatDuration({ hours: 2 }, 'hhh mmm')` returns `"2 hours "` (the trailing space is the literal separator from the format string — the codemod doesn't do separator cleanup; the caller is responsible for structuring the format string). Pass `{ showZeroValues: true }` to force zero-value units to render.
|
|
240
250
|
|
|
241
|
-
|
|
251
|
+
**Locale-aware unit names**: pass a `locale` option to localize the short/long forms via `Intl.NumberFormat`'s `style: 'unit'` mode — same approach `formatDistance` uses for `Intl.RelativeTimeFormat`. Numeric-only tokens (`y`, `o`, `w`, ...) stay ASCII digits regardless of locale, matching the rest of the library's "numbers stay Western" convention.
|
|
252
|
+
|
|
253
|
+
```js
|
|
254
|
+
formatDuration({ hours: 2, minutes: 30 }, 'hhh mmm', { locale: 'fr-FR' }) // "2 heures 30 minutes"
|
|
255
|
+
formatDuration({ hours: 2, minutes: 30 }, 'hhh mmm', { locale: 'es-ES' }) // "2 horas 30 minutos"
|
|
256
|
+
formatDuration({ hours: 2, minutes: 30 }, 'hhh mmm', { locale: 'de-DE' }) // "2 Stunden 30 Minuten"
|
|
257
|
+
formatDuration({ milliseconds: 5 }, 'SSS', { locale: 'fr-FR' }) // "5 millisecondes"
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Without a `locale`, the original English hardcoded singular/plural table is used — byte-identical to previous versions. This is additive: existing calls with no `locale` produce the same output as before. (Passing `locale: 'en-US'` explicitly is *not* identical to no-locale — Intl's spacing differs from the hand-rolled English table, e.g. `"2 hr"` vs `"2h"`. Pick the path that matches your needs.)
|
|
261
|
+
|
|
262
|
+
Milliseconds *are* supported by `Intl.NumberFormat`'s unit list on every Node version this library targets — confirmed against the current Intl spec, not assumed. The original task brief flagged this as a possible gap; empirically it isn't.
|
|
242
263
|
|
|
243
264
|
## Relative time: formatDistance
|
|
244
265
|
|
|
@@ -258,19 +279,30 @@ formatDistance(today, today.add({ days: 2 }), { locale: 'fr-FR' }) // "dans 2 jo
|
|
|
258
279
|
|
|
259
280
|
**Direction convention**: `diff = date1 - date2`. Positive diff → date1 is in the future relative to date2 → "in X". Negative diff → date1 is in the past → "X ago". Swap the args to flip the direction.
|
|
260
281
|
|
|
261
|
-
**Unit-selection cutoffs** (documented
|
|
282
|
+
**Unit-selection cutoffs** (defaults documented below; per-call override via the `cutoffs` option):
|
|
262
283
|
|
|
263
|
-
| abs(diff) | Unit |
|
|
264
|
-
|
|
265
|
-
| < 60 seconds | seconds |
|
|
266
|
-
| < 60 minutes | minutes |
|
|
267
|
-
| < 24 hours | hours |
|
|
268
|
-
| < 30 days | days |
|
|
269
|
-
| < 365 days | months |
|
|
270
|
-
| otherwise | years |
|
|
284
|
+
| abs(diff) | Unit | Default cutoff |
|
|
285
|
+
|-----------|------|----------------|
|
|
286
|
+
| < 60 seconds | seconds | `seconds: 60` |
|
|
287
|
+
| < 60 minutes | minutes | `minutes: 60` |
|
|
288
|
+
| < 24 hours | hours | `hours: 24` |
|
|
289
|
+
| < 30 days | days | `days: 30` |
|
|
290
|
+
| < 365 days | months | `months: 365` (in days — see note) |
|
|
291
|
+
| otherwise | years | — |
|
|
271
292
|
|
|
272
293
|
30 days is an approximation of a month (calendar months are 28-31 days); 365 days is an approximation of a year. These are the same cutoffs date-fns uses, trimmed to the units `Intl.RelativeTimeFormat` supports across engines.
|
|
273
294
|
|
|
295
|
+
The `months` cutoff is in days, not months — "months" itself isn't a fixed number of days, so the months→years boundary is expressed as a day count, matching how the original hardcoded table expressed the same boundary (`30 * MS_PER_DAY` for days, `365 * MS_PER_DAY` for the months cap). This lets a caller say "treat anything under 90 days as months" rather than "anything under 3 months as months" (which would require picking a definition of "month").
|
|
296
|
+
|
|
297
|
+
Override any subset of the boundaries per call. Unspecified boundaries fall back to the defaults above. Throws descriptively on non-monotonic boundaries (e.g. `seconds: 300, minutes: 1` — 300s > 1min, so the seconds branch would always win and the minutes branch would be unreachable) or non-positive values, rather than producing confusing output downstream.
|
|
298
|
+
|
|
299
|
+
```js
|
|
300
|
+
formatDistance(in5d, today) // "in 5 days" (default cutoffs)
|
|
301
|
+
formatDistance(in14d, today, { cutoffs: { days: 10 } }) // "this month" (14d > 10d)
|
|
302
|
+
formatDistance(in200d, today, { cutoffs: { months: 100 } }) // "this year" (200d > 100d)
|
|
303
|
+
formatDistance(in30d, today) // "next month" (exactly at default 30d boundary → next unit up)
|
|
304
|
+
```
|
|
305
|
+
|
|
274
306
|
Accepts `Temporal.PlainDate`, `PlainDateTime`, or `ZonedDateTime`. A `PlainDate` is treated as midnight when diffing against a `PlainDateTime`. Throws on `PlainTime` (no anchor date to diff against) and on partial-date shapes (e.g. `{ year: 2026 }` with no month/day).
|
|
275
307
|
|
|
276
308
|
## Lenient parse mode
|
|
@@ -315,7 +347,7 @@ Registered vocab takes precedence over the `Intl`-derived vocab for that locale
|
|
|
315
347
|
|
|
316
348
|
## parseRelative: natural-language date parsing
|
|
317
349
|
|
|
318
|
-
`parseRelative(input, referenceDate, options?)` resolves common
|
|
350
|
+
`parseRelative(input, referenceDate, options?)` resolves common relative-date phrases against a reference date, returning a `Temporal.PlainDate`. English by default; pass `locale: 'es'` / `'fr'` / `'de'` (or any locale tag with that language subtag) to route to the corresponding grammar.
|
|
319
351
|
|
|
320
352
|
Supported phrases:
|
|
321
353
|
|
|
@@ -324,6 +356,22 @@ Supported phrases:
|
|
|
324
356
|
- **relative unit offsets**: "in 3 days", "2 weeks ago", "in 1 month", "1 year ago"
|
|
325
357
|
- **month-day without year**: "March 5th", "Aug 4" (resolved to next occurrence)
|
|
326
358
|
|
|
359
|
+
Per-language equivalents (each grammar is its own module — phrase patterns and vocabulary are NOT shared across languages, only the matching engine and the resolution helpers are):
|
|
360
|
+
|
|
361
|
+
| Phrase class | es | fr | de |
|
|
362
|
+
|--------------|----|----|-----|
|
|
363
|
+
| today | `hoy` | `aujourd'hui` | `heute` |
|
|
364
|
+
| tomorrow | `mañana` | `demain` | `morgen` |
|
|
365
|
+
| yesterday | `ayer` | `hier` | `gestern` |
|
|
366
|
+
| next Tuesday | `el próximo martes` / `martes próximo` | `mardi prochain` | `nächsten Dienstag` |
|
|
367
|
+
| last Tuesday | `el martes pasado` | `mardi dernier` | `letzten Dienstag` |
|
|
368
|
+
| this Wednesday | `este miércoles` | `ce mercredi` | `diesen Mittwoch` |
|
|
369
|
+
| in 3 days | `en 3 días` | `dans 3 jours` | `in 3 Tagen` |
|
|
370
|
+
| 2 weeks ago | `hace 2 semanas` | `il y a 2 semaines` | `vor 2 Wochen` |
|
|
371
|
+
| March 5 | `5 de marzo` | `5 mars` | `5. März` |
|
|
372
|
+
|
|
373
|
+
Diacritics are stripped before matching (NFD + combining-mark removal), so `"miercoles"` matches the same as `"miércoles"`, `"aout"` as `"août"`, `"naechsten"` as `"nächsten"`. German umlaut transliterations (`ä` → `ae`, `ö` → `oe`, `ü` → `ue`, `ß` → `ss`) are also expanded, so `"5. Maerz"` resolves the same as `"5. März"`.
|
|
374
|
+
|
|
327
375
|
```js
|
|
328
376
|
import { parseRelative } from 'temporal-fmt';
|
|
329
377
|
|
|
@@ -337,12 +385,30 @@ parseRelative('2 weeks ago', today).toString() // '2026-07-21'
|
|
|
337
385
|
parseRelative('March 5th', today).toString() // '2027-03-05' (next occurrence)
|
|
338
386
|
```
|
|
339
387
|
|
|
388
|
+
Per-language examples:
|
|
389
|
+
|
|
390
|
+
```js
|
|
391
|
+
parseRelative('mañana', today, { locale: 'es-ES' }).toString() // '2026-08-05'
|
|
392
|
+
parseRelative('el próximo martes', today, { locale: 'es-ES' }).toString() // '2026-08-11'
|
|
393
|
+
parseRelative('5 de marzo', today, { locale: 'es-ES' }).toString() // '2027-03-05'
|
|
394
|
+
|
|
395
|
+
parseRelative('demain', today, { locale: 'fr-FR' }).toString() // '2026-08-05'
|
|
396
|
+
parseRelative('mardi prochain', today, { locale: 'fr-FR' }).toString() // '2026-08-11'
|
|
397
|
+
parseRelative('5 mars', today, { locale: 'fr-FR' }).toString() // '2027-03-05'
|
|
398
|
+
|
|
399
|
+
parseRelative('morgen', today, { locale: 'de-DE' }).toString() // '2026-08-05'
|
|
400
|
+
parseRelative('nächsten Dienstag', today, { locale: 'de-DE' }).toString() // '2026-08-11'
|
|
401
|
+
parseRelative('5. März', today, { locale: 'de-DE' }).toString() // '2027-03-05'
|
|
402
|
+
```
|
|
403
|
+
|
|
340
404
|
**Ambiguous-case choices** (documented, not inferred):
|
|
341
405
|
|
|
342
406
|
- **"next Tuesday" said on a Tuesday** = 7 days out, not today. "this Tuesday" handles the same-week case, so "next Tuesday" staying strictly-future gives the two phrases distinct, non-overlapping meanings.
|
|
343
407
|
- **"last Tuesday" said on a Tuesday** = 7 days ago (strictly-past, symmetric to "next").
|
|
344
408
|
- **"March 5th" without a year** = next occurrence. Future-leaning: today's date returns today; a past date this year returns next year's occurrence. (The alternative — "nearest in time, past or future" — would mean "March 5th" said on March 6 returns yesterday, which is counterintuitive for the typical "next birthday"/"next deadline" use case.)
|
|
345
|
-
- **"5 days" without "in" or "ago"** = throws. Past or future? parseRelative refuses to guess — same contract as `parse()`'s strict mode.
|
|
409
|
+
- **"5 days" without "in" or "ago"** = throws. Past or future? parseRelative refuses to guess — same contract as `parse()`'s strict mode. Per-language equivalent: bare `"3 días"` / `"3 jours"` / `"3 Tage"` all throw with a localized error message pointing at the disambiguation options (`"en 3 días"`/`"hace 3 días"`, etc.).
|
|
410
|
+
|
|
411
|
+
**Cross-language consistency on the same-day-of-week ambiguity**: the "next X on X = 7 days out, not today" convention holds across all four supported languages (en/es/fr/de). The natural phrasing in each language (`"next Tuesday"` / `"el próximo martes"` / `"mardi prochain"` / `"nächsten Dienstag"`) all resolve to strictly-future-next-week when said on the named weekday. This is a deliberate cross-language convention, not an accident of implementation — if a future language grammar's natural phrasing for "next X" resolves differently by convention, document it in that grammar's section and the README here.
|
|
346
412
|
|
|
347
413
|
Throws a descriptive error for any phrase it doesn't recognize, naming the supported categories in the message. Accepts `PlainDate`, `PlainDateTime`, or `ZonedDateTime` as the reference (needs `dayOfWeek` to compute weekday offsets). Throws on `PlainTime`.
|
|
348
414
|
|
|
@@ -375,6 +441,10 @@ Throws a descriptive error for any phrase it doesn't recognize, naming the suppo
|
|
|
375
441
|
bare `Md` format string is incomplete regardless of ambiguity. The
|
|
376
442
|
examples above use `yyyy-Md` for exactly this reason.
|
|
377
443
|
|
|
444
|
+
- Offset tokens (`X`/`XX`/`XXX`/`x`/`xx`/`xxx`) read `ZonedDateTime.prototype.offset`, which Temporal exposes as a `+HH:MM` string for any modern date. Historical LMT (Local Mean Time) offsets with seconds — e.g. Europe/London before 1847, when it was `+00:01:15` — aren't reachable through that field, and the regex shapes the offset tokens accept don't include a seconds group either. If you need to round-trip a sub-minute historical offset, you're outside what the offset tokens can express; construct the `ZonedDateTime` directly.
|
|
445
|
+
|
|
446
|
+
Range is bounded to `-12:00` through `+14:00`, the IANA-supported range (Baker Island at `-12:00`, Kiritimati at `+14:00`). `+14:01` and `-12:01` throw with a descriptive error even though each piece alone is in bounds — the overall offset exceeds the maximum any real zone uses.
|
|
447
|
+
|
|
378
448
|
## Dev notes
|
|
379
449
|
|
|
380
450
|
Building requires TypeScript 7.0.2+ but `.d.ts` generation runs as a separate
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { type FormatOptions } from './tokens.cjs';
|
|
2
|
+
export interface DistanceCutoffs {
|
|
3
|
+
seconds?: number;
|
|
4
|
+
minutes?: number;
|
|
5
|
+
hours?: number;
|
|
6
|
+
days?: number;
|
|
7
|
+
months?: number;
|
|
8
|
+
}
|
|
2
9
|
export interface FormatDistanceOptions extends FormatOptions {
|
|
3
10
|
/**
|
|
4
11
|
* 'auto' (default) lets Intl.RelativeTimeFormat use natural forms like
|
|
@@ -6,6 +13,17 @@ export interface FormatDistanceOptions extends FormatOptions {
|
|
|
6
13
|
* 'always' forces the strict "1 day ago"/"in 1 day"/"in 0 seconds" form.
|
|
7
14
|
*/
|
|
8
15
|
numeric?: 'always' | 'auto';
|
|
16
|
+
/**
|
|
17
|
+
* Override the unit-selection boundaries (seconds→minutes,
|
|
18
|
+
* minutes→hours, hours→days, days→months, months→years). Any
|
|
19
|
+
* subset can be supplied; omitted boundaries fall back to the
|
|
20
|
+
* defaults (60s, 60min, 24h, 30d, 365d). Values are in each
|
|
21
|
+
* unit's native scale except `months`, which is in days — see
|
|
22
|
+
* DistanceCutoffs. Throws descriptively on non-monotonic
|
|
23
|
+
* boundaries or non-positive values, rather than producing
|
|
24
|
+
* confusing output downstream.
|
|
25
|
+
*/
|
|
26
|
+
cutoffs?: DistanceCutoffs;
|
|
9
27
|
}
|
|
10
28
|
/**
|
|
11
29
|
* Returns a human-readable relative-time string describing `date1`
|
package/dist/formatDistance.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { type FormatOptions } from './tokens.js';
|
|
2
|
+
export interface DistanceCutoffs {
|
|
3
|
+
seconds?: number;
|
|
4
|
+
minutes?: number;
|
|
5
|
+
hours?: number;
|
|
6
|
+
days?: number;
|
|
7
|
+
months?: number;
|
|
8
|
+
}
|
|
2
9
|
export interface FormatDistanceOptions extends FormatOptions {
|
|
3
10
|
/**
|
|
4
11
|
* 'auto' (default) lets Intl.RelativeTimeFormat use natural forms like
|
|
@@ -6,6 +13,17 @@ export interface FormatDistanceOptions extends FormatOptions {
|
|
|
6
13
|
* 'always' forces the strict "1 day ago"/"in 1 day"/"in 0 seconds" form.
|
|
7
14
|
*/
|
|
8
15
|
numeric?: 'always' | 'auto';
|
|
16
|
+
/**
|
|
17
|
+
* Override the unit-selection boundaries (seconds→minutes,
|
|
18
|
+
* minutes→hours, hours→days, days→months, months→years). Any
|
|
19
|
+
* subset can be supplied; omitted boundaries fall back to the
|
|
20
|
+
* defaults (60s, 60min, 24h, 30d, 365d). Values are in each
|
|
21
|
+
* unit's native scale except `months`, which is in days — see
|
|
22
|
+
* DistanceCutoffs. Throws descriptively on non-monotonic
|
|
23
|
+
* boundaries or non-positive values, rather than producing
|
|
24
|
+
* confusing output downstream.
|
|
25
|
+
*/
|
|
26
|
+
cutoffs?: DistanceCutoffs;
|
|
9
27
|
}
|
|
10
28
|
/**
|
|
11
29
|
* Returns a human-readable relative-time string describing `date1`
|
|
@@ -18,10 +18,19 @@ export interface DurationFormatOptions extends FormatOptions {
|
|
|
18
18
|
* Zero-value units are omitted by default; pass { showZeroValues: true }
|
|
19
19
|
* to force them to appear.
|
|
20
20
|
*
|
|
21
|
+
* Unit-name localization: without a `locale`, output is the original
|
|
22
|
+
* English hardcoded singular/plural forms (byte-identical to previous
|
|
23
|
+
* versions). With a `locale`, the short/long forms delegate to
|
|
24
|
+
* `Intl.NumberFormat`'s `style: 'unit'` — same approach `formatDistance`
|
|
25
|
+
* already uses for `Intl.RelativeTimeFormat`. Numeric-only tokens
|
|
26
|
+
* (`y`, `o`, `w`, ...) are not affected by `locale`; they remain ASCII
|
|
27
|
+
* digits, matching the rest of this library's "numbers stay Western"
|
|
28
|
+
* convention.
|
|
29
|
+
*
|
|
21
30
|
* @example
|
|
22
31
|
* formatDuration(Temporal.Duration.from({ years: 2, months: 1 }), 'yyy ooo')
|
|
23
32
|
* // "2 years 1 month"
|
|
24
|
-
* formatDuration({ hours: 2, minutes: 30 }, 'hhh mmm')
|
|
25
|
-
* // "2
|
|
33
|
+
* formatDuration({ hours: 2, minutes: 30 }, 'hhh mmm', { locale: 'fr-FR' })
|
|
34
|
+
* // "2 heures 30 minutes"
|
|
26
35
|
*/
|
|
27
36
|
export declare function formatDuration(duration: Record<string, unknown>, formatStr: string, options?: DurationFormatOptions): string;
|
package/dist/formatDuration.d.ts
CHANGED
|
@@ -18,10 +18,19 @@ export interface DurationFormatOptions extends FormatOptions {
|
|
|
18
18
|
* Zero-value units are omitted by default; pass { showZeroValues: true }
|
|
19
19
|
* to force them to appear.
|
|
20
20
|
*
|
|
21
|
+
* Unit-name localization: without a `locale`, output is the original
|
|
22
|
+
* English hardcoded singular/plural forms (byte-identical to previous
|
|
23
|
+
* versions). With a `locale`, the short/long forms delegate to
|
|
24
|
+
* `Intl.NumberFormat`'s `style: 'unit'` — same approach `formatDistance`
|
|
25
|
+
* already uses for `Intl.RelativeTimeFormat`. Numeric-only tokens
|
|
26
|
+
* (`y`, `o`, `w`, ...) are not affected by `locale`; they remain ASCII
|
|
27
|
+
* digits, matching the rest of this library's "numbers stay Western"
|
|
28
|
+
* convention.
|
|
29
|
+
*
|
|
21
30
|
* @example
|
|
22
31
|
* formatDuration(Temporal.Duration.from({ years: 2, months: 1 }), 'yyy ooo')
|
|
23
32
|
* // "2 years 1 month"
|
|
24
|
-
* formatDuration({ hours: 2, minutes: 30 }, 'hhh mmm')
|
|
25
|
-
* // "2
|
|
33
|
+
* formatDuration({ hours: 2, minutes: 30 }, 'hhh mmm', { locale: 'fr-FR' })
|
|
34
|
+
* // "2 heures 30 minutes"
|
|
26
35
|
*/
|
|
27
36
|
export declare function formatDuration(duration: Record<string, unknown>, formatStr: string, options?: DurationFormatOptions): string;
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var me=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var je=(e,t)=>{for(var n in t)me(e,n,{get:t[n],enumerable:!0})},ze=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ze(t))!He.call(e,o)&&o!==n&&me(e,o,{get:()=>t[o],enumerable:!(r=Ye(t,o))||r.enumerable});return e};var Ke=e=>ze(me({},"__esModule",{value:!0}),e);var Kt={};je(Kt,{format:()=>Me,formatDistance:()=>Ce,formatDuration:()=>Re,parse:()=>Oe,parseRelative:()=>Ie,registerLocaleVocab:()=>De,setTemporal:()=>Te});module.exports=Ke(Kt);var be,ke=[];function Ee(e){ke.push(e)}function Te(e){be=e;for(let t of ke)t()}function We(){return be??globalThis.Temporal}function F(){let e=We();if(!e)throw new Error("temporal-fmt: parse() needs a Temporal implementation to construct its result. Call setTemporal(Temporal) once at startup, or assign one to globalThis.Temporal (native on Node 26+, or a polyfill like temporal-polyfill).");return e}var ue=new Map;function Qe(e,t){let n=[{key:"monthLong",length:12,label:"long month names"},{key:"monthShort",length:12,label:"short month names"},{key:"weekdayLong",length:7,label:"long weekday names"},{key:"weekdayShort",length:7,label:"short weekday names"},{key:"dayPeriod",length:2,label:"day period markers (AM/PM-equivalent)"}];for(let{key:r,length:o,label:a}of n){let i=e[r];if(i===void 0)throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}" is missing required field "${r}" (${a}).`);if(!Array.isArray(i))throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}": "${r}" must be an array, got ${typeof i}.`);if(i.length!==o)throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}": "${r}" must have exactly ${o} entries (got ${i.length}) \u2014 ${a}.`);i.forEach((s,m)=>{if(typeof s!="string"||s.length===0)throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}": "${r}[${m}]" must be a non-empty string, got ${String(s)}.`)})}if(D(e.monthLong,"MMMM month",t),D(e.monthShort,"MMM month",t),D(e.weekdayLong,"EEEE weekday",t),D(e.weekdayShort,"EEE weekday",t),e.dayPeriod[0]===e.dayPeriod[1])throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}": dayPeriod entries must differ (both are "${e.dayPeriod[0]}"); otherwise parse() can't tell AM from PM.`)}function De(e,t){if(typeof e!="string"||e.length===0)throw new Error(`temporal-fmt: registerLocaleVocab requires a non-empty locale string, got ${String(e)}.`);Qe(t,e);let n=M(e);ue.set(n,{monthLong:[...t.monthLong],monthShort:[...t.monthShort],weekdayLong:[...t.weekdayLong],weekdayShort:[...t.weekdayShort],dayPeriod:[...t.dayPeriod]}),L.delete(n)}function M(e){try{return new Intl.Locale(e.replace(/_/g,"-")).toString().toLowerCase()}catch{return e}}var L=new Map,qe=500;function $(e,t,n){let r=e.formatToParts(t),o=r.findIndex(m=>m.type===n);if(o===-1)throw new Error(`temporal-fmt: locale produced no "${n}" part while building match vocabulary.`);let a=r[o].value,i=r[o-1],s=r[o+1];return i?.type==="literal"&&!/\s/.test(i.value)&&(a=i.value+a),s?.type==="literal"&&!/\s/.test(s.value)&&(a=a+s.value),a}function D(e,t,n){let r=new Map;for(let o=0;o<e.length;o++){let a=r.get(e[o]);if(a!==void 0)throw new Error(`temporal-fmt: locale "${n}" renders ${t} index ${a} and ${o} identically ("${e[o]}"). parse() can't reliably tell these apart for this locale/token, so this combination isn't supported.`);r.set(e[o],o)}}function O(e){let t=M(e);return ue.get(t)}function N(e){let t=M(e),n=ue.get(t);if(n)return n;let r=L.get(t);if(r)return r;let o=new Intl.DateTimeFormat(e,{month:"long",timeZone:"UTC"}),a=new Intl.DateTimeFormat(e,{month:"short",timeZone:"UTC"}),i=[],s=[];for(let w=0;w<12;w++){let x=new Date(Date.UTC(2020,w,1));i.push($(o,x,"month")),s.push($(a,x,"month"))}D(i,"MMMM month",e),D(s,"MMM month",e);let m=new Intl.DateTimeFormat(e,{weekday:"long",timeZone:"UTC"}),l=new Intl.DateTimeFormat(e,{weekday:"short",timeZone:"UTC"}),u=[],c=[];for(let w=0;w<7;w++){let x=new Date(Date.UTC(2024,0,1+w));u.push($(m,x,"weekday")),c.push($(l,x,"weekday"))}D(u,"EEEE weekday",e),D(c,"EEE weekday",e);let d=new Intl.DateTimeFormat(e,{hour:"numeric",hour12:!0,timeZone:"UTC"}),f=$(d,new Date(Date.UTC(2020,0,1,1)),"dayPeriod"),y=$(d,new Date(Date.UTC(2020,0,1,13)),"dayPeriod"),S=[...new Set([f,y])],b={monthLong:i,monthShort:s,weekdayLong:u,weekdayShort:c,dayPeriod:S};if(L.size>=qe){let w=L.keys().next().value;w!==void 0&&L.delete(w)}return L.set(t,b),b}var Ge=[0,31,59,90,120,151,181,212,243,273,304,334];function C(e){return e%4===0&&e%100!==0||e%400===0}function A(e){return C(e)?366:365}function ce(e,t,n){let r=Ge[t-1]+n;return t>2&&C(e)&&(r+=1),r}var de=2e3;function Xe(e){let t=0;if(e>=de)for(let r=de;r<e;r++)t+=A(r);else for(let r=e;r<de;r++)t-=A(r);return((5+t)%7+7)%7+1}function le(e,t,n,r){let a=ce(e,t,n)+(4-r),i,s;a<1?(i=e-1,s=a+A(i)):a>A(e)?(i=e+1,s=a-A(e)):(i=e,s=a);let l=1+(4-Xe(i)+7)%7,u=1+Math.floor((s-l)/7);return{isoYear:i,week:u}}function g(e,t){let n=e<0,r=String(Math.abs(e)).padStart(t,"0");return n?"-"+r:r}g.fraction=function(t,n){let r=t.millisecond*1e6+(t.microsecond??0)*1e3+(t.nanosecond??0);return g(r,9).slice(0,n)};var R="en-US",I=new Map,Be=500;function xe(e,t){let n=JSON.stringify([M(e),t]),r=I.get(n);if(r)return r;if(I.size>=Be){let o=I.keys().next().value;o!==void 0&&I.delete(o)}return r=new Intl.DateTimeFormat(e,t),I.set(n,r),r}var U;Ee(()=>{U=void 0});function Je(){if(U===void 0){U=!1;try{let e=F();new Intl.DateTimeFormat("en-US",{day:"numeric"}).formatToParts(e.PlainDate.from({year:1970,month:1,day:1})),U=!0}catch{}}return U}function et(e,t,n,r){let o=e?.calendarId,a={...n,calendar:o&&o!=="iso8601"?o:"gregory"};if(!Je())return e.toLocaleString(t,a);let{toInstant:i,timeZoneId:s}=e,m=typeof i=="function"&&typeof s=="string",l=m?e.toInstant():e,u={...a,...m?{timeZone:s}:{}},d=xe(t,u).formatToParts(l),f=d.findIndex(w=>w.type===r);if(f===-1)throw new Error(`temporal-fmt: locale "${t}" produced no "${r}" part for this token. This usually means the Temporal object is missing the field the token needs.`);let y=d[f].value,S=d[f-1],b=d[f+1];return S?.type==="literal"&&!/\s/.test(S.value)&&(y=S.value+y),b?.type==="literal"&&!/\s/.test(b.value)&&(y=y+b.value),y}function tt(e,t){let n=O(t);if(n)return e<12?n.dayPeriod[0]:n.dayPeriod[1];let r=new Date(Date.UTC(1970,0,1,e)),a=xe(t,{hour:"numeric",hour12:!0,timeZone:"UTC"}).formatToParts(r).find(i=>i.type==="dayPeriod");if(!a)throw new Error(`temporal-fmt: locale "${t}" produced no "dayPeriod" part for token "a".`);return a.value}function K(e,t,n,r,o,a){return o&&a!==void 0&&a>=0&&a<o.length?o[a]:et(e,t,n,r)}var W=[["yyyy",e=>g(e.year,4),"year"],["yy",e=>{if(e.year<0)throw new Error(`temporal-fmt: token "yy" doesn't support negative years (got ${e.year}), since truncating to 2 digits would make it indistinguishable from a positive year. Use "yyyy" instead.`);return g(e.year%100,2)},"year"],["MMMM",(e,t)=>{let n=O(t);return K(e,t,{month:"long"},"month",n?.monthLong,e.month-1)},"month"],["MMM",(e,t)=>{let n=O(t);return K(e,t,{month:"short"},"month",n?.monthShort,e.month-1)},"month"],["MM",e=>g(e.month,2),"month"],["M",e=>String(e.month),"month"],["dd",e=>g(e.day,2),"day"],["d",e=>String(e.day),"day"],["EEEE",(e,t)=>{let n=O(t);return K(e,t,{weekday:"long"},"weekday",n?.weekdayLong,e.dayOfWeek-1)},"dayOfWeek"],["EEE",(e,t)=>{let n=O(t);return K(e,t,{weekday:"short"},"weekday",n?.weekdayShort,e.dayOfWeek-1)},"dayOfWeek"],["HH",e=>g(e.hour,2),"hour"],["H",e=>String(e.hour),"hour"],["hh",e=>g(e.hour%12||12,2),"hour"],["h",e=>String(e.hour%12||12),"hour"],["mm",e=>g(e.minute,2),"minute"],["m",e=>String(e.minute),"minute"],["ss",e=>g(e.second,2),"second"],["s",e=>String(e.second),"second"],["SSSSSSSSS",e=>g.fraction(e,9),"millisecond"],["SSSSSSSS",e=>g.fraction(e,8),"millisecond"],["SSSSSSS",e=>g.fraction(e,7),"millisecond"],["SSSSSS",e=>g.fraction(e,6),"millisecond"],["SSSSS",e=>g.fraction(e,5),"millisecond"],["SSSS",e=>g.fraction(e,4),"millisecond"],["SSS",e=>g.fraction(e,3),"millisecond"],["SS",e=>g.fraction(e,2),"millisecond"],["S",e=>g.fraction(e,1),"millisecond"],["a",(e,t)=>tt(e.hour,t),"hour"],["zzz",e=>e.timeZoneId,"timeZoneId"],["do",e=>{let t=e.day,n=t%10,r=t%100;return r>=11&&r<=13?t+"th":n===1?t+"st":n===2?t+"nd":n===3?t+"rd":t+"th"},"day"],["Q",e=>String(Math.ceil(e.month/3)),"month"],["QQQ",e=>"Q"+Math.ceil(e.month/3),"month"],["ww",e=>{let{week:t}=le(e.year,e.month,e.day,e.dayOfWeek);return g(t,2)},"dayOfWeek"],["RRRR",e=>{let{isoYear:t}=le(e.year,e.month,e.day,e.dayOfWeek);return g(t,4)},"dayOfWeek"]];var nt=W.map(([e])=>e).sort((e,t)=>t.length-e.length);function Q(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r==="'"){if(e[n+1]==="'"){fe(t,"'"),n+=2;continue}let a=n+1,i="",s=!1;for(;a<e.length;){if(e[a]==="'"){if(e[a+1]==="'"){i+="'",a+=2;continue}s=!0,a+=1;break}i+=e[a],a+=1}if(!s)throw new Error(`temporal-fmt: unterminated quote in format string "${e}"`);fe(t,i),n=a;continue}let o=nt.find(a=>e.startsWith(a,n));if(o){t.push({kind:"token",value:o}),n+=o.length;continue}fe(t,r),n+=1}return t}function fe(e,t){let n=e[e.length-1];n&&n.kind==="literal"?n.value+=t:e.push({kind:"literal",value:t})}var rt=new Map(W.map(([e,t,n])=>[e,{fn:t,field:n}]));function Me(e,t,n={}){if(t.length>1e3)throw new Error(`temporal-fmt: format string exceeds maximum length of ${1e3} characters (got ${t.length}).`);let r=n.locale??R,o=Q(t),a="";for(let i of o){if(i.kind==="literal"){a+=i.value;continue}let s=rt.get(i.value);if(!s)throw new Error(`temporal-fmt: unknown token "${i.value}"`);if(e[s.field]===void 0)throw new Error(`temporal-fmt: token "${i.value}" requires "${s.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`);a+=s.fn(e,r)}return a}function ot(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Y(e,t=!1){let n=e.map(ot);return t?`(?:${n.map(at).join("|")})`:`(?:${n.join("|")})`}function at(e){return e.replace(/[a-zA-Z]/g,t=>`[${t.toLowerCase()}${t.toUpperCase()}]`)}var it="(?:UTC|[+-]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d{1,9})?)?|[A-Za-z_]+(?:[+-]\\d{1,2})?(?:\\/[A-Za-z0-9_+-]+)*)";function st(){return it}var q;function mt(){return q||(q=new Set(Intl.supportedValuesOf("timeZone")),q.add("UTC")),q}var ut=/^[+-]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?$/;function Pe(e){return ut.test(e)||mt().has(e)}var dt={yy:"\\d{2}",MM:"(?:0[1-9]|1[0-2])",M:"(?:1[0-2]|[1-9])",dd:"(?:0[1-9]|[12]\\d|3[01])",d:"(?:[12]\\d|3[01]|[1-9])",HH:"(?:[01]\\d|2[0-3])",H:"(?:1\\d|2[0-3]|[0-9])",hh:"(?:0[1-9]|1[0-2])",h:"(?:1[0-2]|[1-9])",mm:"(?:[0-5]\\d)",m:"(?:[1-5]\\d|[0-9])",ss:"(?:[0-5]\\d)",s:"(?:[1-5]\\d|[0-9])",SSSSSSSSS:"\\d{9}",SSSSSSSS:"\\d{8}",SSSSSSS:"\\d{7}",SSSSSS:"\\d{6}",SSSSS:"\\d{5}",SSSS:"\\d{4}",SSS:"\\d{3}",SS:"\\d{2}",S:"\\d",Q:"[1-4]"},ct="Q[1-4]",lt=new Set(["do","ww","RRRR"]),ft="-?\\d{4}",ht="-?\\d{4,}",gt=new Set(["yyyy","yy","MM","M","dd","d","HH","H","hh","h","mm","m","ss","s","SSSSSSSSS","SSSSSSSS","SSSSSSS","SSSSSS","SSSSS","SSSS","SSS","SS","S"]);function ve(e,t,n){if(e==="yyyy")return n!==void 0&>.has(n)?ft:ht;let r=dt[e];if(r)return r;if(e==="QQQ")return ct;if(lt.has(e))throw new Error(`temporal-fmt: token "${e}" is format-only \u2014 it can't be parsed back into a value. Use a different token in the parse format string (e.g. "d" for "do", "MM" for "ww").`);let o=N(t);switch(e){case"MMMM":return Y(o.monthLong);case"MMM":return Y(o.monthShort);case"EEEE":return Y(o.weekdayLong);case"EEE":return Y(o.weekdayShort);case"a":return Y(o.dayPeriod,!0);case"zzz":return st();default:throw new Error(`temporal-fmt: unknown token "${e}"`)}}var Fe=new Set(["M","d","H","h","m","s"]),pt={M:[{digits:1,min:1,max:9},{digits:2,min:10,max:12}],d:[{digits:1,min:1,max:9},{digits:2,min:10,max:31}],H:[{digits:1,min:0,max:9},{digits:2,min:10,max:23}],h:[{digits:1,min:1,max:9},{digits:2,min:10,max:12}],m:[{digits:1,min:0,max:9},{digits:2,min:10,max:59}],s:[{digits:1,min:0,max:9},{digits:2,min:10,max:59}]};function $e(e,t){let n=new Map;function r(o,a){let i=`${o}:${a}`,s=n.get(i);if(s)return s;if(o===t.length){let c=a===e.length?[[]]:[];return n.set(i,c),c}let m=t[o],l=pt[m];if(!l)throw new Error(`temporal-fmt: internal error \u2014 "${m}" is not an unpadded numeric token`);let u=[];for(let{digits:c,min:d,max:f}of l){if(a+c>e.length)continue;let y=e.slice(a,a+c);if(c===2&&y[0]==="0")continue;let S=Number(y);if(!(S<d||S>f)){for(let b of r(o+1,a+c))if(u.push([S,...b]),u.length===2)break;if(u.length===2)break}}return n.set(i,u),u}return r(0,0)}function yt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Le(e,t){let n=[],r=[],o="",a=0,i={groupNames:[],tokens:[]},s=()=>{i.tokens.length>=2&&r.push(i),i={groupNames:[],tokens:[]}};for(let[m,l]of e.entries()){if(l.kind==="literal"){o+=yt(l.value),s();continue}let u=`g${a++}`;n.push({name:u,token:l.value});let c=e[m+1],d=c?.kind==="token"?c.value:void 0;o+=`(?<${u}>${ve(l.value,t,d)})`,Fe.has(l.value)?(i.groupNames.push(u),i.tokens.push(l.value)):s()}return s(),{regex:new RegExp(`^(?:${o})$`,"u"),groups:n,ambiguousRuns:r}}var Z=new Map,St=500;function bt(e,t){let n=JSON.stringify([M(t),e]),r=Z.get(n);if(r)return r;if(Z.size>=St){let o=Z.keys().next().value;o!==void 0&&Z.delete(o)}return r=Le(Q(e),t),Z.set(n,r),r}var _=new Map,kt=500;function Et(e){let t=new Intl.Locale(e).toString().toLowerCase();if(_.has(t))return _.get(t);if(_.size>=kt){let i=_.keys().next().value;i!==void 0&&_.delete(i)}let n,r=t.split("-"),o=r.indexOf("u"),a=o===-1?-1:r.indexOf("ca",o+1);if(a!==-1&&a+1<r.length){let i=new Intl.DateTimeFormat(t).resolvedOptions().calendar;n=i==="gregory"?void 0:i}return _.set(t,n),n}function h(e,t,n){e[t]=n}function Tt(e,t,n,r,o){let a=N(r);switch(t){case"yyyy":h(e,"year",Number(n));break;case"yy":h(e,"twoDigitYear",Number(n));break;case"MM":case"M":h(e,"month",Number(n));break;case"MMMM":h(e,"month",a.monthLong.indexOf(n)+1);break;case"MMM":h(e,"month",a.monthShort.indexOf(n)+1);break;case"dd":case"d":h(e,"day",Number(n));break;case"EEEE":h(e,"weekdayRaw",n),h(e,"weekdayExpected",a.weekdayLong.indexOf(n)+1);break;case"EEE":h(e,"weekdayRaw",n),h(e,"weekdayExpected",a.weekdayShort.indexOf(n)+1);break;case"HH":case"H":h(e,"hour",Number(n));break;case"hh":case"h":h(e,"hour12",Number(n));break;case"mm":case"m":h(e,"minute",Number(n));break;case"ss":case"s":h(e,"second",Number(n));break;case"S":case"SS":case"SSS":case"SSSS":case"SSSSS":case"SSSSSS":case"SSSSSSS":case"SSSSSSSS":case"SSSSSSSSS":{let i=Number(n.padEnd(9,"0"));h(e,"millisecond",Math.floor(i/1e6)),h(e,"microsecond",Math.floor(i/1e3)%1e3),h(e,"nanosecond",i%1e3);break}case"a":{let i=a.dayPeriod.findIndex(s=>s.toLowerCase()===n.toLowerCase());if(i<0)throw new Error(`temporal-fmt: unknown day period "${n}" for locale "${r}".`);h(e,"dayPeriodRaw",n),h(e,"isPM",i===1);break}case"zzz":h(e,"timeZoneId",n);break;case"Q":h(e,"quarter",Number(n));break;case"QQQ":h(e,"quarter",Number(n.slice(1)));break}}function Dt(e,t){let n=t.indexOf("d");if(n!==-1){let r=e.filter(o=>o[n]<=12);if(r.length>0)return r[0]}return e[0]}function xt(e){if(e.year!==void 0&&e.twoDigitYear!==void 0)throw new Error('temporal-fmt: format string mixes "yyyy" and "yy" year representations.');if(e.year!==void 0)return e.year;if(e.twoDigitYear!==void 0)return e.twoDigitYear<=68?2e3+e.twoDigitYear:1900+e.twoDigitYear}function Mt(e,t,n){if(e.hour!==void 0&&e.hour12!==void 0)throw new Error(`temporal-fmt: format string "${t}" mixes a 24-hour token ("HH"/"H") with a 12-hour token ("hh"/"h").`);if(e.hour!==void 0){if(e.dayPeriodRaw!==void 0){let r=N(n),o=e.hour<12?r.dayPeriod[0]:r.dayPeriod[1];if(e.dayPeriodRaw.toLowerCase()!==o?.toLowerCase())throw new Error(`temporal-fmt: format string "${t}" contains a day period that contradicts the 24-hour value.`)}return e.hour}if(e.hour12!==void 0){if(e.isPM===void 0)throw new Error(`temporal-fmt: format string "${t}" uses a 12-hour token ("hh"/"h") without an "a" token, so parse() can't tell AM from PM.`);return e.hour12%12+(e.isPM?12:0)}}function Oe(e,t,n={}){if(e.length>1e3)throw new Error(`temporal-fmt: format string exceeds maximum length of ${1e3} characters (got ${e.length}).`);if(t.length>1e5)throw new Error(`temporal-fmt: input exceeds maximum length of ${1e5} characters (got ${t.length}).`);let r=n.locale??R,o=Et(r),a=bt(e,r),i=a.regex.exec(t);if(!i)throw new Error("temporal-fmt: no valid pattern matches the format string and input shape");if(a.groups.length===0)throw new Error(`temporal-fmt: format string "${e}" has no tokens \u2014 nothing to parse into a value.`);for(let{name:p,token:k}of a.groups)if(k==="zzz"&&!Pe(i.groups[p]))throw new Error("temporal-fmt: no valid pattern matches the format string and input shape");let s=[];for(let p of a.ambiguousRuns){let k=p.groupNames.map(se=>i.groups[se]).join(""),E=$e(k,p.tokens);if(E.length>1){if(!n.lenient)throw new Error(`temporal-fmt: "${k}" in format string "${e}" is ambiguous \u2014 ${E.length} different ways to read tokens "${p.tokens.join("")}" (with no separator between them) are all individually valid (e.g. ${JSON.stringify(E[0])} vs ${JSON.stringify(E[1])}). parse() won't guess; add a separator between these tokens, or use their padded form (e.g. "MM" instead of "M") so each one has a fixed width. Pass { lenient: true } to opt into a documented heuristic that picks one.`);s.push({groupNames:p.groupNames,values:Dt(E,p.tokens)})}}let m={},l=new Map;for(let{groupNames:p,values:k}of s)p.forEach((E,se)=>l.set(E,String(k[se])));for(let{name:p,token:k}of a.groups){let E=l.get(p)??i.groups[p];Tt(m,k,E,r,e)}let u=xt(m),c=Mt(m,e,r),{month:d,day:f,minute:y,second:S,millisecond:b,microsecond:w,nanosecond:x,timeZoneId:te,weekdayExpected:ne,weekdayRaw:Ue,quarter:re}=m,Ve=u!==void 0||d!==void 0||f!==void 0,P=u!==void 0&&d!==void 0&&f!==void 0;if(Ve&&!P)throw new Error(`temporal-fmt: format string "${e}" has an incomplete date \u2014 year, month, and day tokens must all be present together.`);let oe=c!==void 0||y!==void 0||S!==void 0||b!==void 0;if(te!==void 0&&!(P&&oe))throw new Error(`temporal-fmt: format string "${e}" has a "zzz" token but needs a full date and time to build a ZonedDateTime.`);if(ne!==void 0&&!P)throw new Error(`temporal-fmt: format string "${e}" has a weekday token ("EEEE"/"EEE") but needs a full date to validate it against.`);if(!P&&!oe)throw new Error(`temporal-fmt: format string "${e}" has no date or time tokens to parse.`);let j=F(),ae={hour:c??0,minute:y??0,second:S??0,millisecond:b??0,microsecond:w??0,nanosecond:x??0},ie=o?{calendar:o}:{},z={overflow:"reject"},v;try{te!==void 0?v=j.ZonedDateTime.from({year:u,month:d,day:f,...ae,...ie,timeZone:te},z):P&&oe?v=j.PlainDateTime.from({year:u,month:d,day:f,...ae,...ie},z):P?v=j.PlainDate.from({year:u,month:d,day:f,...ie},z):v=j.PlainTime.from(ae,z)}catch(p){throw new Error(`temporal-fmt: "${t}" doesn't describe a valid date/time for format "${e}": ${p.message}`)}if(ne!==void 0){let p=v.dayOfWeek;if(p!==ne){let k=N(r);throw new Error(`temporal-fmt: "${Ue}" doesn't match the actual weekday (${k.weekdayLong[p-1]}) for the parsed date.`)}}if(re!==void 0&&d!==void 0){let p=Math.ceil(d/3);if(re!==p)throw new Error(`temporal-fmt: format string "${e}" contains a quarter token (Q/QQQ) whose value (Q${re}) disagrees with the parsed month's actual quarter \u2014 month ${d} is in Q${p}.`)}return v}var Ne={y:{longSingular:"year",longPlural:"years",shortSingular:"yr",shortPlural:"yrs",field:"years"},o:{longSingular:"month",longPlural:"months",shortSingular:"mo",shortPlural:"mos",field:"months"},w:{longSingular:"week",longPlural:"weeks",shortSingular:"wk",shortPlural:"wks",field:"weeks"},d:{longSingular:"day",longPlural:"days",shortSingular:"d",shortPlural:"d",field:"days"},h:{longSingular:"hour",longPlural:"hours",shortSingular:"h",shortPlural:"h",field:"hours"},m:{longSingular:"minute",longPlural:"minutes",shortSingular:"m",shortPlural:"m",field:"minutes"},s:{longSingular:"second",longPlural:"seconds",shortSingular:"s",shortPlural:"s",field:"seconds"},S:{longSingular:"millisecond",longPlural:"milliseconds",shortSingular:"ms",shortPlural:"ms",field:"milliseconds"}},Pt=Object.keys(Ne).flatMap(e=>[e+e+e,e+e,e]).sort((e,t)=>t.length-e.length);function vt(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r==="'"){if(e[n+1]==="'"){he(t,"'"),n+=2;continue}let a=n+1,i="",s=!1;for(;a<e.length;){if(e[a]==="'"){if(e[a+1]==="'"){i+="'",a+=2;continue}s=!0,a+=1;break}i+=e[a],a+=1}if(!s)throw new Error(`temporal-fmt: unterminated quote in duration format string "${e}"`);he(t,i),n=a;continue}let o=Pt.find(a=>e.startsWith(a,n));if(o){let a=o[0],i=o.length===1?"numeric":o.length===2?"short":"long";t.push({kind:"token",value:o,unit:a,form:i}),n+=o.length;continue}he(t,r),n+=1}return t}function he(e,t){let n=e[e.length-1];n&&n.kind==="literal"?n.value+=t:e.push({kind:"literal",value:t})}function Ft(e,t){let n=e[t];if(n==null)return 0;if(typeof n=="number"&&Number.isFinite(n))return n;let r=Number(n);if(!Number.isFinite(r))throw new Error(`temporal-fmt: duration field "${t}" is not a finite number (got ${String(n)}).`);return r}function Re(e,t,n={}){if(t.length>1e3)throw new Error(`temporal-fmt: duration format string exceeds maximum length of ${1e3} characters (got ${t.length}).`);n.locale;let r=n.showZeroValues===!0,o=vt(t),a="";for(let i of o){if(i.kind==="literal"){a+=i.value;continue}let s=Ne[i.unit];if(!s)throw new Error(`temporal-fmt: unknown duration token "${i.value}"`);let m=Ft(e,s.field);m===0&&!r||(i.form==="numeric"?a+=String(m):i.form==="short"?a+=m+(m===1||m===-1?s.shortSingular:s.shortPlural):a+=m+" "+(m===1||m===-1?s.longSingular:s.longPlural))}return a}function _e(e,t){if(e===null||typeof e!="object")throw new Error(`temporal-fmt: formatDistance expects Temporal values, got ${t} = ${String(e)}.`);let n=e,r=typeof n.year=="number",o=typeof n.month=="number",a=typeof n.day=="number";if(r!==o||o!==a)throw new Error(`temporal-fmt: formatDistance got a ${t} with a partial date (some of year/month/day missing). Pass a full Temporal.PlainDate / PlainDateTime / ZonedDateTime.`);return{year:r?n.year:void 0,month:o?n.month:void 0,day:a?n.day:void 0,hour:typeof n.hour=="number"?n.hour:void 0,minute:typeof n.minute=="number"?n.minute:void 0,second:typeof n.second=="number"?n.second:void 0,millisecond:typeof n.millisecond=="number"?n.millisecond:void 0}}var ge=2e3,pe=1e3,G=60*pe,X=60*G,T=24*X;function $t(e,t,n){let r=0;if(e>=ge)for(let o=ge;o<e;o++)r+=C(o)?366:365;else for(let o=e;o<ge;o++)r-=C(o)?366:365;return r+=ce(e,t,n)-1,r}function Ae(e){if(e.year===void 0||e.month===void 0||e.day===void 0)throw new Error("temporal-fmt: formatDistance needs a Temporal value with year/month/day fields (PlainDate, PlainDateTime, or ZonedDateTime). A PlainTime or other shape has no anchor date to diff against.");let t=$t(e.year,e.month,e.day),n=e.hour??0,r=e.minute??0,o=e.second??0,a=e.millisecond??0;return t*T+n*X+r*G+o*pe+a}var Lt=[{maxMs:G,unit:"second"},{maxMs:X,unit:"minute"},{maxMs:T,unit:"hour"},{maxMs:30*T,unit:"day"},{maxMs:365*T,unit:"month"}],H=new Map,Ot=100;function Nt(e,t){let n=`${Rt(e)}|${t}`,r=H.get(n);if(r)return r;if(H.size>=Ot){let o=H.keys().next().value;o!==void 0&&H.delete(o)}return r=new Intl.RelativeTimeFormat(e,{numeric:t}),H.set(n,r),r}function Rt(e){try{return new Intl.Locale(e.replace(/_/g,"-")).toString().toLowerCase()}catch{return e}}function Ce(e,t,n={}){let r=_e(e,"date1"),o=_e(t,"date2"),a=Ae(r)-Ae(o),i=Math.abs(a),s="year";for(let{maxMs:f,unit:y}of Lt)if(i<f){s=y;break}let m=_t(s),l=Math.round(a/m),u=n.numeric??"auto",c=n.locale??R;return Nt(c,u).format(l,s)}function _t(e){switch(e){case"second":return pe;case"minute":return G;case"hour":return X;case"day":return T;case"week":return 7*T;case"month":return 30*T;case"quarter":return 91*T;case"year":return 365*T;default:throw new Error(`temporal-fmt: formatDistance hit unhandled unit "${String(e)}".`)}}var we=["January","February","March","April","May","June","July","August","September","October","November","December"],At=we.flatMap((e,t)=>[[e,t+1],[e.slice(0,3),t+1]]),Ct=At.map(([e])=>e).join("|"),Se=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],It=Se.join("|");function Ut(e){let t=e.toLowerCase(),n=Se.find(r=>r.toLowerCase()===t);return Se.indexOf(n??e)+1}function Vt(e){let t=e.toLowerCase(),n=we.findIndex(o=>o.toLowerCase()===t);return n>=0?n+1:we.findIndex(o=>o.slice(0,3).toLowerCase()===t)+1}function Yt(e){let t=e.dayOfWeek;if(typeof t!="number")throw new Error("temporal-fmt: parseRelative needs a reference date exposing dayOfWeek (a Temporal.PlainDate / PlainDateTime / ZonedDateTime).");return t}function B(e){if(typeof e.year!="number")throw new Error("temporal-fmt: parseRelative reference date is missing year.");return e.year}function J(e){if(typeof e.month!="number")throw new Error("temporal-fmt: parseRelative reference date is missing month.");return e.month}function ee(e){if(typeof e.day!="number")throw new Error("temporal-fmt: parseRelative reference date is missing day.");return e.day}function Ie(e,t,n={}){n.locale;let r=t,o=F(),a=(e??"").trim().replace(/\s+/g," ");if(a.length===0)throw new Error("temporal-fmt: parseRelative got an empty input string.");let i=a.toLowerCase();if(i==="today")return Ht(o,B(r),J(r),ee(r));if(i==="tomorrow")return ye(o,r,1);if(i==="yesterday")return ye(o,r,-1);let s=a.match(new RegExp(`^(next|last|this)\\s+(${It})$`,"i"));if(s){let u=s[1].toLowerCase(),c=s[2],d=Yt(r),f=Ut(c),y=Zt(u,d,f);return ye(o,r,y)}let m=a.match(/^(in\s+)?(\d+)\s+(day|week|month|year)s?(?:\s+ago)?$/i);if(m){let u=m[1],c=m[2],d=m[3].toLowerCase(),f=!!u,y=/\bago\b/i.test(a);if(!f&&!y)throw new Error(`temporal-fmt: parseRelative can't tell whether "${a}" is past or future \u2014 use "in ${c} ${d}s" or "${c} ${d}s ago".`);return jt(o,r,(f?1:-1)*Number(c),d)}let l=a.match(new RegExp(`^(${Ct})\\s+(\\d{1,2})(?:st|nd|rd|th)?(?:,?\\s*(\\d{4}))?$`,"i"));if(l){let u=l[1],c=l[2],d=Vt(u),f=Number(c);return zt(o,r,d,f)}throw new Error(`temporal-fmt: parseRelative doesn't recognize "${a}". Supported: weekday refs ("next Tuesday"), day offsets ("today"/"tomorrow"/"yesterday"), unit offsets ("in 3 days", "2 weeks ago"), and month-day ("March 5th").`)}function Zt(e,t,n){if(e==="next"){let r=n-t;return r<=0&&(r+=7),r}if(e==="last"){let r=n-t;return r>=0&&(r-=7),r}return n-t}function Ht(e,t,n,r){return e.PlainDate.from({year:t,month:n,day:r},{overflow:"reject"})}function ye(e,t,n){return e.PlainDate.from({year:B(t),month:J(t),day:ee(t)}).add({days:n})}function jt(e,t,n,r){let o=e.PlainDate.from({year:B(t),month:J(t),day:ee(t)}),a={};return r==="day"&&(a.days=n),r==="week"&&(a.weeks=n),r==="month"&&(a.months=n),r==="year"&&(a.years=n),o.add(a)}function zt(e,t,n,r){let o=B(t),a=e.PlainDate.from({year:o,month:J(t),day:ee(t)});try{let i=e.PlainDate.from({year:o,month:n,day:r},{overflow:"reject"});if(!e.PlainDate.compare)throw new Error("temporal-fmt: parseRelative needs Temporal.PlainDate.compare to resolve month-day phrases; the active implementation does not expose it.");return e.PlainDate.compare(i,a)>=0?i:e.PlainDate.from({year:o+1,month:n,day:r},{overflow:"reject"})}catch(i){try{return e.PlainDate.from({year:o+1,month:n,day:r},{overflow:"reject"})}catch{throw new Error(`temporal-fmt: parseRelative can't resolve month ${n} day ${r} \u2014 it isn't a valid date in either ${o} or ${o+1}. Original error: ${i.message}`)}}}0&&(module.exports={format,formatDistance,formatDuration,parse,parseRelative,registerLocaleVocab,setTemporal});
|
|
1
|
+
"use strict";var xe=Object.defineProperty;var lt=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var ft=Object.prototype.hasOwnProperty;var pt=(e,t)=>{for(var n in t)xe(e,n,{get:t[n],enumerable:!0})},ht=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of dt(t))!ft.call(e,o)&&o!==n&&xe(e,o,{get:()=>t[o],enumerable:!(r=lt(t,o))||r.enumerable});return e};var gt=e=>ht(xe({},"__esModule",{value:!0}),e);var yn={};pt(yn,{format:()=>He,formatDistance:()=>Je,formatDuration:()=>Ke,parse:()=>Ve,parseRelative:()=>mt,registerLocaleVocab:()=>Ie,setTemporal:()=>Ce});module.exports=gt(yn);var Oe,Ae=[];function Le(e){Ae.push(e)}function Ce(e){Oe=e;for(let t of Ae)t()}function yt(){return Oe??globalThis.Temporal}function C(){let e=yt();if(!e)throw new Error("temporal-fmt: parse() needs a Temporal implementation to construct its result. Call setTemporal(Temporal) once at startup, or assign one to globalThis.Temporal (native on Node 26+, or a polyfill like temporal-polyfill).");return e}var ve=new Map;function wt(e,t){let n=[{key:"monthLong",length:12,label:"long month names"},{key:"monthShort",length:12,label:"short month names"},{key:"weekdayLong",length:7,label:"long weekday names"},{key:"weekdayShort",length:7,label:"short weekday names"},{key:"dayPeriod",length:2,label:"day period markers (AM/PM-equivalent)"}];for(let{key:r,length:o,label:a}of n){let s=e[r];if(s===void 0)throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}" is missing required field "${r}" (${a}).`);if(!Array.isArray(s))throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}": "${r}" must be an array, got ${typeof s}.`);if(s.length!==o)throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}": "${r}" must have exactly ${o} entries (got ${s.length}) \u2014 ${a}.`);s.forEach((i,u)=>{if(typeof i!="string"||i.length===0)throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}": "${r}[${u}]" must be a non-empty string, got ${String(i)}.`)})}if(D(e.monthLong,"MMMM month",t),D(e.monthShort,"MMM month",t),D(e.weekdayLong,"EEEE weekday",t),D(e.weekdayShort,"EEE weekday",t),e.dayPeriod[0]===e.dayPeriod[1])throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}": dayPeriod entries must differ (both are "${e.dayPeriod[0]}"); otherwise parse() can't tell AM from PM.`)}function Ie(e,t){if(typeof e!="string"||e.length===0)throw new Error(`temporal-fmt: registerLocaleVocab requires a non-empty locale string, got ${String(e)}.`);wt(t,e);let n=v(e);ve.set(n,{monthLong:[...t.monthLong],monthShort:[...t.monthShort],weekdayLong:[...t.weekdayLong],weekdayShort:[...t.weekdayShort],dayPeriod:[...t.dayPeriod]}),X.delete(n)}function v(e){try{return new Intl.Locale(e.replace(/_/g,"-")).toString().toLowerCase()}catch{return e}}var X=new Map,St=500;function I(e,t,n){let r=e.formatToParts(t),o=r.findIndex(u=>u.type===n);if(o===-1)throw new Error(`temporal-fmt: locale produced no "${n}" part while building match vocabulary.`);let a=r[o].value,s=r[o-1],i=r[o+1];return s?.type==="literal"&&!/\s/.test(s.value)&&(a=s.value+a),i?.type==="literal"&&!/\s/.test(i.value)&&(a=a+i.value),a}function D(e,t,n){let r=new Map;for(let o=0;o<e.length;o++){let a=r.get(e[o]);if(a!==void 0)throw new Error(`temporal-fmt: locale "${n}" renders ${t} index ${a} and ${o} identically ("${e[o]}"). parse() can't reliably tell these apart for this locale/token, so this combination isn't supported.`);r.set(e[o],o)}}function H(e){let t=v(e);return ve.get(t)}function U(e){let t=v(e),n=ve.get(t);if(n)return n;let r=X.get(t);if(r)return r;let o=new Intl.DateTimeFormat(e,{month:"long",timeZone:"UTC"}),a=new Intl.DateTimeFormat(e,{month:"short",timeZone:"UTC"}),s=[],i=[];for(let S=0;S<12;S++){let N=new Date(Date.UTC(2020,S,1));s.push(I(o,N,"month")),i.push(I(a,N,"month"))}D(s,"MMMM month",e),D(i,"MMM month",e);let u=new Intl.DateTimeFormat(e,{weekday:"long",timeZone:"UTC"}),c=new Intl.DateTimeFormat(e,{weekday:"short",timeZone:"UTC"}),m=[],p=[];for(let S=0;S<7;S++){let N=new Date(Date.UTC(2024,0,1+S));m.push(I(u,N,"weekday")),p.push(I(c,N,"weekday"))}D(m,"EEEE weekday",e),D(p,"EEE weekday",e);let l=new Intl.DateTimeFormat(e,{hour:"numeric",hour12:!0,timeZone:"UTC"}),g=I(l,new Date(Date.UTC(2020,0,1,1)),"dayPeriod"),y=I(l,new Date(Date.UTC(2020,0,1,13)),"dayPeriod"),w=[...new Set([g,y])],E={monthLong:s,monthShort:i,weekdayLong:m,weekdayShort:p,dayPeriod:w};if(X.size>=St){let S=X.keys().next().value;S!==void 0&&X.delete(S)}return X.set(t,E),E}var bt=[0,31,59,90,120,151,181,212,243,273,304,334];function Q(e){return e%4===0&&e%100!==0||e%400===0}function G(e){return Q(e)?366:365}function De(e,t,n){let r=bt[t-1]+n;return t>2&&Q(e)&&(r+=1),r}var Me=2e3;function Et(e){let t=0;if(e>=Me)for(let r=Me;r<e;r++)t+=G(r);else for(let r=e;r<Me;r++)t-=G(r);return((5+t)%7+7)%7+1}function Re(e,t,n,r){let a=De(e,t,n)+(4-r),s,i;a<1?(s=e-1,i=a+G(s)):a>G(e)?(s=e+1,i=a-G(e)):(s=e,i=a);let c=1+(4-Et(s)+7)%7,m=1+Math.floor((i-c)/7);return{isoYear:s,week:m}}function h(e,t){let n=e<0,r=String(Math.abs(e)).padStart(t,"0");return n?"-"+r:r}h.fraction=function(t,n){let r=t.millisecond*1e6+(t.microsecond??0)*1e3+(t.nanosecond??0);return h(r,9).slice(0,n)};var j="en-US",J=new Map,kt=500;function Xe(e,t){let n=JSON.stringify([v(e),t]),r=J.get(n);if(r)return r;if(J.size>=kt){let o=J.keys().next().value;o!==void 0&&J.delete(o)}return r=new Intl.DateTimeFormat(e,t),J.set(n,r),r}var q;Le(()=>{q=void 0});function $t(){if(q===void 0){q=!1;try{let e=C();new Intl.DateTimeFormat("en-US",{day:"numeric"}).formatToParts(e.PlainDate.from({year:1970,month:1,day:1})),q=!0}catch{}}return q}function Tt(e,t,n,r){let o=e?.calendarId,a={...n,calendar:o&&o!=="iso8601"?o:"gregory"};if(!$t())return e.toLocaleString(t,a);let{toInstant:s,timeZoneId:i}=e,u=typeof s=="function"&&typeof i=="string",c=u?e.toInstant():e,m={...a,...u?{timeZone:i}:{}},l=Xe(t,m).formatToParts(c),g=l.findIndex(S=>S.type===r);if(g===-1)throw new Error(`temporal-fmt: locale "${t}" produced no "${r}" part for this token. This usually means the Temporal object is missing the field the token needs.`);let y=l[g].value,w=l[g-1],E=l[g+1];return w?.type==="literal"&&!/\s/.test(w.value)&&(y=w.value+y),E?.type==="literal"&&!/\s/.test(E.value)&&(y=y+E.value),y}function xt(e,t){let n=H(t);if(n)return e<12?n.dayPeriod[0]:n.dayPeriod[1];let r=new Date(Date.UTC(1970,0,1,e)),a=Xe(t,{hour:"numeric",hour12:!0,timeZone:"UTC"}).formatToParts(r).find(s=>s.type==="dayPeriod");if(!a)throw new Error(`temporal-fmt: locale "${t}" produced no "dayPeriod" part for token "a".`);return a.value}function ie(e,t,n,r,o,a){return o&&a!==void 0&&a>=0&&a<o.length?o[a]:Tt(e,t,n,r)}function z(e,t){if(e==="+00:00"&&(t==="X"||t==="XX"||t==="XXX"))return"Z";let n=e[0],r=e.slice(1,3),o=e.slice(4,6);switch(t){case"X":case"x":return o==="00"?`${n}${r}`:`${n}${r}${o}`;case"XX":case"xx":return`${n}${r}${o}`;case"XXX":case"xxx":return`${n}${r}:${o}`}}var me=[["yyyy",e=>h(e.year,4),"year"],["yy",e=>{if(e.year<0)throw new Error(`temporal-fmt: token "yy" doesn't support negative years (got ${e.year}), since truncating to 2 digits would make it indistinguishable from a positive year. Use "yyyy" instead.`);return h(e.year%100,2)},"year"],["MMMM",(e,t)=>{let n=H(t);return ie(e,t,{month:"long"},"month",n?.monthLong,e.month-1)},"month"],["MMM",(e,t)=>{let n=H(t);return ie(e,t,{month:"short"},"month",n?.monthShort,e.month-1)},"month"],["MM",e=>h(e.month,2),"month"],["M",e=>String(e.month),"month"],["dd",e=>h(e.day,2),"day"],["d",e=>String(e.day),"day"],["EEEE",(e,t)=>{let n=H(t);return ie(e,t,{weekday:"long"},"weekday",n?.weekdayLong,e.dayOfWeek-1)},"dayOfWeek"],["EEE",(e,t)=>{let n=H(t);return ie(e,t,{weekday:"short"},"weekday",n?.weekdayShort,e.dayOfWeek-1)},"dayOfWeek"],["HH",e=>h(e.hour,2),"hour"],["H",e=>String(e.hour),"hour"],["hh",e=>h(e.hour%12||12,2),"hour"],["h",e=>String(e.hour%12||12),"hour"],["mm",e=>h(e.minute,2),"minute"],["m",e=>String(e.minute),"minute"],["ss",e=>h(e.second,2),"second"],["s",e=>String(e.second),"second"],["SSSSSSSSS",e=>h.fraction(e,9),"millisecond"],["SSSSSSSS",e=>h.fraction(e,8),"millisecond"],["SSSSSSS",e=>h.fraction(e,7),"millisecond"],["SSSSSS",e=>h.fraction(e,6),"millisecond"],["SSSSS",e=>h.fraction(e,5),"millisecond"],["SSSS",e=>h.fraction(e,4),"millisecond"],["SSS",e=>h.fraction(e,3),"millisecond"],["SS",e=>h.fraction(e,2),"millisecond"],["S",e=>h.fraction(e,1),"millisecond"],["a",(e,t)=>xt(e.hour,t),"hour"],["zzz",e=>e.timeZoneId,"timeZoneId"],["xxx",e=>z(e.offset,"xxx"),"offset"],["xx",e=>z(e.offset,"xx"),"offset"],["X",e=>z(e.offset,"X"),"offset"],["XX",e=>z(e.offset,"XX"),"offset"],["XXX",e=>z(e.offset,"XXX"),"offset"],["x",e=>z(e.offset,"x"),"offset"],["do",e=>{let t=e.day,n=t%10,r=t%100;return r>=11&&r<=13?t+"th":n===1?t+"st":n===2?t+"nd":n===3?t+"rd":t+"th"},"day"],["Q",e=>String(Math.ceil(e.month/3)),"month"],["QQQ",e=>"Q"+Math.ceil(e.month/3),"month"],["ww",e=>{let{week:t}=Re(e.year,e.month,e.day,e.dayOfWeek);return h(t,2)},"dayOfWeek"],["RRRR",e=>{let{isoYear:t}=Re(e.year,e.month,e.day,e.dayOfWeek);return h(t,4)},"dayOfWeek"]];var vt=me.map(([e])=>e).sort((e,t)=>t.length-e.length);function ue(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r==="'"){if(e[n+1]==="'"){Ne(t,"'"),n+=2;continue}let a=n+1,s="",i=!1;for(;a<e.length;){if(e[a]==="'"){if(e[a+1]==="'"){s+="'",a+=2;continue}i=!0,a+=1;break}s+=e[a],a+=1}if(!i)throw new Error(`temporal-fmt: unterminated quote in format string "${e}"`);Ne(t,s),n=a;continue}let o=vt.find(a=>e.startsWith(a,n));if(o){t.push({kind:"token",value:o}),n+=o.length;continue}Ne(t,r),n+=1}return t}function Ne(e,t){let n=e[e.length-1];n&&n.kind==="literal"?n.value+=t:e.push({kind:"literal",value:t})}var Mt=new Map(me.map(([e,t,n])=>[e,{fn:t,field:n}]));function He(e,t,n={}){if(t.length>1e3)throw new Error(`temporal-fmt: format string exceeds maximum length of ${1e3} characters (got ${t.length}).`);let r=n.locale??j,o=ue(t),a="";for(let s of o){if(s.kind==="literal"){a+=s.value;continue}let i=Mt.get(s.value);if(!i)throw new Error(`temporal-fmt: unknown token "${s.value}"`);if(e[i.field]===void 0)throw new Error(`temporal-fmt: token "${s.value}" requires "${i.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`);a+=i.fn(e,r)}return a}function Dt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ee(e,t=!1){let n=e.map(Dt);return t?`(?:${n.map(Rt).join("|")})`:`(?:${n.join("|")})`}function Rt(e){return e.replace(/[a-zA-Z]/g,t=>`[${t.toLowerCase()}${t.toUpperCase()}]`)}var Nt="(?:UTC|[+-]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d{1,9})?)?|[A-Za-z_]+(?:[+-]\\d{1,2})?(?:\\/[A-Za-z0-9_+-]+)*)",Ft={X:"(?:Z|[+-]\\d{2}(?:\\d{2})?)",XX:"(?:Z|[+-]\\d{4})",XXX:"(?:Z|[+-]\\d{2}:\\d{2})",x:"[+-]\\d{2}(?:\\d{2})?",xx:"[+-]\\d{4}",xxx:"[+-]\\d{2}:\\d{2}"};function Pt(){return Nt}var ce;function _t(){return ce||(ce=new Set(Intl.supportedValuesOf("timeZone")),ce.add("UTC")),ce}var Ot=/^[+-]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?$/;function Ue(e){return Ot.test(e)||_t().has(e)}var At={yy:"\\d{2}",MM:"(?:0[1-9]|1[0-2])",M:"(?:1[0-2]|[1-9])",dd:"(?:0[1-9]|[12]\\d|3[01])",d:"(?:[12]\\d|3[01]|[1-9])",HH:"(?:[01]\\d|2[0-3])",H:"(?:1\\d|2[0-3]|[0-9])",hh:"(?:0[1-9]|1[0-2])",h:"(?:1[0-2]|[1-9])",mm:"(?:[0-5]\\d)",m:"(?:[1-5]\\d|[0-9])",ss:"(?:[0-5]\\d)",s:"(?:[1-5]\\d|[0-9])",SSSSSSSSS:"\\d{9}",SSSSSSSS:"\\d{8}",SSSSSSS:"\\d{7}",SSSSSS:"\\d{6}",SSSSS:"\\d{5}",SSSS:"\\d{4}",SSS:"\\d{3}",SS:"\\d{2}",S:"\\d",Q:"[1-4]"},Lt="Q[1-4]",Ct=new Set(["do","ww","RRRR"]),It="-?\\d{4}",Xt="-?\\d{4,}",Ht=new Set(["yyyy","yy","MM","M","dd","d","HH","H","hh","h","mm","m","ss","s","SSSSSSSSS","SSSSSSSS","SSSSSSS","SSSSSS","SSSSS","SSSS","SSS","SS","S"]);function ze(e,t,n){if(e==="yyyy")return n!==void 0&&Ht.has(n)?It:Xt;let r=At[e];if(r)return r;if(e==="QQQ")return Lt;if(Ct.has(e))throw new Error(`temporal-fmt: token "${e}" is format-only \u2014 it can't be parsed back into a value. Use a different token in the parse format string (e.g. "d" for "do", "MM" for "ww").`);let o=U(t);switch(e){case"MMMM":return ee(o.monthLong);case"MMM":return ee(o.monthShort);case"EEEE":return ee(o.weekdayLong);case"EEE":return ee(o.weekdayShort);case"a":return ee(o.dayPeriod,!0);case"zzz":return Pt();case"X":case"XX":case"XXX":case"x":case"xx":case"xxx":return Ft[e];default:throw new Error(`temporal-fmt: unknown token "${e}"`)}}var je=new Set(["M","d","H","h","m","s"]),Ut={M:[{digits:1,min:1,max:9},{digits:2,min:10,max:12}],d:[{digits:1,min:1,max:9},{digits:2,min:10,max:31}],H:[{digits:1,min:0,max:9},{digits:2,min:10,max:23}],h:[{digits:1,min:1,max:9},{digits:2,min:10,max:12}],m:[{digits:1,min:0,max:9},{digits:2,min:10,max:59}],s:[{digits:1,min:0,max:9},{digits:2,min:10,max:59}]};function Ze(e,t){let n=new Map;function r(o,a){let s=`${o}:${a}`,i=n.get(s);if(i)return i;if(o===t.length){let p=a===e.length?[[]]:[];return n.set(s,p),p}let u=t[o],c=Ut[u];if(!c)throw new Error(`temporal-fmt: internal error \u2014 "${u}" is not an unpadded numeric token`);let m=[];for(let{digits:p,min:l,max:g}of c){if(a+p>e.length)continue;let y=e.slice(a,a+p);if(p===2&&y[0]==="0")continue;let w=Number(y);if(!(w<l||w>g)){for(let E of r(o+1,a+p))if(m.push([w,...E]),m.length===2)break;if(m.length===2)break}}return n.set(s,m),m}return r(0,0)}function zt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ye(e,t){let n=[],r=[],o="",a=0,s={groupNames:[],tokens:[]},i=()=>{s.tokens.length>=2&&r.push(s),s={groupNames:[],tokens:[]}};for(let[u,c]of e.entries()){if(c.kind==="literal"){o+=zt(c.value),i();continue}let m=`g${a++}`;n.push({name:m,token:c.value});let p=e[u+1],l=p?.kind==="token"?p.value:void 0;o+=`(?<${m}>${ze(c.value,t,l)})`,je.has(c.value)?(s.groupNames.push(m),s.tokens.push(c.value)):i()}return i(),{regex:new RegExp(`^(?:${o})$`,"u"),groups:n,ambiguousRuns:r}}var te=new Map,Zt=500;function Yt(e,t){let n=JSON.stringify([v(t),e]),r=te.get(n);if(r)return r;if(te.size>=Zt){let o=te.keys().next().value;o!==void 0&&te.delete(o)}return r=Ye(ue(e),t),te.set(n,r),r}var Z=new Map,Vt=500;function Wt(e){let t=new Intl.Locale(e).toString().toLowerCase();if(Z.has(t))return Z.get(t);if(Z.size>=Vt){let s=Z.keys().next().value;s!==void 0&&Z.delete(s)}let n,r=t.split("-"),o=r.indexOf("u"),a=o===-1?-1:r.indexOf("ca",o+1);if(a!==-1&&a+1<r.length){let s=new Intl.DateTimeFormat(t).resolvedOptions().calendar;n=s==="gregory"?void 0:s}return Z.set(t,n),n}function Kt(e,t){if(e==="Z"){if(t==="x"||t==="xx"||t==="xxx")throw new Error(`temporal-fmt: offset token "${t}" doesn't accept "Z" \u2014 only the uppercase variants (X/XX/XXX) emit "Z" for UTC. Use "+00:00", "+0000", or "+00" depending on the variant's width.`);return"+00:00"}let n=e[0];if(n!=="+"&&n!=="-")throw new Error(`temporal-fmt: offset "${e}" for token "${t}" doesn't start with "+", "-", or "Z".`);let r=e.slice(1),o,a;if(r.length===2){if(t!=="X"&&t!=="x")throw new Error(`temporal-fmt: offset token "${t}" can't match "${e}" \u2014 it requires minutes, but "${e}" has none.`);o=r,a="00"}else if(r.length===4){if(t==="XXX"||t==="xxx")throw new Error(`temporal-fmt: offset token "${t}" can't match "${e}" \u2014 it requires a colon between hours and minutes (e.g. "${n}${r.slice(0,2)}:${r.slice(2)}").`);o=r.slice(0,2),a=r.slice(2,4)}else if(r.length===5&&r[2]===":"){if(t!=="XXX"&&t!=="xxx")throw new Error(`temporal-fmt: offset token "${t}" can't match "${e}" \u2014 it doesn't use a colon (use "${n}${r.slice(0,2)}${r.slice(3)}" instead).`);o=r.slice(0,2),a=r.slice(3,5)}else throw new Error(`temporal-fmt: offset "${e}" doesn't match the shape token "${t}" accepts.`);let s=Number(o),i=Number(a);if(s>14)throw new Error(`temporal-fmt: offset hours ${s} in "${e}" out of range (max 14 \u2014 Kiritimati, Line Islands is +14:00).`);if(i>59)throw new Error(`temporal-fmt: offset minutes ${i} in "${e}" out of range (max 59).`);if(n==="+"&&s===14&&i!==0)throw new Error(`temporal-fmt: offset "${e}" exceeds the maximum supported UTC offset of +14:00.`);if(n==="-"&&s===12&&i!==0)throw new Error(`temporal-fmt: offset "${e}" exceeds the maximum supported negative UTC offset of -12:00.`);return`${n}${o}:${a}`}function f(e,t,n){e[t]=n}function Gt(e,t,n,r,o){let a=U(r);switch(t){case"yyyy":f(e,"year",Number(n));break;case"yy":f(e,"twoDigitYear",Number(n));break;case"MM":case"M":f(e,"month",Number(n));break;case"MMMM":f(e,"month",a.monthLong.indexOf(n)+1);break;case"MMM":f(e,"month",a.monthShort.indexOf(n)+1);break;case"dd":case"d":f(e,"day",Number(n));break;case"EEEE":f(e,"weekdayRaw",n),f(e,"weekdayExpected",a.weekdayLong.indexOf(n)+1);break;case"EEE":f(e,"weekdayRaw",n),f(e,"weekdayExpected",a.weekdayShort.indexOf(n)+1);break;case"HH":case"H":f(e,"hour",Number(n));break;case"hh":case"h":f(e,"hour12",Number(n));break;case"mm":case"m":f(e,"minute",Number(n));break;case"ss":case"s":f(e,"second",Number(n));break;case"S":case"SS":case"SSS":case"SSSS":case"SSSSS":case"SSSSSS":case"SSSSSSS":case"SSSSSSSS":case"SSSSSSSSS":{let s=Number(n.padEnd(9,"0"));f(e,"millisecond",Math.floor(s/1e6)),f(e,"microsecond",Math.floor(s/1e3)%1e3),f(e,"nanosecond",s%1e3);break}case"a":{let s=a.dayPeriod.findIndex(i=>i.toLowerCase()===n.toLowerCase());if(s<0)throw new Error(`temporal-fmt: unknown day period "${n}" for locale "${r}".`);f(e,"dayPeriodRaw",n),f(e,"isPM",s===1);break}case"zzz":f(e,"timeZoneId",n);break;case"X":case"XX":case"XXX":case"x":case"xx":case"xxx":f(e,"offsetString",Kt(n,t));break;case"Q":f(e,"quarter",Number(n));break;case"QQQ":f(e,"quarter",Number(n.slice(1)));break}}function Qt(e,t){let n=t.indexOf("d");if(n!==-1){let r=e.filter(o=>o[n]<=12);if(r.length>0)return r[0]}return e[0]}function Jt(e){if(e.year!==void 0&&e.twoDigitYear!==void 0)throw new Error('temporal-fmt: format string mixes "yyyy" and "yy" year representations.');if(e.year!==void 0)return e.year;if(e.twoDigitYear!==void 0)return e.twoDigitYear<=68?2e3+e.twoDigitYear:1900+e.twoDigitYear}function qt(e,t,n){if(e.hour!==void 0&&e.hour12!==void 0)throw new Error(`temporal-fmt: format string "${t}" mixes a 24-hour token ("HH"/"H") with a 12-hour token ("hh"/"h").`);if(e.hour!==void 0){if(e.dayPeriodRaw!==void 0){let r=U(n),o=e.hour<12?r.dayPeriod[0]:r.dayPeriod[1];if(e.dayPeriodRaw.toLowerCase()!==o?.toLowerCase())throw new Error(`temporal-fmt: format string "${t}" contains a day period that contradicts the 24-hour value.`)}return e.hour}if(e.hour12!==void 0){if(e.isPM===void 0)throw new Error(`temporal-fmt: format string "${t}" uses a 12-hour token ("hh"/"h") without an "a" token, so parse() can't tell AM from PM.`);return e.hour12%12+(e.isPM?12:0)}}function Ve(e,t,n={}){if(e.length>1e3)throw new Error(`temporal-fmt: format string exceeds maximum length of ${1e3} characters (got ${e.length}).`);if(t.length>1e5)throw new Error(`temporal-fmt: input exceeds maximum length of ${1e5} characters (got ${t.length}).`);let r=n.locale??j,o=Wt(r),a=Yt(e,r),s=a.regex.exec(t);if(!s)throw new Error("temporal-fmt: no valid pattern matches the format string and input shape");if(a.groups.length===0)throw new Error(`temporal-fmt: format string "${e}" has no tokens \u2014 nothing to parse into a value.`);for(let{name:d,token:$}of a.groups)if($==="zzz"&&!Ue(s.groups[d]))throw new Error("temporal-fmt: no valid pattern matches the format string and input shape");let i=[];for(let d of a.ambiguousRuns){let $=d.groupNames.map(Te=>s.groups[Te]).join(""),x=Ze($,d.tokens);if(x.length>1){if(!n.lenient)throw new Error(`temporal-fmt: "${$}" in format string "${e}" is ambiguous \u2014 ${x.length} different ways to read tokens "${d.tokens.join("")}" (with no separator between them) are all individually valid (e.g. ${JSON.stringify(x[0])} vs ${JSON.stringify(x[1])}). parse() won't guess; add a separator between these tokens, or use their padded form (e.g. "MM" instead of "M") so each one has a fixed width. Pass { lenient: true } to opt into a documented heuristic that picks one.`);i.push({groupNames:d.groupNames,values:Qt(x,d.tokens)})}}let u={},c=new Map;for(let{groupNames:d,values:$}of i)d.forEach((x,Te)=>c.set(x,String($[Te])));for(let{name:d,token:$}of a.groups){let x=c.get(d)??s.groups[d];Gt(u,$,x,r,e)}let m=Jt(u),p=qt(u,e,r),{month:l,day:g,minute:y,second:w,millisecond:E,microsecond:S,nanosecond:N,timeZoneId:V,offsetString:L,weekdayExpected:ke,weekdayRaw:ut,quarter:$e}=u,ct=m!==void 0||l!==void 0||g!==void 0,F=m!==void 0&&l!==void 0&&g!==void 0;if(ct&&!F)throw new Error(`temporal-fmt: format string "${e}" has an incomplete date \u2014 year, month, and day tokens must all be present together.`);let oe=p!==void 0||y!==void 0||w!==void 0||E!==void 0;if(V!==void 0&&!(F&&oe))throw new Error(`temporal-fmt: format string "${e}" has a "zzz" token but needs a full date and time to build a ZonedDateTime.`);if(L!==void 0&&!(F&&oe))throw new Error(`temporal-fmt: format string "${e}" has an offset token (X/XX/XXX/x/xx/xxx) but needs a full date and time to build a ZonedDateTime.`);if(ke!==void 0&&!F)throw new Error(`temporal-fmt: format string "${e}" has a weekday token ("EEEE"/"EEE") but needs a full date to validate it against.`);if(!F&&!oe)throw new Error(`temporal-fmt: format string "${e}" has no date or time tokens to parse.`);let W=C(),ae={hour:p??0,minute:y??0,second:w??0,millisecond:E??0,microsecond:S??0,nanosecond:N??0},se=o?{calendar:o}:{},K={overflow:"reject"},M;try{V!==void 0?M=W.ZonedDateTime.from({year:m,month:l,day:g,...ae,...se,timeZone:V},K):L!==void 0?M=W.ZonedDateTime.from({year:m,month:l,day:g,...ae,...se,timeZone:L},K):F&&oe?M=W.PlainDateTime.from({year:m,month:l,day:g,...ae,...se},K):F?M=W.PlainDate.from({year:m,month:l,day:g,...se},K):M=W.PlainTime.from(ae,K)}catch(d){throw new Error(`temporal-fmt: "${t}" doesn't describe a valid date/time for format "${e}": ${d.message}`)}if(L!==void 0&&V!==void 0){let d=M.offset;if(d!==L)throw new Error(`temporal-fmt: format string "${e}" has both a "zzz" zone ("${V}") and an offset token ("${L}"), but the zone's actual offset at this instant is "${d}". The offset and the zone disagree \u2014 fix one or the other.`)}if(ke!==void 0){let d=M.dayOfWeek;if(d!==ke){let $=U(r);throw new Error(`temporal-fmt: "${ut}" doesn't match the actual weekday (${$.weekdayLong[d-1]}) for the parsed date.`)}}if($e!==void 0&&l!==void 0){let d=Math.ceil(l/3);if($e!==d)throw new Error(`temporal-fmt: format string "${e}" contains a quarter token (Q/QQQ) whose value (Q${$e}) disagrees with the parsed month's actual quarter \u2014 month ${l} is in Q${d}.`)}return M}var We={y:{longSingular:"year",longPlural:"years",shortSingular:"yr",shortPlural:"yrs",field:"years",intlUnit:"year"},o:{longSingular:"month",longPlural:"months",shortSingular:"mo",shortPlural:"mos",field:"months",intlUnit:"month"},w:{longSingular:"week",longPlural:"weeks",shortSingular:"wk",shortPlural:"wks",field:"weeks",intlUnit:"week"},d:{longSingular:"day",longPlural:"days",shortSingular:"d",shortPlural:"d",field:"days",intlUnit:"day"},h:{longSingular:"hour",longPlural:"hours",shortSingular:"h",shortPlural:"h",field:"hours",intlUnit:"hour"},m:{longSingular:"minute",longPlural:"minutes",shortSingular:"m",shortPlural:"m",field:"minutes",intlUnit:"minute"},s:{longSingular:"second",longPlural:"seconds",shortSingular:"s",shortPlural:"s",field:"seconds",intlUnit:"second"},S:{longSingular:"millisecond",longPlural:"milliseconds",shortSingular:"ms",shortPlural:"ms",field:"milliseconds",intlUnit:"millisecond"}},Bt=Object.keys(We).flatMap(e=>[e+e+e,e+e,e]).sort((e,t)=>t.length-e.length);function en(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r==="'"){if(e[n+1]==="'"){Fe(t,"'"),n+=2;continue}let a=n+1,s="",i=!1;for(;a<e.length;){if(e[a]==="'"){if(e[a+1]==="'"){s+="'",a+=2;continue}i=!0,a+=1;break}s+=e[a],a+=1}if(!i)throw new Error(`temporal-fmt: unterminated quote in duration format string "${e}"`);Fe(t,s),n=a;continue}let o=Bt.find(a=>e.startsWith(a,n));if(o){let a=o[0],s=o.length===1?"numeric":o.length===2?"short":"long";t.push({kind:"token",value:o,unit:a,form:s}),n+=o.length;continue}Fe(t,r),n+=1}return t}function Fe(e,t){let n=e[e.length-1];n&&n.kind==="literal"?n.value+=t:e.push({kind:"literal",value:t})}function tn(e,t){let n=e[t];if(n==null)return 0;if(typeof n=="number"&&Number.isFinite(n))return n;let r=Number(n);if(!Number.isFinite(r))throw new Error(`temporal-fmt: duration field "${t}" is not a finite number (got ${String(n)}).`);return r}var ne=new Map,nn=200;function rn(e,t,n){let r=`${v(e)}|${t}|${n}`,o=ne.get(r);if(o)return o;if(ne.size>=nn){let s=ne.keys().next().value;s!==void 0&&ne.delete(s)}let a=new Intl.NumberFormat(e,{style:"unit",unit:t,unitDisplay:n});return ne.set(r,a),a}function Ke(e,t,n={}){if(t.length>1e3)throw new Error(`temporal-fmt: duration format string exceeds maximum length of ${1e3} characters (got ${t.length}).`);let r=n.showZeroValues===!0,o=n.locale,a=o!==void 0,s=en(t),i="";for(let u of s){if(u.kind==="literal"){i+=u.value;continue}let c=We[u.unit];if(!c)throw new Error(`temporal-fmt: unknown duration token "${u.value}"`);let m=tn(e,c.field);if(!(m===0&&!r)){if(u.form==="numeric"){i+=String(m);continue}if(a){let p=u.form==="short"?"short":"long",l=rn(o,c.intlUnit,p);i+=l.format(m);continue}u.form==="short"?i+=m+(m===1||m===-1?c.shortSingular:c.shortPlural):i+=m+" "+(m===1||m===-1?c.longSingular:c.longPlural)}}return i}function Ge(e,t){if(e===null||typeof e!="object")throw new Error(`temporal-fmt: formatDistance expects Temporal values, got ${t} = ${String(e)}.`);let n=e,r=typeof n.year=="number",o=typeof n.month=="number",a=typeof n.day=="number";if(r!==o||o!==a)throw new Error(`temporal-fmt: formatDistance got a ${t} with a partial date (some of year/month/day missing). Pass a full Temporal.PlainDate / PlainDateTime / ZonedDateTime.`);return{year:r?n.year:void 0,month:o?n.month:void 0,day:a?n.day:void 0,hour:typeof n.hour=="number"?n.hour:void 0,minute:typeof n.minute=="number"?n.minute:void 0,second:typeof n.second=="number"?n.second:void 0,millisecond:typeof n.millisecond=="number"?n.millisecond:void 0}}var Pe=2e3,le=1e3,de=60*le,fe=60*de,R=24*fe;function on(e,t,n){let r=0;if(e>=Pe)for(let o=Pe;o<e;o++)r+=Q(o)?366:365;else for(let o=e;o<Pe;o++)r-=Q(o)?366:365;return r+=De(e,t,n)-1,r}function Qe(e){if(e.year===void 0||e.month===void 0||e.day===void 0)throw new Error("temporal-fmt: formatDistance needs a Temporal value with year/month/day fields (PlainDate, PlainDateTime, or ZonedDateTime). A PlainTime or other shape has no anchor date to diff against.");let t=on(e.year,e.month,e.day),n=e.hour??0,r=e.minute??0,o=e.second??0,a=e.millisecond??0;return t*R+n*fe+r*de+o*le+a}var an={seconds:60,minutes:60,hours:24,days:30,months:365};function sn(e){let t={...an,...e};for(let i of Object.keys(t)){let u=t[i];if(typeof u!="number"||!Number.isFinite(u)||u<=0)throw new Error(`temporal-fmt: formatDistance cutoff "${i}" must be a positive finite number (got ${String(u)}).`)}let n=t.seconds*le,r=t.minutes*de,o=t.hours*fe,a=t.days*R,s=t.months*R;if(!(n<=r&&r<=o&&o<=a&&a<=s))throw new Error(`temporal-fmt: formatDistance cutoffs must be monotonically non-decreasing in equivalent ms (seconds \u2264 minutes \u2264 hours \u2264 days \u2264 months). Got: seconds=${t.seconds}s, minutes=${t.minutes}min, hours=${t.hours}h, days=${t.days}d, months=${t.months}d \u2014 pick a sequence where each boundary is at least as large as the one before it.`);return[{maxMs:n,unit:"second"},{maxMs:r,unit:"minute"},{maxMs:o,unit:"hour"},{maxMs:a,unit:"day"},{maxMs:s,unit:"month"}]}var re=new Map,mn=100;function un(e,t){let n=`${cn(e)}|${t}`,r=re.get(n);if(r)return r;if(re.size>=mn){let o=re.keys().next().value;o!==void 0&&re.delete(o)}return r=new Intl.RelativeTimeFormat(e,{numeric:t}),re.set(n,r),r}function cn(e){try{return new Intl.Locale(e.replace(/_/g,"-")).toString().toLowerCase()}catch{return e}}function Je(e,t,n={}){let r=Ge(e,"date1"),o=Ge(t,"date2"),a=Qe(r)-Qe(o),s=Math.abs(a),i=sn(n.cutoffs),u="year";for(let{maxMs:y,unit:w}of i)if(s<y){u=w;break}let c=ln(u),m=Math.round(a/c),p=n.numeric??"auto",l=n.locale??j;return un(l,p).format(m,u)}function ln(e){switch(e){case"second":return le;case"minute":return de;case"hour":return fe;case"day":return R;case"week":return 7*R;case"month":return 30*R;case"quarter":return 91*R;case"year":return 365*R;default:throw new Error(`temporal-fmt: formatDistance hit unhandled unit "${String(e)}".`)}}function T(e){return e.toLowerCase().replace(/ä/g,"ae").replace(/ö/g,"oe").replace(/ü/g,"ue").replace(/ß/g,"ss").normalize("NFD").replace(/[\u0300-\u036f]/g,"")}function _(e){if(typeof e.year!="number")throw new Error("temporal-fmt: parseRelative reference date is missing year.");return e.year}function O(e){if(typeof e.month!="number")throw new Error("temporal-fmt: parseRelative reference date is missing month.");return e.month}function A(e){if(typeof e.day!="number")throw new Error("temporal-fmt: parseRelative reference date is missing day.");return e.day}function ge(e){let t=e.dayOfWeek;if(typeof t!="number")throw new Error("temporal-fmt: parseRelative needs a reference date exposing dayOfWeek (a Temporal.PlainDate / PlainDateTime / ZonedDateTime).");return t}function k(e){return[...e.map(T)].sort((r,o)=>o.length-r.length).map(r=>r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")}function ye(e,t,n,r){return e.PlainDate.from({year:t,month:n,day:r},{overflow:"reject"})}function b(e,t,n){return e.PlainDate.from({year:_(t),month:O(t),day:A(t)}).add({days:n})}function P(e,t,n,r){let o=e.PlainDate.from({year:_(t),month:O(t),day:A(t)}),a={};return r==="day"&&(a.days=n),r==="week"&&(a.weeks=n),r==="month"&&(a.months=n),r==="year"&&(a.years=n),o.add(a)}function we(e,t,n){if(e==="next"){let r=n-t;return r<=0&&(r+=7),r}if(e==="last"){let r=n-t;return r>=0&&(r-=7),r}return n-t}function Se(e,t,n,r){let o=_(t),a=e.PlainDate.from({year:o,month:O(t),day:A(t)});try{let s=e.PlainDate.from({year:o,month:n,day:r},{overflow:"reject"});if(!e.PlainDate.compare)throw new Error("temporal-fmt: parseRelative needs Temporal.PlainDate.compare to resolve month-day phrases; the active implementation does not expose it.");return e.PlainDate.compare(s,a)>=0?s:e.PlainDate.from({year:o+1,month:n,day:r},{overflow:"reject"})}catch(s){try{return e.PlainDate.from({year:o+1,month:n,day:r},{overflow:"reject"})}catch{throw new Error(`temporal-fmt: parseRelative can't resolve month ${n} day ${r} \u2014 it isn't a valid date in either ${o} or ${o+1}. Original error: ${s.message}`)}}}function be(e,t){let n=T(e),r=t.findIndex(o=>T(o)===n);if(r<0)throw new Error(`temporal-fmt: parseRelative internal error \u2014 weekday "${e}" not in names list.`);return r+1}function Ee(e,t,n=[]){let r=T(e),o=t.findIndex(s=>T(s)===r);if(o>=0)return o+1;let a=n.findIndex(s=>T(s)===r);if(a>=0)return a+1;throw new Error(`temporal-fmt: parseRelative internal error \u2014 month "${e}" not in names list.`)}var qe=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],Be=["January","February","March","April","May","June","July","August","September","October","November","December"],et=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],he={supportedHint:'Supported: weekday refs ("next Tuesday"), day offsets ("today"/"tomorrow"/"yesterday"), unit offsets ("in 3 days", "2 weeks ago"), and month-day ("March 5th").',matchers:[{pattern:/^today$/i,resolve:(e,t)=>ye(t.temporal,_(t.reference),O(t.reference),A(t.reference))},{pattern:/^tomorrow$/i,resolve:(e,t)=>b(t.temporal,t.reference,1)},{pattern:/^yesterday$/i,resolve:(e,t)=>b(t.temporal,t.reference,-1)},{pattern:new RegExp(`^(next|last|this)\\s+(${k(qe)})$`,"i"),resolve:(e,t)=>{let n=e[1].toLowerCase(),r=be(e[2],qe),o=ge(t.reference);return b(t.temporal,t.reference,we(n,o,r))}},{pattern:/^(in\s+)?(\d+)\s+(day|week|month|year)s?(?:\s+ago)?$/i,resolve:(e,t)=>{let n=e[1],r=e[2],o=e[3].toLowerCase(),a=!!n,s=/\bago\b/i.test(e[0]);if(!a&&!s)throw new Error(`temporal-fmt: parseRelative can't tell whether "${e[0]}" is past or future \u2014 use "in ${r} ${o}s" or "${r} ${o}s ago".`);let i=a?1:-1;return P(t.temporal,t.reference,i*Number(r),o)}},{pattern:new RegExp(`^(${k([...Be,...et])})\\s+(\\d{1,2})(?:st|nd|rd|th)?(?:,?\\s*(\\d{4}))?$`,"i"),resolve:(e,t)=>{let n=Ee(e[1],Be,et),r=Number(e[2]);return Se(t.temporal,t.reference,n,r)}}]},pe=["lunes","martes","mi\xE9rcoles","jueves","viernes","s\xE1bado","domingo"],tt=["enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"],nt=["ene","feb","mar","abr","may","jun","jul","ago","sept","oct","nov","dic"],dn={supportedHint:'Frases soportadas: referencias de d\xEDa de la semana ("el pr\xF3ximo lunes", "el lunes pasado", "este martes"), offsets de d\xEDa ("hoy"/"ma\xF1ana"/"ayer"), offsets de unidad ("en 3 d\xEDas", "hace 2 semanas"), y mes-d\xEDa ("5 de marzo").',matchers:[{pattern:/^hoy$/i,resolve:(e,t)=>ye(t.temporal,_(t.reference),O(t.reference),A(t.reference))},{pattern:/^ma[ñn]ana$/i,resolve:(e,t)=>b(t.temporal,t.reference,1)},{pattern:/^ayer$/i,resolve:(e,t)=>b(t.temporal,t.reference,-1)},{pattern:new RegExp(`^(?:el\\s+)?(?:(pr[o\xF3]ximo|pasado)\\s+(${k(pe)})|(${k(pe)})\\s+(pr[o\xF3]ximo|pasado)|este\\s+(${k(pe)}))$`,"i"),resolve:(e,t)=>{let n,r;e[1]&&e[2]?(n=e[1],r=e[2]):e[3]&&e[4]?(r=e[3],n=e[4]):(n="este",r=e[5]);let o=T(n)==="proximo"?"next":n.toLowerCase()==="este"?"this":"last",a=be(r,pe),s=ge(t.reference);return b(t.temporal,t.reference,we(o,s,a))}},{pattern:new RegExp("^(?:(en|dentro\\s+de)\\s+(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?|(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?\\s+(hace))$","i"),resolve:(e,t)=>{let n,r,o;e[1]&&e[2]&&e[3]?(n=e[2],r=e[3],o=1):(n=e[5],r=e[6],o=-1);let a=Y(r);return P(t.temporal,t.reference,o*Number(n),a)}},{pattern:new RegExp("^hace\\s+(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?$","i"),resolve:(e,t)=>{let n=Number(e[1]),r=Y(e[2]);return P(t.temporal,t.reference,-n,r)}},{pattern:new RegExp("^(\\d+)\\s+(d[i\xED]a|semana|mes|a[\xF1n]o)s?$","i"),resolve:(e,t)=>{throw new Error(`temporal-fmt: parseRelative no puede decidir si "${e[0]}" es pasado o futuro \u2014 usa "en ${e[1]} ${e[2]}s" o "hace ${e[1]} ${e[2]}s".`)}},{pattern:new RegExp(`^(\\d{1,2})\\.?\\s+de\\s+(${k([...tt,...nt])})(?:\\s+de\\s+(\\d{4}))?$`,"i"),resolve:(e,t)=>{let n=Number(e[1]),r=Ee(e[2],tt,nt);return Se(t.temporal,t.reference,r,n)}}]},_e=["lundi","mardi","mercredi","jeudi","vendredi","samedi","dimanche"],rt=["janvier","f\xE9vrier","mars","avril","mai","juin","juillet","ao\xFBt","septembre","octobre","novembre","d\xE9cembre"],ot=["janv.","f\xE9vr.","mars","avr.","mai","juin","juil.","ao\xFBt","sept.","oct.","nov.","d\xE9c."],fn={supportedHint:`Phrases prises en charge : r\xE9f\xE9rences de jour de la semaine ("lundi prochain", "mardi dernier", "ce mercredi"), d\xE9calages de jour ("aujourd'hui"/"demain"/"hier"), d\xE9calages d'unit\xE9 ("dans 3 jours", "il y a 2 semaines"), et mois-jour ("5 mars").`,matchers:[{pattern:/^aujourd'hui$/i,resolve:(e,t)=>ye(t.temporal,_(t.reference),O(t.reference),A(t.reference))},{pattern:/^demain$/i,resolve:(e,t)=>b(t.temporal,t.reference,1)},{pattern:/^hier$/i,resolve:(e,t)=>b(t.temporal,t.reference,-1)},{pattern:new RegExp(`^(?:(${k(_e)})\\s+(prochain|dernier)|ce\\s+(${k(_e)}))$`,"i"),resolve:(e,t)=>{let n,r;e[1]&&e[2]?(r=e[1],n=e[2].toLowerCase()==="prochain"?"next":"last"):(n="this",r=e[3]);let o=be(r,_e),a=ge(t.reference);return b(t.temporal,t.reference,we(n,a,o))}},{pattern:new RegExp("^il\\s+y\\s+a\\s+(\\d+)\\s+(jour|semaine|mois|an|ann[e\xE9e]e)s?$","i"),resolve:(e,t)=>{let n=Number(e[1]),r=Y(e[2]);return P(t.temporal,t.reference,-n,r)}},{pattern:new RegExp("^dans\\s+(\\d+)\\s+(jour|semaine|mois|an|ann[e\xE9e]e)s?$","i"),resolve:(e,t)=>{let n=Number(e[1]),r=Y(e[2]);return P(t.temporal,t.reference,n,r)}},{pattern:new RegExp("^(\\d+)\\s+(jour|semaine|mois|an|ann[e\xE9e]e)s?$","i"),resolve:(e,t)=>{throw new Error(`temporal-fmt: parseRelative ne peut pas d\xE9terminer si "${e[0]}" est pass\xE9 ou futur \u2014 utilisez "dans ${e[1]} ${e[2]}s" ou "il y a ${e[1]} ${e[2]}s".`)}},{pattern:new RegExp(`^(\\d{1,2})\\s+(${k([...rt,...ot])})(?:\\s+(\\d{4}))?$`,"i"),resolve:(e,t)=>{let n=Number(e[1]),r=Ee(e[2],rt,ot);return Se(t.temporal,t.reference,r,n)}}]},at=["Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"],st=["Januar","Februar","M\xE4rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],it=["Jan","Feb","M\xE4r","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"],pn={supportedHint:'Unterst\xFCtzte Phrasen: Wochentag-Bez\xFCge ("n\xE4chsten Dienstag", "letzten Freitag", "diesen Montag"), Tages-Offsets ("heute"/"morgen"/"gestern"), Einheiten-Offsets ("in 3 Tagen", "vor 2 Wochen"), und Monat-Tag ("5. M\xE4rz").',matchers:[{pattern:/^heute$/i,resolve:(e,t)=>ye(t.temporal,_(t.reference),O(t.reference),A(t.reference))},{pattern:/^morgen$/i,resolve:(e,t)=>b(t.temporal,t.reference,1)},{pattern:/^gestern$/i,resolve:(e,t)=>b(t.temporal,t.reference,-1)},{pattern:new RegExp(`^(n(?:ae|a|\xE4)chsten|letzten|diesen)\\s+(${k(at)})$`,"i"),resolve:(e,t)=>{let n=T(e[1]),r=n==="nachsten"||n==="naechsten"?"next":n==="diesen"?"this":"last",o=be(e[2],at),a=ge(t.reference);return b(t.temporal,t.reference,we(r,a,o))}},{pattern:new RegExp("^vor\\s+(\\d+)\\s+(Tag(?:e|n|en)?|Woche(?:n)?|Monat(?:e|n|en)?|Jahr(?:e|n|en)?)$","i"),resolve:(e,t)=>{let n=Number(e[1]),r=Y(e[2]);return P(t.temporal,t.reference,-n,r)}},{pattern:new RegExp("^in\\s+(\\d+)\\s+(Tag(?:e|n|en)?|Woche(?:n)?|Monat(?:e|n|en)?|Jahr(?:e|n|en)?)$","i"),resolve:(e,t)=>{let n=Number(e[1]),r=Y(e[2]);return P(t.temporal,t.reference,n,r)}},{pattern:new RegExp("^(\\d+)\\s+(Tag(?:e|n|en)?|Woche(?:n)?|Monat(?:e|n|en)?|Jahr(?:e|n|en)?)$","i"),resolve:(e,t)=>{throw new Error(`temporal-fmt: parseRelative kann nicht erkennen, ob "${e[0]}" Vergangenheit oder Zukunft ist \u2014 verwende "in ${e[1]} ${e[2]}" oder "vor ${e[1]} ${e[2]}".`)}},{pattern:new RegExp(`^(\\d{1,2})\\.?\\s+(${k([...st,...it,"Maerz","Maer"])})(?:\\s+(\\d{4}))?$`,"i"),resolve:(e,t)=>{let n=Number(e[1]),r=Ee(e[2],st,it);return Se(t.temporal,t.reference,r,n)}}]},hn={en:he,es:dn,fr:fn,de:pn};function gn(e){if(!e)return he;try{let n=new Intl.Locale(e.replace(/_/g,"-")).language.toLowerCase();return hn[n]??he}catch{return he}}function Y(e){let t=T(e);if(t==="day"||t==="week"||t==="month"||t==="year")return t;if(t==="dia")return"day";if(t==="semana")return"week";if(t==="mes")return"month";if(t==="ano"||t==="a\xF1o")return"year";if(t==="jour")return"day";if(t==="semaine")return"week";if(t==="mois")return"month";if(t==="an"||t==="annee")return"year";if(t==="tag"||t==="tagen")return"day";if(t==="woche"||t==="wochen")return"week";if(t==="monat"||t==="monaten")return"month";if(t==="jahr"||t==="jahren")return"year";throw new Error(`temporal-fmt: parseRelative internal error \u2014 unrecognized unit word "${e}".`)}function mt(e,t,n={}){let r=t,o=C(),a=(e??"").trim().replace(/\s+/g," ");if(a.length===0)throw new Error("temporal-fmt: parseRelative got an empty input string.");let s=T(a),i=gn(n.locale),u={temporal:o,reference:r};for(let c of i.matchers){let m=s.match(c.pattern);if(m)return c.resolve(m,u)}throw new Error(`temporal-fmt: parseRelative doesn't recognize "${a}". `+i.supportedHint)}0&&(module.exports={format,formatDistance,formatDuration,parse,parseRelative,registerLocaleVocab,setTemporal});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|