@vielzeug/tempo 1.0.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -43
- package/dist/_convert.cjs +1 -1
- package/dist/_convert.cjs.map +1 -1
- package/dist/_convert.d.ts +9 -43
- package/dist/_convert.d.ts.map +1 -1
- package/dist/_convert.js +12 -10
- package/dist/_convert.js.map +1 -1
- package/dist/_floor.cjs +1 -1
- package/dist/_floor.cjs.map +1 -1
- package/dist/_floor.d.ts +3 -7
- package/dist/_floor.d.ts.map +1 -1
- package/dist/_floor.js +1 -4
- package/dist/_floor.js.map +1 -1
- package/dist/_tz.cjs +1 -1
- package/dist/_tz.cjs.map +1 -1
- package/dist/_tz.d.ts +4 -11
- package/dist/_tz.d.ts.map +1 -1
- package/dist/_tz.js +8 -16
- package/dist/_tz.js.map +1 -1
- package/dist/boundary.cjs +1 -1
- package/dist/boundary.cjs.map +1 -1
- package/dist/boundary.d.ts +0 -21
- package/dist/boundary.d.ts.map +1 -1
- package/dist/boundary.js +2 -2
- package/dist/boundary.js.map +1 -1
- package/dist/classify.cjs +1 -1
- package/dist/classify.cjs.map +1 -1
- package/dist/classify.d.ts +3 -45
- package/dist/classify.d.ts.map +1 -1
- package/dist/classify.js +33 -31
- package/dist/classify.js.map +1 -1
- package/dist/compare.cjs +1 -1
- package/dist/compare.cjs.map +1 -1
- package/dist/compare.d.ts +6 -70
- package/dist/compare.d.ts.map +1 -1
- package/dist/compare.js +31 -45
- package/dist/compare.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +21 -131
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +30 -73
- package/dist/core.js.map +1 -1
- package/dist/format.cjs +1 -1
- package/dist/format.cjs.map +1 -1
- package/dist/format.d.ts +17 -17
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +10 -10
- package/dist/format.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/range.cjs +1 -1
- package/dist/range.cjs.map +1 -1
- package/dist/range.d.ts +3 -57
- package/dist/range.d.ts.map +1 -1
- package/dist/range.js +9 -20
- package/dist/range.js.map +1 -1
- package/dist/tempo.cjs +1 -1
- package/dist/tempo.cjs.map +1 -1
- package/dist/tempo.iife.js +1 -1
- package/dist/tempo.iife.js.map +1 -1
- package/dist/tempo.js +1 -1
- package/dist/tempo.js.map +1 -1
- package/dist/types.d.ts +34 -36
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","names":[],"sources":["../src/format.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type {\n DurationFormatOptions,\n FormatOptions,\n FormatPattern,\n RelativeFormatOptions,\n RelativeTimeInput,\n TimeDiffResult,\n TimeInput,\n TimeOptions,\n} from './types';\n\nimport { toInstant, toZoned } from './_convert';\nimport { inferTimeZone } from './_tz';\nimport { fail } from './errors';\n\n// ─── Formatter types ──────────────────────────────────────────────────────────\n\ntype DurationFormatter = { format(value: Temporal.Duration): string };\ntype DurationFormatterConstructor = new (\n locales?: Intl.LocalesArgument,\n options?: { style?: 'digital' | 'long' | 'narrow' | 'short' },\n) => DurationFormatter;\n\n// ─── Formatter caches ─────────────────────────────────────────────────────────\n\nconst FORMATTER_CACHE_MAX = 128;\n\nfunction cappedGetOrCreate<V>(cache: Map<string, V>, key: string, factory: () => V): V {\n const cached = cache.get(key);\n\n if (cached !== undefined) return cached;\n\n if (cache.size >= FORMATTER_CACHE_MAX) {\n const oldest = cache.keys().next().value;\n\n if (oldest !== undefined) cache.delete(oldest);\n }\n\n const value = factory();\n\n cache.set(key, value);\n\n return value;\n}\n\nconst DATE_TIME_FORMATTER_CACHE = new Map<string, Intl.DateTimeFormat>();\nconst RELATIVE_TIME_FORMATTER_CACHE = new Map<string, Intl.RelativeTimeFormat>();\nconst DURATION_FORMATTER_CACHE = new Map<string, DurationFormatter>();\n\n// ─── Format presets ───────────────────────────────────────────────────────────\n\nconst FORMAT_PRESETS: Record<FormatPattern, Intl.DateTimeFormatOptions> = {\n 'date-only': { dateStyle: 'short' },\n long: { dateStyle: 'full', timeStyle: 'long' },\n medium: { dateStyle: 'medium', timeStyle: 'short' },\n short: { dateStyle: 'short', timeStyle: 'short' },\n 'time-only': { timeStyle: 'short' },\n};\n\n// ─── Formatter factory helpers ────────────────────────────────────────────────\n\nfunction serializeIntlOptions(options: Intl.DateTimeFormatOptions): string {\n return JSON.stringify(\n Object.entries(options)\n .filter(([, value]) => value !== undefined)\n .sort(([l], [r]) => l.localeCompare(r))\n .map(([key, value]) => [key, String(value)]),\n );\n}\n\nfunction makeFormatter(options: FormatOptions, fallbackTz?: string): Intl.DateTimeFormat {\n const tz = options.tz ?? fallbackTz;\n const locale = options.locale;\n\n if (options.intl !== undefined) {\n const cacheKey = `${String(locale ?? '')}|intl|${tz ?? ''}|${serializeIntlOptions(options.intl)}`;\n\n return cappedGetOrCreate(DATE_TIME_FORMATTER_CACHE, cacheKey, () => {\n const intlOptions = tz !== undefined ? { ...options.intl, timeZone: tz } : options.intl;\n\n return new Intl.DateTimeFormat(locale, intlOptions);\n });\n }\n\n const pattern = options.pattern ?? 'medium';\n const cacheKey = `${String(locale ?? '')}|${pattern}|${tz ?? ''}`;\n\n return cappedGetOrCreate(\n DATE_TIME_FORMATTER_CACHE,\n cacheKey,\n () => new Intl.DateTimeFormat(locale, { ...FORMAT_PRESETS[pattern], timeZone: tz }),\n );\n}\n\nfunction getRelativeFormatter(options: {\n locale?: Intl.LocalesArgument;\n numeric?: Intl.RelativeTimeFormatNumeric;\n style?: Intl.RelativeTimeFormatStyle;\n}): Intl.RelativeTimeFormat {\n const cacheKey = `${String(options.locale ?? '')}|${options.numeric ?? 'auto'}|${options.style ?? 'long'}`;\n\n return cappedGetOrCreate(\n RELATIVE_TIME_FORMATTER_CACHE,\n cacheKey,\n () =>\n new Intl.RelativeTimeFormat(options.locale, {\n numeric: options.numeric ?? 'auto',\n style: options.style ?? 'long',\n }),\n );\n}\n\nfunction getDurationFormatter(options: {\n locale?: Intl.LocalesArgument;\n style?: 'digital' | 'long' | 'narrow' | 'short';\n}): DurationFormatter | null {\n const IntlWithDurationFormat = Intl as typeof Intl & { DurationFormat?: DurationFormatterConstructor };\n\n if (!IntlWithDurationFormat.DurationFormat) return null;\n\n const cacheKey = `${String(options.locale ?? '')}|${options.style ?? ''}`;\n\n return cappedGetOrCreate(\n DURATION_FORMATTER_CACHE,\n cacheKey,\n () => new IntlWithDurationFormat.DurationFormat!(options.locale, { style: options.style }),\n );\n}\n\n// ─── Time scale constants ─────────────────────────────────────────────────────\n\nconst SECONDS_PER_MINUTE = 60;\nconst SECONDS_PER_HOUR = 3_600;\nconst SECONDS_PER_DAY = 86_400;\nconst SECONDS_PER_WEEK = 604_800;\nconst SECONDS_PER_MONTH = 2_629_800; // ≈ 30.4375 days × 86400\nconst SECONDS_PER_YEAR = 31_557_600; // 365.25 days × 86400\n\n// ─── Relative time helpers ────────────────────────────────────────────────────\n\nconst RELATIVE_UNITS: ReadonlyArray<{ scale: number; thresholdToPromote: number; unit: Intl.RelativeTimeFormatUnit }> =\n [\n { scale: 1, thresholdToPromote: SECONDS_PER_MINUTE, unit: 'second' },\n { scale: SECONDS_PER_MINUTE, thresholdToPromote: SECONDS_PER_HOUR / SECONDS_PER_MINUTE, unit: 'minute' },\n { scale: SECONDS_PER_HOUR, thresholdToPromote: SECONDS_PER_DAY / SECONDS_PER_HOUR, unit: 'hour' },\n { scale: SECONDS_PER_DAY, thresholdToPromote: SECONDS_PER_WEEK / SECONDS_PER_DAY, unit: 'day' },\n { scale: SECONDS_PER_WEEK, thresholdToPromote: SECONDS_PER_MONTH / SECONDS_PER_WEEK, unit: 'week' },\n { scale: SECONDS_PER_MONTH, thresholdToPromote: 12, unit: 'month' },\n { scale: SECONDS_PER_YEAR, thresholdToPromote: Number.POSITIVE_INFINITY, unit: 'year' },\n ];\n\nfunction toRelativeUnit(seconds: number): { unit: Intl.RelativeTimeFormatUnit; value: number } {\n if (!Number.isFinite(seconds)) fail('formatRelative received a non-finite time difference.');\n\n const roundedSeconds = Math.round(seconds);\n\n for (const { scale, thresholdToPromote, unit } of RELATIVE_UNITS) {\n const value = Math.round(roundedSeconds / scale);\n\n if (Math.abs(value) < thresholdToPromote) return { unit, value };\n }\n\n return { unit: 'year', value: Math.round(roundedSeconds / SECONDS_PER_YEAR) };\n}\n\n// ─── Duration fallback renderer ───────────────────────────────────────────────\n\n// All English duration unit names follow the same pluralization rule: singular = plural.slice(0, -1)\nconst DURATION_UNITS = [\n 'years',\n 'months',\n 'weeks',\n 'days',\n 'hours',\n 'minutes',\n 'seconds',\n 'milliseconds',\n 'microseconds',\n 'nanoseconds',\n] as const satisfies ReadonlyArray<keyof Temporal.Duration>;\n\n// English-only fallback; runs only when Intl.DurationFormat is unavailable in the runtime.\nfunction buildDurationFallback(duration: Temporal.Duration): string {\n const parts: string[] = [];\n\n for (const unit of DURATION_UNITS) {\n const value = Math.abs(duration[unit] as number);\n\n if (value !== 0) parts.push(`${value} ${value === 1 ? unit.slice(0, -1) : unit}`);\n }\n\n return parts.length === 0 ? '0 seconds' : parts.join(', ');\n}\n\n// ─── Private helpers ──────────────────────────────────────────────────────────\n\n/**\n * Resolves a shared display timezone for two-input range functions.\n * Throws when both inputs are `ZonedDateTime` with different zones and no `options.tz` override.\n */\nfunction resolveRangeTz(start: TimeInput, end: TimeInput, options: FormatOptions, caller: string): string | undefined {\n if (options.tz) return options.tz;\n\n const startTz = start instanceof Temporal.ZonedDateTime ? start.timeZoneId : undefined;\n const endTz = end instanceof Temporal.ZonedDateTime ? end.timeZoneId : undefined;\n\n if (startTz && endTz && startTz !== endTz) {\n fail(`${caller} received ZonedDateTime inputs with different time zones. Pass options.tz explicitly.`);\n }\n\n return startTz ?? endTz;\n}\n\n// ─── Public API ───────────────────────────────────────────────────────────────\n\n/**\n * Formats `input` using `Intl.DateTimeFormat`. Defaults to `pattern: 'medium'`.\n *\n * Pass `intl` for full `Intl.DateTimeFormatOptions` control (mutually exclusive with `pattern`).\n * The timezone is inferred from a `ZonedDateTime` input or from `options.tz`.\n *\n * @example\n * ```ts\n * format(parseInstant('2026-03-21T10:15:30Z'), { locale: 'en-GB', pattern: 'short', tz: 'UTC' })\n * // '21/03/2026, 10:15'\n * ```\n */\nexport function format(input: TimeInput, options: FormatOptions = {}): string {\n const tz = options.tz ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n return makeFormatter(options, tz).format(new Date(toInstant(input, { tz }).epochMilliseconds));\n}\n\n/**\n * Formats a time span between `start` and `end` using `Intl.DateTimeFormat.formatRange`.\n *\n * @example\n * ```ts\n * formatRange(start, end, { locale: 'en-GB', pattern: 'short', tz: 'UTC' })\n * // '21/03/2026, 10:00 – 12:00'\n * ```\n */\nexport function formatRange(start: TimeInput, end: TimeInput, options: FormatOptions = {}): string {\n const tz = resolveRangeTz(start, end, options, 'formatRange');\n const formatter = makeFormatter(options, tz);\n\n return formatter.formatRange(\n new Date(toInstant(start, { tz }).epochMilliseconds),\n new Date(toInstant(end, { tz }).epochMilliseconds),\n );\n}\n\n/**\n * Returns the raw `Intl.DateTimeRangeFormatPart[]` array for a time span, enabling\n * fine-grained rendering of range start, end, and shared parts separately.\n *\n * @example\n * ```ts\n * formatRangeParts(start, end, { locale: 'en-US', pattern: 'short', tz: 'UTC' })\n * // [{ type: 'month', value: '3', source: 'startRange' }, ...]\n * ```\n */\nexport function formatRangeParts(\n start: TimeInput,\n end: TimeInput,\n options: FormatOptions = {},\n): ReturnType<Intl.DateTimeFormat['formatRangeToParts']> {\n const tz = resolveRangeTz(start, end, options, 'formatRangeParts');\n const formatter = makeFormatter(options, tz);\n\n return formatter.formatRangeToParts(\n new Date(toInstant(start, { tz }).epochMilliseconds),\n new Date(toInstant(end, { tz }).epochMilliseconds),\n );\n}\n\n/**\n * Serializes `input` to a UTC ISO 8601 instant string (`2026-03-21T10:15:30Z`).\n * Requires `options.tz` when input is a `PlainDate` or `PlainDateTime`.\n *\n * @example\n * ```ts\n * formatInstant(parseZoned('2026-03-21T11:15:30+01:00[Europe/Berlin]'))\n * // '2026-03-21T10:15:30Z'\n * ```\n */\nexport function formatInstant(input: TimeInput, options: TimeOptions = {}): string {\n return toInstant(input, options).toString();\n}\n\n/**\n * Serializes `input` to a zoned ISO 8601 string (`2026-03-21T11:15:30+01:00[Europe/Berlin]`).\n *\n * @param options.tz - Required when `input` is a `PlainDate` or `PlainDateTime`.\n * Inferred automatically from a `ZonedDateTime` or `Instant` input.\n *\n * @throws {TempoError} When `input` is a `PlainDate` or `PlainDateTime` and `options.tz` is omitted.\n *\n * @example\n * ```ts\n * formatZoned(parseInstant('2026-03-21T10:15:30Z'), { tz: 'Europe/Berlin' })\n * // '2026-03-21T11:15:30+01:00[Europe/Berlin]'\n *\n * formatZoned(parseZoned('2026-03-21T11:15:30+01:00[Europe/Berlin]'))\n * // '2026-03-21T11:15:30+01:00[Europe/Berlin]' (tz inferred)\n * ```\n */\nexport function formatZoned(input: TimeInput, options: TimeOptions = {}): string {\n const tz = inferTimeZone(input, options);\n\n return toZoned(input, { tz }).toString();\n}\n\n/**\n * Formats `input` relative to `options.base` (defaults to now) using `Intl.RelativeTimeFormat`.\n *\n * @example\n * ```ts\n * formatRelative(parseInstant('2026-03-21T12:00:00Z'), {\n * base: parseInstant('2026-03-21T10:00:00Z'),\n * locale: 'en-US',\n * numeric: 'always',\n * })\n * // 'in 2 hours'\n * ```\n */\nexport function formatRelative(input: RelativeTimeInput, options: RelativeFormatOptions = {}): string {\n const target = input instanceof Temporal.Instant ? input : input.toInstant();\n const base = options.base\n ? options.base instanceof Temporal.Instant\n ? options.base\n : options.base.toInstant()\n : Temporal.Now.instant();\n const differenceInSeconds = (target.epochMilliseconds - base.epochMilliseconds) / 1000;\n const { unit, value } = toRelativeUnit(differenceInSeconds);\n\n return getRelativeFormatter(options).format(value, unit);\n}\n\n/**\n * Parses an ISO duration string or `Temporal.DurationLike` into a `Temporal.Duration`.\n *\n * @example\n * ```ts\n * parseDuration('PT2H30M').toString() // 'PT2H30M'\n * parseDuration({ hours: 2, minutes: 30 }).toString() // 'PT2H30M'\n * ```\n */\nexport function parseDuration(input: string | Temporal.DurationLike): Temporal.Duration {\n try {\n return Temporal.Duration.from(input);\n } catch {\n fail(`Invalid duration input: \"${String(input)}\". Expected an ISO 8601 duration string or Temporal.DurationLike.`);\n }\n}\n\n/**\n * Formats a duration using `Intl.DurationFormat` when available, falling back to\n * a human-readable plain-English string.\n *\n * @example\n * ```ts\n * formatDuration('PT2H30M', { locale: 'en-US', style: 'long' })\n * // '2 hours, 30 minutes'\n * ```\n */\nexport function formatDuration(input: string | Temporal.DurationLike, options: DurationFormatOptions = {}): string {\n const duration = parseDuration(input);\n const formatter = getDurationFormatter(options);\n\n if (formatter) return formatter.format(duration);\n\n return buildDurationFallback(duration);\n}\n\n/**\n * Returns the raw `Intl.DateTimeFormatPart[]` array for `input`, enabling\n * custom rendering where individual parts (year, month, day, etc.) need\n * to be styled or composed differently.\n *\n * @example\n * ```ts\n * formatParts(parseInstant('2026-03-21T10:15:30Z'), { pattern: 'medium', tz: 'UTC' })\n * // [{ type: 'month', value: 'Mar' }, { type: 'literal', value: ' ' }, ...]\n * ```\n */\nexport function formatParts(input: TimeInput, options: FormatOptions = {}): Intl.DateTimeFormatPart[] {\n const tz = options.tz ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n return makeFormatter(options, tz).formatToParts(new Date(toInstant(input, { tz }).epochMilliseconds));\n}\n\n/**\n * Converts a `TimeDiffResult` to a human-readable string.\n * Uses the singular unit name when value is 1, plural (unit + 's') otherwise.\n *\n * Pass `options.locale` to localize the numeric part via `Intl.NumberFormat`.\n * Unit names remain English — for fully localized output use {@link formatRelative}\n * or {@link formatDuration} instead.\n *\n * @example\n * ```ts\n * humanize({ unit: 'day', value: 1 }) // '1 day'\n * humanize({ unit: 'day', value: 3 }) // '3 days'\n * humanize({ unit: 'day', value: 3 }, { locale: 'ar' }) // '٣ days'\n * humanize({ unit: 'millisecond', value: 0 }) // '0 milliseconds'\n * ```\n */\nexport function humanize(diff: TimeDiffResult, options: { locale?: Intl.LocalesArgument } = {}): string {\n const { unit, value } = diff;\n const formatted = options.locale ? new Intl.NumberFormat(options.locale).format(value) : String(value);\n\n return `${formatted} ${value === 1 ? unit : `${unit}s`}`;\n}\n"],"mappings":";;;;;AA2BA,IAAM,IAAsB;AAE5B,SAAS,EAAqB,GAAuB,GAAa,GAAqB;CACrF,IAAM,IAAS,EAAM,IAAI,CAAG;CAE5B,IAAI,MAAW,KAAA,GAAW,OAAO;CAEjC,IAAI,EAAM,QAAQ,GAAqB;EACrC,IAAM,IAAS,EAAM,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;EAEnC,AAAI,MAAW,KAAA,KAAW,EAAM,OAAO,CAAM;CAC/C;CAEA,IAAM,IAAQ,EAAQ;CAItB,OAFA,EAAM,IAAI,GAAK,CAAK,GAEb;AACT;AAEA,IAAM,oBAA4B,IAAI,IAAiC,GACjE,oBAAgC,IAAI,IAAqC,GACzE,oBAA2B,IAAI,IAA+B,GAI9D,IAAoE;CACxE,aAAa,EAAE,WAAW,QAAQ;CAClC,MAAM;EAAE,WAAW;EAAQ,WAAW;CAAO;CAC7C,QAAQ;EAAE,WAAW;EAAU,WAAW;CAAQ;CAClD,OAAO;EAAE,WAAW;EAAS,WAAW;CAAQ;CAChD,aAAa,EAAE,WAAW,QAAQ;AACpC;AAIA,SAAS,EAAqB,GAA6C;CACzE,OAAO,KAAK,UACV,OAAO,QAAQ,CAAO,CAAC,CACpB,QAAQ,GAAG,OAAW,MAAU,KAAA,CAAS,CAAC,CAC1C,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC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poral } from '@js-temporal/polyfill';\n\nimport type {\n DurationFormatOptions,\n FormatOptions,\n FormatPattern,\n RelativeFormatOptions,\n RelativeTimeInput,\n TimeDiffResult,\n TimeInput,\n TimeZoneOptions,\n} from './types';\n\nimport { toInstant, toZoned } from './_convert';\nimport { inferTimeZone } from './_tz';\nimport { fail } from './errors';\n\n// ─── Formatter types ──────────────────────────────────────────────────────────\n\ntype DurationFormatter = { format(value: Temporal.Duration): string };\ntype DurationFormatterConstructor = new (\n locales?: Intl.LocalesArgument,\n options?: { style?: 'digital' | 'long' | 'narrow' | 'short' },\n) => DurationFormatter;\n\n// ─── Formatter caches ─────────────────────────────────────────────────────────\n\nconst FORMATTER_CACHE_MAX = 128;\n\nfunction cappedGetOrCreate<V>(cache: Map<string, V>, key: string, factory: () => V): V {\n const cached = cache.get(key);\n\n if (cached !== undefined) return cached;\n\n if (cache.size >= FORMATTER_CACHE_MAX) {\n const oldest = cache.keys().next().value;\n\n if (oldest !== undefined) cache.delete(oldest);\n }\n\n const value = factory();\n\n cache.set(key, value);\n\n return value;\n}\n\nconst DATE_TIME_FORMATTER_CACHE = new Map<string, Intl.DateTimeFormat>();\nconst RELATIVE_TIME_FORMATTER_CACHE = new Map<string, Intl.RelativeTimeFormat>();\nconst DURATION_FORMATTER_CACHE = new Map<string, DurationFormatter>();\n\n// ─── Format presets ───────────────────────────────────────────────────────────\n\nconst FORMAT_PRESETS: Record<FormatPattern, Intl.DateTimeFormatOptions> = {\n 'date-only': { dateStyle: 'short' },\n long: { dateStyle: 'full', timeStyle: 'long' },\n medium: { dateStyle: 'medium', timeStyle: 'short' },\n short: { dateStyle: 'short', timeStyle: 'short' },\n 'time-only': { timeStyle: 'short' },\n};\n\n// ─── Formatter factory helpers ────────────────────────────────────────────────\n\nfunction serializeIntlOptions(options: Intl.DateTimeFormatOptions): string {\n return JSON.stringify(\n Object.entries(options)\n .filter(([, value]) => value !== undefined)\n .sort(([l], [r]) => l.localeCompare(r))\n .map(([key, value]) => [key, String(value)]),\n );\n}\n\nfunction makeFormatter(options: FormatOptions, fallbackTz?: string): Intl.DateTimeFormat {\n const timeZone = options.timeZone ?? fallbackTz;\n const locale = options.locale;\n\n if (options.intl !== undefined) {\n const cacheKey = `${String(locale ?? '')}|intl|${timeZone ?? ''}|${serializeIntlOptions(options.intl)}`;\n\n return cappedGetOrCreate(DATE_TIME_FORMATTER_CACHE, cacheKey, () => {\n const intlOptions = timeZone !== undefined ? { ...options.intl, timeZone: timeZone } : options.intl;\n\n return new Intl.DateTimeFormat(locale, intlOptions);\n });\n }\n\n const pattern = options.pattern ?? 'medium';\n const cacheKey = `${String(locale ?? '')}|${pattern}|${timeZone ?? ''}`;\n\n return cappedGetOrCreate(\n DATE_TIME_FORMATTER_CACHE,\n cacheKey,\n () => new Intl.DateTimeFormat(locale, { ...FORMAT_PRESETS[pattern], timeZone: timeZone }),\n );\n}\n\nfunction getRelativeFormatter(options: {\n locale?: Intl.LocalesArgument;\n numeric?: Intl.RelativeTimeFormatNumeric;\n style?: Intl.RelativeTimeFormatStyle;\n}): Intl.RelativeTimeFormat {\n const cacheKey = `${String(options.locale ?? '')}|${options.numeric ?? 'auto'}|${options.style ?? 'long'}`;\n\n return cappedGetOrCreate(\n RELATIVE_TIME_FORMATTER_CACHE,\n cacheKey,\n () =>\n new Intl.RelativeTimeFormat(options.locale, {\n numeric: options.numeric ?? 'auto',\n style: options.style ?? 'long',\n }),\n );\n}\n\nfunction getDurationFormatter(options: {\n locale?: Intl.LocalesArgument;\n style?: 'digital' | 'long' | 'narrow' | 'short';\n}): DurationFormatter | null {\n const IntlWithDurationFormat = Intl as typeof Intl & { DurationFormat?: DurationFormatterConstructor };\n\n if (!IntlWithDurationFormat.DurationFormat) return null;\n\n const cacheKey = `${String(options.locale ?? '')}|${options.style ?? ''}`;\n\n return cappedGetOrCreate(\n DURATION_FORMATTER_CACHE,\n cacheKey,\n () => new IntlWithDurationFormat.DurationFormat!(options.locale, { style: options.style }),\n );\n}\n\n// ─── Time scale constants ─────────────────────────────────────────────────────\n\nconst SECONDS_PER_MINUTE = 60;\nconst SECONDS_PER_HOUR = 3_600;\nconst SECONDS_PER_DAY = 86_400;\nconst SECONDS_PER_WEEK = 604_800;\nconst SECONDS_PER_MONTH = 2_629_800; // ≈ 30.4375 days × 86400\nconst SECONDS_PER_YEAR = 31_557_600; // 365.25 days × 86400\n\n// ─── Relative time helpers ────────────────────────────────────────────────────\n\nconst RELATIVE_UNITS: ReadonlyArray<{ scale: number; thresholdToPromote: number; unit: Intl.RelativeTimeFormatUnit }> =\n [\n { scale: 1, thresholdToPromote: SECONDS_PER_MINUTE, unit: 'second' },\n { scale: SECONDS_PER_MINUTE, thresholdToPromote: SECONDS_PER_HOUR / SECONDS_PER_MINUTE, unit: 'minute' },\n { scale: SECONDS_PER_HOUR, thresholdToPromote: SECONDS_PER_DAY / SECONDS_PER_HOUR, unit: 'hour' },\n { scale: SECONDS_PER_DAY, thresholdToPromote: SECONDS_PER_WEEK / SECONDS_PER_DAY, unit: 'day' },\n { scale: SECONDS_PER_WEEK, thresholdToPromote: SECONDS_PER_MONTH / SECONDS_PER_WEEK, unit: 'week' },\n { scale: SECONDS_PER_MONTH, thresholdToPromote: 12, unit: 'month' },\n { scale: SECONDS_PER_YEAR, thresholdToPromote: Number.POSITIVE_INFINITY, unit: 'year' },\n ];\n\nfunction toRelativeUnit(seconds: number): { unit: Intl.RelativeTimeFormatUnit; value: number } {\n if (!Number.isFinite(seconds)) fail('formatRelative received a non-finite time difference.');\n\n const roundedSeconds = Math.round(seconds);\n\n for (const { scale, thresholdToPromote, unit } of RELATIVE_UNITS) {\n const value = Math.round(roundedSeconds / scale);\n\n if (Math.abs(value) < thresholdToPromote) return { unit, value };\n }\n\n return { unit: 'year', value: Math.round(roundedSeconds / SECONDS_PER_YEAR) };\n}\n\n// ─── Duration fallback renderer ───────────────────────────────────────────────\n\n// All English duration unit names follow the same pluralization rule: singular = plural.slice(0, -1)\nconst DURATION_UNITS = [\n 'years',\n 'months',\n 'weeks',\n 'days',\n 'hours',\n 'minutes',\n 'seconds',\n 'milliseconds',\n 'microseconds',\n 'nanoseconds',\n] as const satisfies ReadonlyArray<keyof Temporal.Duration>;\n\n// English-only fallback; runs only when Intl.DurationFormat is unavailable in the runtime.\nfunction buildDurationFallback(duration: Temporal.Duration): string {\n const parts: string[] = [];\n\n for (const unit of DURATION_UNITS) {\n const value = Math.abs(duration[unit] as number);\n\n if (value !== 0) parts.push(`${value} ${value === 1 ? unit.slice(0, -1) : unit}`);\n }\n\n return parts.length === 0 ? '0 seconds' : parts.join(', ');\n}\n\n// ─── Private helpers ──────────────────────────────────────────────────────────\n\n/**\n * Resolves a shared display timezone for two-input range functions.\n * Throws when both inputs are `ZonedDateTime` with different zones and no `options.timeZone` override.\n */\nfunction resolveRangeTz(start: TimeInput, end: TimeInput, options: FormatOptions, caller: string): string | undefined {\n if (options.timeZone) return options.timeZone;\n\n const startTz = start instanceof Temporal.ZonedDateTime ? start.timeZoneId : undefined;\n const endTz = end instanceof Temporal.ZonedDateTime ? end.timeZoneId : undefined;\n\n if (startTz && endTz && startTz !== endTz) {\n fail(`${caller} received ZonedDateTime inputs with different time zones. Pass options.timeZone explicitly.`);\n }\n\n return startTz ?? endTz;\n}\n\n// ─── Public API ───────────────────────────────────────────────────────────────\n\n/**\n * Formats `input` using `Intl.DateTimeFormat`. Defaults to `pattern: 'medium'`.\n *\n * Pass `intl` for full `Intl.DateTimeFormatOptions` control (mutually exclusive with `pattern`).\n * The timezone is inferred from a `ZonedDateTime` input or from `options.timeZone`.\n *\n * @example\n * ```ts\n * format(parse('2026-03-21T10:15:30Z', { as: 'instant' }), { locale: 'en-GB', pattern: 'short', timeZone: 'UTC' })\n * // '21/03/2026, 10:15'\n * ```\n */\nexport function format(input: TimeInput, options: FormatOptions = {}): string {\n const timeZone = options.timeZone ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n return makeFormatter(options, timeZone).format(new Date(toInstant(input, { timeZone }).epochMilliseconds));\n}\n\n/**\n * Formats a time span between `start` and `end` using `Intl.DateTimeFormat.formatRange`.\n *\n * @example\n * ```ts\n * formatRange(start, end, { locale: 'en-GB', pattern: 'short', timeZone: 'UTC' })\n * // '21/03/2026, 10:00 – 12:00'\n * ```\n */\nexport function formatRange(start: TimeInput, end: TimeInput, options: FormatOptions = {}): string {\n const timeZone = resolveRangeTz(start, end, options, 'formatRange');\n const formatter = makeFormatter(options, timeZone);\n\n return formatter.formatRange(\n new Date(toInstant(start, { timeZone }).epochMilliseconds),\n new Date(toInstant(end, { timeZone }).epochMilliseconds),\n );\n}\n\n/**\n * Returns the raw `Intl.DateTimeRangeFormatPart[]` array for a time span, enabling\n * fine-grained rendering of range start, end, and shared parts separately.\n *\n * @example\n * ```ts\n * formatRangeParts(start, end, { locale: 'en-US', pattern: 'short', timeZone: 'UTC' })\n * // [{ type: 'month', value: '3', source: 'startRange' }, ...]\n * ```\n */\nexport function formatRangeParts(\n start: TimeInput,\n end: TimeInput,\n options: FormatOptions = {},\n): ReturnType<Intl.DateTimeFormat['formatRangeToParts']> {\n const timeZone = resolveRangeTz(start, end, options, 'formatRangeParts');\n const formatter = makeFormatter(options, timeZone);\n\n return formatter.formatRangeToParts(\n new Date(toInstant(start, { timeZone }).epochMilliseconds),\n new Date(toInstant(end, { timeZone }).epochMilliseconds),\n );\n}\n\n/**\n * Serializes `input` to a UTC ISO 8601 instant string (`2026-03-21T10:15:30Z`).\n * Requires `options.timeZone` when input is a `PlainDate` or `PlainDateTime`.\n *\n * @example\n * ```ts\n * formatInstant(parse('2026-03-21T11:15:30+01:00[Europe/Berlin]', { as: 'zonedDateTime' }))\n * // '2026-03-21T10:15:30Z'\n * ```\n */\nexport function formatInstant(input: TimeInput, options: TimeZoneOptions = {}): string {\n return toInstant(input, options).toString();\n}\n\n/**\n * Serializes `input` to a zoned ISO 8601 string (`2026-03-21T11:15:30+01:00[Europe/Berlin]`).\n *\n * @param options.timeZone - Required when `input` is a `PlainDate` or `PlainDateTime`.\n * Inferred automatically from a `ZonedDateTime` or `Instant` input.\n *\n * @throws {TempoError} When `input` is a `PlainDate` or `PlainDateTime` and `options.timeZone` is omitted.\n *\n * @example\n * ```ts\n * formatZoned(parse('2026-03-21T10:15:30Z', { as: 'instant' }), { timeZone: 'Europe/Berlin' })\n * // '2026-03-21T11:15:30+01:00[Europe/Berlin]'\n *\n * formatZoned(parse('2026-03-21T11:15:30+01:00[Europe/Berlin]', { as: 'zonedDateTime' }))\n * // '2026-03-21T11:15:30+01:00[Europe/Berlin]' (timeZone inferred)\n * ```\n */\nexport function formatZoned(input: TimeInput, options: TimeZoneOptions = {}): string {\n const timeZone = inferTimeZone(input, options);\n\n return toZoned(input, { timeZone }).toString();\n}\n\n/**\n * Formats `input` relative to `options.base` (defaults to now) using `Intl.RelativeTimeFormat`.\n *\n * @example\n * ```ts\n * formatRelative(parse('2026-03-21T12:00:00Z', { as: 'instant' }), {\n * base: parse('2026-03-21T10:00:00Z', { as: 'instant' }),\n * locale: 'en-US',\n * numeric: 'always',\n * })\n * // 'in 2 hours'\n * ```\n */\nexport function formatRelative(input: RelativeTimeInput, options: RelativeFormatOptions = {}): string {\n const target = input instanceof Temporal.Instant ? input : input.toInstant();\n const base = options.base\n ? options.base instanceof Temporal.Instant\n ? options.base\n : options.base.toInstant()\n : Temporal.Now.instant();\n const differenceInSeconds = (target.epochMilliseconds - base.epochMilliseconds) / 1000;\n const { unit, value } = toRelativeUnit(differenceInSeconds);\n\n return getRelativeFormatter(options).format(value, unit);\n}\n\n/**\n * Parses an ISO duration string or `Temporal.DurationLike` into a `Temporal.Duration`.\n *\n * @example\n * ```ts\n * parseDuration('PT2H30M').toString() // 'PT2H30M'\n * parseDuration({ hours: 2, minutes: 30 }).toString() // 'PT2H30M'\n * ```\n */\nexport function parseDuration(input: string | Temporal.DurationLike): Temporal.Duration {\n try {\n return Temporal.Duration.from(input);\n } catch {\n fail(`Invalid duration input: \"${String(input)}\". Expected an ISO 8601 duration string or Temporal.DurationLike.`);\n }\n}\n\n/**\n * Formats a duration using `Intl.DurationFormat` when available, falling back to\n * a human-readable plain-English string.\n *\n * @example\n * ```ts\n * formatDuration('PT2H30M', { locale: 'en-US', style: 'long' })\n * // '2 hours, 30 minutes'\n * ```\n */\nexport function formatDuration(input: string | Temporal.DurationLike, options: DurationFormatOptions = {}): string {\n const duration = parseDuration(input);\n const formatter = getDurationFormatter(options);\n\n if (formatter) return formatter.format(duration);\n\n return buildDurationFallback(duration);\n}\n\n/**\n * Returns the raw `Intl.DateTimeFormatPart[]` array for `input`, enabling\n * custom rendering where individual parts (year, month, day, etc.) need\n * to be styled or composed differently.\n *\n * @example\n * ```ts\n * formatParts(parse('2026-03-21T10:15:30Z', { as: 'instant' }), { pattern: 'medium', timeZone: 'UTC' })\n * // [{ type: 'month', value: 'Mar' }, { type: 'literal', value: ' ' }, ...]\n * ```\n */\nexport function formatParts(input: TimeInput, options: FormatOptions = {}): Intl.DateTimeFormatPart[] {\n const timeZone = options.timeZone ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n return makeFormatter(options, timeZone).formatToParts(new Date(toInstant(input, { timeZone }).epochMilliseconds));\n}\n\n/**\n * Converts a `TimeDiffResult` to a human-readable string.\n * Uses the singular unit name when value is 1, plural (unit + 's') otherwise.\n *\n * Pass `options.locale` to localize the numeric part via `Intl.NumberFormat`.\n * Unit names remain English — for fully localized output use {@link formatRelative}\n * or {@link formatDuration} instead.\n *\n * @example\n * ```ts\n * humanize({ unit: 'day', value: 1 }) // '1 day'\n * humanize({ unit: 'day', value: 3 }) // '3 days'\n * humanize({ unit: 'day', value: 3 }, { locale: 'ar' }) // '٣ days'\n * humanize({ unit: 'millisecond', value: 0 }) // '0 milliseconds'\n * ```\n */\nexport function humanize(diff: TimeDiffResult, options: { locale?: Intl.LocalesArgument } = {}): string {\n const { unit, value } = diff;\n const formatted = options.locale ? new Intl.NumberFormat(options.locale).format(value) : String(value);\n\n return `${formatted} ${value === 1 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CAAC,OAAO,GAAO,CAAI;AACzD;AAWA,SAAgB,EAAc,GAA0D;CACtF,IAAI;EACF,OAAO,EAAS,SAAS,KAAK,CAAK;CACrC,QAAQ;EACN,EAAK,4BAA4B,OAAO,CAAK,EAAE,kEAAkE;CACnH;AACF;AAYA,SAAgB,EAAe,GAAuC,IAAiC,CAAC,GAAW;CACjH,IAAM,IAAW,EAAc,CAAK,GAC9B,IAAY,EAAqB,CAAO;CAI9C,OAFI,IAAkB,EAAU,OAAO,CAAQ,IAExC,EAAsB,CAAQ;AACvC;AAaA,SAAgB,EAAY,GAAkB,IAAyB,CAAC,GAA8B;CACpG,IAAM,IAAW,EAAQ,aAAa,aAAiB,EAAS,gBAAgB,EAAM,aAAa,KAAA;CAEnG,OAAO,EAAc,GAAS,CAAQ,CAAC,CAAC,cAAc,IAAI,KAAK,EAAU,GAAO,EAAE,YAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC;AAClH;AAkBA,SAAgB,EAAS,GAAsB,IAA6C,CAAC,GAAW;CACtG,IAAM,EAAE,SAAM,aAAU;CAGxB,OAAO,GAFW,EAAQ,SAAS,IAAI,KAAK,aAAa,EAAQ,MAAM,CAAC,CAAC,OAAO,CAAK,IAAI,OAAO,CAAK,EAEjF,GAAG,MAAU,IAAI,IAAO,GAAG,EAAK;AACtD"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./_convert.cjs"),n=require("./core.cjs"),r=require("./boundary.cjs"),i=require("./compare.cjs"),a=require("./format.cjs"),o=require("./classify.cjs"),s=require("./range.cjs");let c=require("@js-temporal/polyfill");exports.TempoError=e.TempoError,exports.TempoInvalidInputError=e.TempoInvalidInputError,exports.TempoInvalidTzError=e.TempoInvalidTzError,exports.TempoMissingTzError=e.TempoMissingTzError,exports.TempoUnsupportedInputError=e.TempoUnsupportedInputError,Object.defineProperty(exports,"Temporal",{enumerable:!0,get:function(){return c.Temporal}}),exports.clamp=i.clamp,exports.dateRange=s.dateRange,exports.difference=n.difference,exports.endOf=r.endOf,exports.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./_convert.cjs"),n=require("./core.cjs"),r=require("./boundary.cjs"),i=require("./compare.cjs"),a=require("./format.cjs"),o=require("./classify.cjs"),s=require("./range.cjs");let c=require("@js-temporal/polyfill");exports.TempoError=e.TempoError,exports.TempoInvalidInputError=e.TempoInvalidInputError,exports.TempoInvalidTzError=e.TempoInvalidTzError,exports.TempoMissingTzError=e.TempoMissingTzError,exports.TempoUnsupportedInputError=e.TempoUnsupportedInputError,Object.defineProperty(exports,"Temporal",{enumerable:!0,get:function(){return c.Temporal}}),exports.clamp=i.clamp,exports.classifyExpiry=o.classifyExpiry,exports.contains=i.contains,exports.dateRange=s.dateRange,exports.difference=n.difference,exports.endOf=r.endOf,exports.format=a.format,exports.formatDuration=a.formatDuration,exports.formatInstant=a.formatInstant,exports.formatParts=a.formatParts,exports.formatRange=a.formatRange,exports.formatRangeParts=a.formatRangeParts,exports.formatRelative=a.formatRelative,exports.formatZoned=a.formatZoned,exports.humanize=a.humanize,exports.inTimeZone=t.inTimeZone,exports.isAfter=i.isAfter,exports.isBefore=i.isBefore,exports.isSame=i.isSame,exports.isValid=n.isValid,exports.now=n.now,exports.nowInstant=n.nowInstant,exports.parse=n.parse,exports.parseDuration=a.parseDuration,exports.recurrence=s.recurrence,exports.shift=n.shift,exports.startOf=r.startOf,exports.timeDiff=o.timeDiff,exports.toInstant=t.toInstant;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { Temporal } from '@js-temporal/polyfill';
|
|
2
2
|
export { TempoError, TempoInvalidInputError, TempoInvalidTzError, TempoMissingTzError, TempoUnsupportedInputError, } from './errors';
|
|
3
|
-
export { difference, isValid, now, nowInstant, parse,
|
|
4
|
-
export {
|
|
3
|
+
export { difference, isValid, now, nowInstant, parse, shift } from './core';
|
|
4
|
+
export { inTimeZone, toInstant } from './_convert';
|
|
5
5
|
export { endOf, startOf } from './boundary';
|
|
6
|
-
export { clamp, isAfter, isBefore, isSame
|
|
6
|
+
export { clamp, contains, isAfter, isBefore, isSame } from './compare';
|
|
7
7
|
export { format, formatDuration, formatInstant, formatParts, formatRange, formatRangeParts, formatRelative, formatZoned, humanize, parseDuration, } from './format';
|
|
8
|
-
export {
|
|
8
|
+
export { classifyExpiry, timeDiff } from './classify';
|
|
9
9
|
export { dateRange, recurrence } from './range';
|
|
10
|
-
export type { BoundaryOptions, BoundaryUnit, CalendarUnit, CompareOptions,
|
|
10
|
+
export type { AbsoluteTime, BoundaryOptions, BoundaryUnit, CalendarUnit, ClampInput, ClassifyExpiryInput, CompareOptions, ContainsInput, DifferenceInput, Disambiguation, DisambiguationOptions, DurationFormatOptions, ExpiryThresholds, FixedDuration, FormatOptions, FormatPattern, ParseAs, RecurrenceRule, RelativeFormatOptions, RelativeTimeInput, ShiftOptions, TempoUnit, TimeDiffResult, TimeDiffUnit, TimeInput, TimeZoneOptions, WallTime, WeekStartDay, } from './types';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EACL,UAAU,EACV,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EACL,MAAM,EACN,cAAc,EACd,aAAa,EACb,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,QAAQ,EACR,aAAa,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChD,YAAY,EACV,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,aAAa,EACb,OAAO,EACP,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,cAAc,EACd,YAAY,EACZ,SAAS,EACT,eAAe,EACf,QAAQ,EACR,YAAY,GACb,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { TempoError as e, TempoInvalidInputError as t, TempoInvalidTzError as n, TempoMissingTzError as r, TempoUnsupportedInputError as i } from "./errors.js";
|
|
2
|
-
import {
|
|
3
|
-
import { difference as s, isValid as c, now as l, nowInstant as u, parse as d,
|
|
4
|
-
import { endOf as
|
|
5
|
-
import { clamp as
|
|
6
|
-
import { format as
|
|
7
|
-
import {
|
|
8
|
-
import { dateRange as
|
|
9
|
-
import { Temporal as
|
|
10
|
-
export { e as TempoError, t as TempoInvalidInputError, n as TempoInvalidTzError, r as TempoMissingTzError, i as TempoUnsupportedInputError,
|
|
2
|
+
import { inTimeZone as a, toInstant as o } from "./_convert.js";
|
|
3
|
+
import { difference as s, isValid as c, now as l, nowInstant as u, parse as d, shift as f } from "./core.js";
|
|
4
|
+
import { endOf as p, startOf as m } from "./boundary.js";
|
|
5
|
+
import { clamp as h, contains as g, isAfter as _, isBefore as v, isSame as y } from "./compare.js";
|
|
6
|
+
import { format as b, formatDuration as x, formatInstant as S, formatParts as C, formatRange as w, formatRangeParts as T, formatRelative as E, formatZoned as D, humanize as O, parseDuration as k } from "./format.js";
|
|
7
|
+
import { classifyExpiry as A, timeDiff as j } from "./classify.js";
|
|
8
|
+
import { dateRange as M, recurrence as N } from "./range.js";
|
|
9
|
+
import { Temporal as P } from "@js-temporal/polyfill";
|
|
10
|
+
export { e as TempoError, t as TempoInvalidInputError, n as TempoInvalidTzError, r as TempoMissingTzError, i as TempoUnsupportedInputError, P as Temporal, h as clamp, A as classifyExpiry, g as contains, M as dateRange, s as difference, p as endOf, b as format, x as formatDuration, S as formatInstant, C as formatParts, w as formatRange, T as formatRangeParts, E as formatRelative, D as formatZoned, O as humanize, a as inTimeZone, _ as isAfter, v as isBefore, y as isSame, c as isValid, l as now, u as nowInstant, d as parse, k as parseDuration, N as recurrence, f as shift, m as startOf, j as timeDiff, o as toInstant };
|
package/dist/range.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./errors.cjs"),t=require("./_tz.cjs"),n=require("./_convert.cjs");let r=require("@js-temporal/polyfill");function i(i,o,s,c={}){let l=t.inferTimeZone(i,c),u=n.toZoned(i,{
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./_tz.cjs"),n=require("./_convert.cjs");let r=require("@js-temporal/polyfill");function i(i,o,s,c={}){let l=t.inferTimeZone(i,c),u=n.toZoned(i,{timeZone:l}),d=n.toZoned(o,{timeZone:l});if(r.Temporal.ZonedDateTime.compare(u.add(s),u)<=0)throw new e.TempoInvalidInputError(`dateRange: step must advance time forward.`);return a(u,d,s)}function*a(e,t,n){for(let i=e;r.Temporal.ZonedDateTime.compare(i,t)<=0;i=i.add(n))yield i}function o(e,r,i={}){let a=t.inferTimeZone(e,i),o=r.frequency===`daily`?{days:r.interval??1}:r.frequency===`weekly`?{weeks:r.interval??1}:r.frequency===`monthly`?{months:r.interval??1}:{years:r.interval??1},c=r.until?n.toInstant(r.until,{timeZone:a}):void 0;return s(n.toZoned(e,{timeZone:a}),o,r.count,c)}function*s(e,t,n,i){for(let a=e,o=0;n===void 0||o<n;a=a.add(t),o++){if(i&&r.Temporal.Instant.compare(a.toInstant(),i)>0)return;yield a}}exports.dateRange=i,exports.recurrence=o;
|
|
2
2
|
//# sourceMappingURL=range.cjs.map
|
package/dist/range.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.cjs","names":[],"sources":["../src/range.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { RecurrenceRule, TimeInput,
|
|
1
|
+
{"version":3,"file":"range.cjs","names":[],"sources":["../src/range.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { RecurrenceRule, TimeInput, TimeZoneOptions } from './types';\n\nimport { toInstant, toZoned } from './_convert';\nimport { inferTimeZone } from './_tz';\nimport { TempoInvalidInputError } from './errors';\n\nexport function dateRange(\n start: TimeInput,\n end: TimeInput,\n step: Temporal.DurationLike,\n options: TimeZoneOptions = {},\n): Generator<Temporal.ZonedDateTime> {\n const timeZone = inferTimeZone(start, options);\n const startZoned = toZoned(start, { timeZone });\n const endZoned = toZoned(end, { timeZone });\n\n if (Temporal.ZonedDateTime.compare(startZoned.add(step), startZoned) <= 0) {\n throw new TempoInvalidInputError('dateRange: step must advance time forward.');\n }\n\n return generateRange(startZoned, endZoned, step);\n}\n\nfunction* generateRange(\n start: Temporal.ZonedDateTime,\n end: Temporal.ZonedDateTime,\n step: Temporal.DurationLike,\n): Generator<Temporal.ZonedDateTime> {\n for (let current = start; Temporal.ZonedDateTime.compare(current, end) <= 0; current = current.add(step)) {\n yield current;\n }\n}\n\nexport function recurrence(\n start: TimeInput,\n rule: RecurrenceRule,\n options: TimeZoneOptions = {},\n): Generator<Temporal.ZonedDateTime> {\n const timeZone = inferTimeZone(start, options);\n const step =\n rule.frequency === 'daily'\n ? { days: rule.interval ?? 1 }\n : rule.frequency === 'weekly'\n ? { weeks: rule.interval ?? 1 }\n : rule.frequency === 'monthly'\n ? { months: rule.interval ?? 1 }\n : { years: rule.interval ?? 1 };\n const until = rule.until ? toInstant(rule.until, { timeZone }) : undefined;\n\n return generateRecurrence(toZoned(start, { timeZone }), step, rule.count, until);\n}\n\nfunction* generateRecurrence(\n start: Temporal.ZonedDateTime,\n step: Temporal.DurationLike,\n count: number | undefined,\n until: Temporal.Instant | undefined,\n): Generator<Temporal.ZonedDateTime> {\n for (\n let current = start, emitted = 0;\n count === undefined || emitted < count;\n current = current.add(step), emitted++\n ) {\n if (until && Temporal.Instant.compare(current.toInstant(), until) > 0) return;\n\n yield current;\n }\n}\n"],"mappings":"0HAQA,SAAgB,EACd,EACA,EACA,EACA,EAA2B,CAAC,EACO,CACnC,IAAM,EAAW,EAAA,cAAc,EAAO,CAAO,EACvC,EAAa,EAAA,QAAQ,EAAO,CAAE,UAAS,CAAC,EACxC,EAAW,EAAA,QAAQ,EAAK,CAAE,UAAS,CAAC,EAE1C,GAAI,EAAA,SAAS,cAAc,QAAQ,EAAW,IAAI,CAAI,EAAG,CAAU,GAAK,EACtE,MAAM,IAAI,EAAA,uBAAuB,4CAA4C,EAG/E,OAAO,EAAc,EAAY,EAAU,CAAI,CACjD,CAEA,SAAU,EACR,EACA,EACA,EACmC,CACnC,IAAK,IAAI,EAAU,EAAO,EAAA,SAAS,cAAc,QAAQ,EAAS,CAAG,GAAK,EAAG,EAAU,EAAQ,IAAI,CAAI,EACrG,MAAM,CAEV,CAEA,SAAgB,EACd,EACA,EACA,EAA2B,CAAC,EACO,CACnC,IAAM,EAAW,EAAA,cAAc,EAAO,CAAO,EACvC,EACJ,EAAK,YAAc,QACf,CAAE,KAAM,EAAK,UAAY,CAAE,EAC3B,EAAK,YAAc,SACjB,CAAE,MAAO,EAAK,UAAY,CAAE,EAC5B,EAAK,YAAc,UACjB,CAAE,OAAQ,EAAK,UAAY,CAAE,EAC7B,CAAE,MAAO,EAAK,UAAY,CAAE,EAChC,EAAQ,EAAK,MAAQ,EAAA,UAAU,EAAK,MAAO,CAAE,UAAS,CAAC,EAAI,IAAA,GAEjE,OAAO,EAAmB,EAAA,QAAQ,EAAO,CAAE,UAAS,CAAC,EAAG,EAAM,EAAK,MAAO,CAAK,CACjF,CAEA,SAAU,EACR,EACA,EACA,EACA,EACmC,CACnC,IACE,IAAI,EAAU,EAAO,EAAU,EAC/B,IAAU,IAAA,IAAa,EAAU,EACjC,EAAU,EAAQ,IAAI,CAAI,EAAG,IAC7B,CACA,GAAI,GAAS,EAAA,SAAS,QAAQ,QAAQ,EAAQ,UAAU,EAAG,CAAK,EAAI,EAAG,OAEvE,MAAM,CACR,CACF"}
|
package/dist/range.d.ts
CHANGED
|
@@ -1,59 +1,5 @@
|
|
|
1
1
|
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
-
import type { RecurrenceRule, TimeInput,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* advancing by `step` on each iteration.
|
|
6
|
-
*
|
|
7
|
-
* Returns a generator — use `for...of` for lazy consumption or spread to collect
|
|
8
|
-
* into an array: `[...dateRange(...)]`.
|
|
9
|
-
*
|
|
10
|
-
* @throws {RangeError} when `step` does not advance the date forward. Thrown eagerly at call time.
|
|
11
|
-
*
|
|
12
|
-
* Yields nothing when `start > end` (the generator terminates immediately).
|
|
13
|
-
*
|
|
14
|
-
* When `start` is a `ZonedDateTime`, the timezone is inferred from it. If `end` is in a
|
|
15
|
-
* different timezone, it is silently re-projected into `start`'s timezone. Pass `options.tz`
|
|
16
|
-
* explicitly to override.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* // Lazy — safe for large ranges
|
|
21
|
-
* for (const day of dateRange(start, end, { days: 1 }, { tz: 'UTC' })) {
|
|
22
|
-
* if (someCondition(day)) break;
|
|
23
|
-
* }
|
|
24
|
-
*
|
|
25
|
-
* // Collect to array
|
|
26
|
-
* const days = [...dateRange(start, end, { days: 1 }, { tz: 'UTC' })];
|
|
27
|
-
*
|
|
28
|
-
* // ZonedDateTime inputs — tz is inferred, no need to pass options
|
|
29
|
-
* const days = [...dateRange(zdtStart, zdtEnd, { days: 1 })];
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export declare function dateRange(start: TimeInput, end: TimeInput, step: Temporal.DurationLike, options?: TimeOptions): Generator<Temporal.ZonedDateTime>;
|
|
33
|
-
/**
|
|
34
|
-
* Lazily generates `ZonedDateTime` occurrences according to a recurrence rule.
|
|
35
|
-
*
|
|
36
|
-
* Supports `daily`, `weekly`, `monthly`, and `yearly` frequencies with an optional
|
|
37
|
-
* `interval` (defaults to `1`), `count` limit, and `until` boundary (inclusive).
|
|
38
|
-
* The `RecurrenceRule` type enforces that at least one of `count` or `until` must be
|
|
39
|
-
* provided — this is a compile-time guarantee for TypeScript callers.
|
|
40
|
-
* Passing `count: 0` yields an empty sequence without error.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* // Every Monday for 4 weeks
|
|
45
|
-
* const mondays = [...recurrence(start, { frequency: 'weekly', count: 4 }, { tz: 'UTC' })];
|
|
46
|
-
*
|
|
47
|
-
* // Bi-weekly until a deadline
|
|
48
|
-
* for (const date of recurrence(start, { frequency: 'weekly', interval: 2, until: deadline }, { tz: 'UTC' })) {
|
|
49
|
-
* schedule(date);
|
|
50
|
-
* }
|
|
51
|
-
*
|
|
52
|
-
* // ZonedDateTime start — tz is inferred, no need to pass options
|
|
53
|
-
* for (const date of recurrence(zdtStart, { frequency: 'daily', count: 7 })) {
|
|
54
|
-
* schedule(date);
|
|
55
|
-
* }
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export declare function recurrence(start: TimeInput, rule: RecurrenceRule, options?: TimeOptions): Generator<Temporal.ZonedDateTime>;
|
|
2
|
+
import type { RecurrenceRule, TimeInput, TimeZoneOptions } from './types';
|
|
3
|
+
export declare function dateRange(start: TimeInput, end: TimeInput, step: Temporal.DurationLike, options?: TimeZoneOptions): Generator<Temporal.ZonedDateTime>;
|
|
4
|
+
export declare function recurrence(start: TimeInput, rule: RecurrenceRule, options?: TimeZoneOptions): Generator<Temporal.ZonedDateTime>;
|
|
59
5
|
//# sourceMappingURL=range.d.ts.map
|
package/dist/range.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAM1E,wBAAgB,SAAS,CACvB,KAAK,EAAE,SAAS,EAChB,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,QAAQ,CAAC,YAAY,EAC3B,OAAO,GAAE,eAAoB,GAC5B,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,CAUnC;AAYD,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,cAAc,EACpB,OAAO,GAAE,eAAoB,GAC5B,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,CAanC"}
|
package/dist/range.js
CHANGED
|
@@ -4,33 +4,22 @@ import { toInstant as n, toZoned as r } from "./_convert.js";
|
|
|
4
4
|
import { Temporal as i } from "@js-temporal/polyfill";
|
|
5
5
|
//#region src/range.ts
|
|
6
6
|
function a(n, a, s, c = {}) {
|
|
7
|
-
let l = t(n, c), u = r(n, {
|
|
8
|
-
|
|
9
|
-
tz: l
|
|
10
|
-
}), d = r(a, {
|
|
11
|
-
...c,
|
|
12
|
-
tz: l
|
|
13
|
-
});
|
|
14
|
-
if (i.ZonedDateTime.compare(u.add(s), u) <= 0) throw new e("dateRange: step must advance the date forward");
|
|
7
|
+
let l = t(n, c), u = r(n, { timeZone: l }), d = r(a, { timeZone: l });
|
|
8
|
+
if (i.ZonedDateTime.compare(u.add(s), u) <= 0) throw new e("dateRange: step must advance time forward.");
|
|
15
9
|
return o(u, d, s);
|
|
16
10
|
}
|
|
17
11
|
function* o(e, t, n) {
|
|
18
|
-
let r = e;
|
|
19
|
-
for (; i.ZonedDateTime.compare(r, t) <= 0;) yield r, r = r.add(n);
|
|
12
|
+
for (let r = e; i.ZonedDateTime.compare(r, t) <= 0; r = r.add(n)) yield r;
|
|
20
13
|
}
|
|
21
14
|
function s(e, i, a = {}) {
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
tz: d
|
|
25
|
-
});
|
|
26
|
-
return c(r(e, {
|
|
27
|
-
...a,
|
|
28
|
-
tz: d
|
|
29
|
-
}), f, o, p);
|
|
15
|
+
let o = t(e, a), s = i.frequency === "daily" ? { days: i.interval ?? 1 } : i.frequency === "weekly" ? { weeks: i.interval ?? 1 } : i.frequency === "monthly" ? { months: i.interval ?? 1 } : { years: i.interval ?? 1 }, l = i.until ? n(i.until, { timeZone: o }) : void 0;
|
|
16
|
+
return c(r(e, { timeZone: o }), s, i.count, l);
|
|
30
17
|
}
|
|
31
18
|
function* c(e, t, n, r) {
|
|
32
|
-
let a = e, o = 0;
|
|
33
|
-
|
|
19
|
+
for (let a = e, o = 0; n === void 0 || o < n; a = a.add(t), o++) {
|
|
20
|
+
if (r && i.Instant.compare(a.toInstant(), r) > 0) return;
|
|
21
|
+
yield a;
|
|
22
|
+
}
|
|
34
23
|
}
|
|
35
24
|
//#endregion
|
|
36
25
|
export { a as dateRange, s as recurrence };
|
package/dist/range.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.js","names":[],"sources":["../src/range.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { RecurrenceRule, TimeInput,
|
|
1
|
+
{"version":3,"file":"range.js","names":[],"sources":["../src/range.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { RecurrenceRule, TimeInput, TimeZoneOptions } from './types';\n\nimport { toInstant, toZoned } from './_convert';\nimport { inferTimeZone } from './_tz';\nimport { TempoInvalidInputError } from './errors';\n\nexport function dateRange(\n start: TimeInput,\n end: TimeInput,\n step: Temporal.DurationLike,\n options: TimeZoneOptions = {},\n): Generator<Temporal.ZonedDateTime> {\n const timeZone = inferTimeZone(start, options);\n const startZoned = toZoned(start, { timeZone });\n const endZoned = toZoned(end, { timeZone });\n\n if (Temporal.ZonedDateTime.compare(startZoned.add(step), startZoned) <= 0) {\n throw new TempoInvalidInputError('dateRange: step must advance time forward.');\n }\n\n return generateRange(startZoned, endZoned, step);\n}\n\nfunction* generateRange(\n start: Temporal.ZonedDateTime,\n end: Temporal.ZonedDateTime,\n step: Temporal.DurationLike,\n): Generator<Temporal.ZonedDateTime> {\n for (let current = start; Temporal.ZonedDateTime.compare(current, end) <= 0; current = current.add(step)) {\n yield current;\n }\n}\n\nexport function recurrence(\n start: TimeInput,\n rule: RecurrenceRule,\n options: TimeZoneOptions = {},\n): Generator<Temporal.ZonedDateTime> {\n const timeZone = inferTimeZone(start, options);\n const step =\n rule.frequency === 'daily'\n ? { days: rule.interval ?? 1 }\n : rule.frequency === 'weekly'\n ? { weeks: rule.interval ?? 1 }\n : rule.frequency === 'monthly'\n ? { months: rule.interval ?? 1 }\n : { years: rule.interval ?? 1 };\n const until = rule.until ? toInstant(rule.until, { timeZone }) : undefined;\n\n return generateRecurrence(toZoned(start, { timeZone }), step, rule.count, until);\n}\n\nfunction* generateRecurrence(\n start: Temporal.ZonedDateTime,\n step: Temporal.DurationLike,\n count: number | undefined,\n until: Temporal.Instant | undefined,\n): Generator<Temporal.ZonedDateTime> {\n for (\n let current = start, emitted = 0;\n count === undefined || emitted < count;\n current = current.add(step), emitted++\n ) {\n if (until && Temporal.Instant.compare(current.toInstant(), until) > 0) return;\n\n yield current;\n }\n}\n"],"mappings":";;;;;AAQA,SAAgB,EACd,GACA,GACA,GACA,IAA2B,CAAC,GACO;CACnC,IAAM,IAAW,EAAc,GAAO,CAAO,GACvC,IAAa,EAAQ,GAAO,EAAE,YAAS,CAAC,GACxC,IAAW,EAAQ,GAAK,EAAE,YAAS,CAAC;CAE1C,IAAI,EAAS,cAAc,QAAQ,EAAW,IAAI,CAAI,GAAG,CAAU,KAAK,GACtE,MAAM,IAAI,EAAuB,4CAA4C;CAG/E,OAAO,EAAc,GAAY,GAAU,CAAI;AACjD;AAEA,UAAU,EACR,GACA,GACA,GACmC;CACnC,KAAK,IAAI,IAAU,GAAO,EAAS,cAAc,QAAQ,GAAS,CAAG,KAAK,GAAG,IAAU,EAAQ,IAAI,CAAI,GACrG,MAAM;AAEV;AAEA,SAAgB,EACd,GACA,GACA,IAA2B,CAAC,GACO;CACnC,IAAM,IAAW,EAAc,GAAO,CAAO,GACvC,IACJ,EAAK,cAAc,UACf,EAAE,MAAM,EAAK,YAAY,EAAE,IAC3B,EAAK,cAAc,WACjB,EAAE,OAAO,EAAK,YAAY,EAAE,IAC5B,EAAK,cAAc,YACjB,EAAE,QAAQ,EAAK,YAAY,EAAE,IAC7B,EAAE,OAAO,EAAK,YAAY,EAAE,GAChC,IAAQ,EAAK,QAAQ,EAAU,EAAK,OAAO,EAAE,YAAS,CAAC,IAAI,KAAA;CAEjE,OAAO,EAAmB,EAAQ,GAAO,EAAE,YAAS,CAAC,GAAG,GAAM,EAAK,OAAO,CAAK;AACjF;AAEA,UAAU,EACR,GACA,GACA,GACA,GACmC;CACnC,KACE,IAAI,IAAU,GAAO,IAAU,GAC/B,MAAU,KAAA,KAAa,IAAU,GACjC,IAAU,EAAQ,IAAI,CAAI,GAAG,KAC7B;EACA,IAAI,KAAS,EAAS,QAAQ,QAAQ,EAAQ,UAAU,GAAG,CAAK,IAAI,GAAG;EAEvE,MAAM;CACR;AACF"}
|
package/dist/tempo.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@js-temporal/polyfill");var t=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},n=class extends t{},r=class extends t{},i=class extends t{},a=class extends t{};function o(e,t=n){throw new t(e)}function s(t){try{e.Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(t)}catch{o(`Unknown or invalid timezone: "${t}". Expected an IANA timezone name (e.g. "America/New_York") or UTC offset (e.g. "+05:30").`,r)}return t}function c(t,n){let r=n.tz??(t instanceof e.Temporal.ZonedDateTime?t.timeZoneId:void 0);return r||o(`This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.`,i),s(r)}function l(t,n){if(n.tz)return s(n.tz);let r;for(let n of t){if(!(n instanceof e.Temporal.ZonedDateTime))continue;let t=n.timeZoneId;if(!r){r=t;continue}r!==t&&o(`Comparison received ZonedDateTime inputs with different time zones. Pass options.tz explicitly.`)}return r||o(`This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.`,i),r}function u(t,n){return e.Temporal.Instant.compare(t,n)<=0?[t,n]:[n,t]}var d=new Set([`day`,`month`,`week`,`year`]),f=26298e5;function p(t,n={}){if(t instanceof e.Temporal.Instant)return t;if(t instanceof e.Temporal.ZonedDateTime)return t.toInstant();if(t instanceof e.Temporal.PlainDateTime)return n.tz||o(`This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.`,i),t.toZonedDateTime(s(n.tz),{disambiguation:n.prefer}).toInstant();if(t instanceof e.Temporal.PlainDate)return n.tz||o(`This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.`,i),t.toZonedDateTime({timeZone:s(n.tz)}).toInstant();o(`Unsupported time input type: ${String(t)}`,a)}function m(t,n){let r=n,i=s(r.tz);if(t instanceof e.Temporal.ZonedDateTime)return t.withTimeZone(i);if(t instanceof e.Temporal.PlainDateTime)return t.toZonedDateTime(i,{disambiguation:r.prefer});if(t instanceof e.Temporal.PlainDate)return t.toZonedDateTime({timeZone:i});if(t instanceof e.Temporal.Instant)return t.toZonedDateTimeISO(i);o(`Unsupported time input type: ${String(t)}`,a)}function ee(e,t){return m(e,{tz:t})}function h(t){return e.Temporal.Now.zonedDateTimeISO(t)}function g(){return e.Temporal.Now.instant()}function _(t){try{return e.Temporal.ZonedDateTime.from(t)}catch{o(`Invalid zoned date-time string: "${t}". Expected an ISO 8601 string with offset and timezone (e.g. 2026-03-21T10:00:00+01:00[Europe/Berlin]).`)}}function v(t){try{return e.Temporal.PlainDate.from(t)}catch{o(`Invalid plain date string: "${t}". Expected an ISO 8601 date string (e.g. YYYY-MM-DD).`)}}function y(t){try{return e.Temporal.PlainDateTime.from(t)}catch{o(`Invalid date/time string: "${t}". Expected an ISO 8601 date or date-time string (e.g. YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss).`)}}function b(t){try{return e.Temporal.Instant.from(t)}catch{o(`Invalid instant string: "${t}". Expected an ISO 8601 UTC string (e.g. YYYY-MM-DDTHH:mm:ssZ).`)}}function te(e,t,n={}){let r=c(e,n);return m(e,{prefer:n.prefer,tz:r}).add(t)}function x(t,n,r={}){let{largestUnit:i,prefer:a,roundingIncrement:o,roundingMode:s,smallestUnit:c}=r,u={largestUnit:i,roundingIncrement:o,roundingMode:s,smallestUnit:c};if(!(i!==void 0&&d.has(i)||c!==void 0&&d.has(c))&&t instanceof e.Temporal.Instant&&n instanceof e.Temporal.Instant)return n.since(t,u);let f=l([t,n],r);return m(n,{prefer:a,tz:f}).since(m(t,{prefer:a,tz:f}),u)}function S(t){return t instanceof e.Temporal.Instant||t instanceof e.Temporal.ZonedDateTime||t instanceof e.Temporal.PlainDateTime||t instanceof e.Temporal.PlainDate}function C(t,n){if(n===`zoned`)return _(t);if(n===`instant`)return b(t);if(n===`plain-datetime`)return y(t);if(n===`plain-date`)return v(t);try{return e.Temporal.ZonedDateTime.from(t)}catch{}try{return e.Temporal.Instant.from(t)}catch{}if(t.includes(`T`))try{return e.Temporal.PlainDateTime.from(t)}catch{}else try{return e.Temporal.PlainDate.from(t)}catch{}o(`Unable to parse date/time string: "${t}". Expected ISO 8601 ZonedDateTime, Instant, PlainDateTime, or PlainDate.`)}var w={hour:0,microsecond:0,millisecond:0,minute:0,nanosecond:0,second:0},T={day:w,hour:{microsecond:0,millisecond:0,minute:0,nanosecond:0,second:0},minute:{microsecond:0,millisecond:0,nanosecond:0,second:0},month:{...w,day:1},year:{...w,day:1,month:1}};function E(e,t,n){let r=m(e,{prefer:n.prefer,tz:n.tz});if(t===`week`){let e=(r.dayOfWeek-(n.weekStartsOn??1)+7)%7;return r.subtract({days:e}).with(w).toInstant()}return r.with(T[t]).toInstant()}var D={day:{days:1},hour:{hours:1},minute:{minutes:1},month:{months:1},week:{weeks:1},year:{years:1}};function O(e,t,n={}){let r=c(e,n);return E(e,t,{tz:r,weekStartsOn:n.weekStartsOn}).toZonedDateTimeISO(r)}function ne(e,t,n={}){let r=c(e,n);return E(e,t,{tz:r,weekStartsOn:n.weekStartsOn}).toZonedDateTimeISO(r).add(D[t]).subtract({nanoseconds:1})}function re(e,t,n,r){let i={tz:l([e,t],r),weekStartsOn:r.weekStartsOn};return{left:E(e,n,i),right:E(t,n,i)}}function k(e,t,n,r,i){let a={tz:l([e,t,n],i),weekStartsOn:i.weekStartsOn},o=E(e,r,a),[s,c]=u(E(t,r,a),E(n,r,a));return{lower:s,target:o,upper:c}}function A(t,n,r){if(!r.unit)return e.Temporal.Instant.compare(p(t,r),p(n,r));let{left:i,right:a}=re(t,n,r.unit,r);return e.Temporal.Instant.compare(i,a)}function ie(e,t,n={}){return A(e,t,n)<0}function ae(e,t,n={}){return A(e,t,n)>0}function oe(e,t,n={}){return A(e,t,n)===0}function se(t,n,r,i={}){if(!i.unit){let a=p(t,i),[o,s]=u(p(n,i),p(r,i));return e.Temporal.Instant.compare(o,a)<=0&&e.Temporal.Instant.compare(a,s)<=0}let{lower:a,target:o,upper:s}=k(t,n,r,i.unit,i);return e.Temporal.Instant.compare(a,o)<=0&&e.Temporal.Instant.compare(o,s)<=0}function j(t,n,r,i={}){let a=t instanceof e.Temporal.ZonedDateTime,o=a?t.timeZoneId:void 0;if(!i.unit){let s=p(t,i),[c,l]=u(p(n,i),p(r,i)),d;return d=e.Temporal.Instant.compare(s,c)<0?c:e.Temporal.Instant.compare(s,l)>0?l:s,a&&o?d.toZonedDateTimeISO(o):d}let{lower:s,target:c,upper:d}=k(t,n,r,i.unit,i),f;f=e.Temporal.Instant.compare(c,s)<0?s:e.Temporal.Instant.compare(c,d)>0?d:c;let m=i.tz??o??l([t,n,r],i);return a?f.toZonedDateTimeISO(m):f}var M=128;function N(e,t,n){let r=e.get(t);if(r!==void 0)return r;if(e.size>=M){let t=e.keys().next().value;t!==void 0&&e.delete(t)}let i=n();return e.set(t,i),i}var P=new Map,F=new Map,I=new Map,L={"date-only":{dateStyle:`short`},long:{dateStyle:`full`,timeStyle:`long`},medium:{dateStyle:`medium`,timeStyle:`short`},short:{dateStyle:`short`,timeStyle:`short`},"time-only":{timeStyle:`short`}};function R(e){return JSON.stringify(Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,String(t)]))}function z(e,t){let n=e.tz??t,r=e.locale;if(e.intl!==void 0)return N(P,`${String(r??``)}|intl|${n??``}|${R(e.intl)}`,()=>{let t=n===void 0?e.intl:{...e.intl,timeZone:n};return new Intl.DateTimeFormat(r,t)});let i=e.pattern??`medium`;return N(P,`${String(r??``)}|${i}|${n??``}`,()=>new Intl.DateTimeFormat(r,{...L[i],timeZone:n}))}function B(e){return N(F,`${String(e.locale??``)}|${e.numeric??`auto`}|${e.style??`long`}`,()=>new Intl.RelativeTimeFormat(e.locale,{numeric:e.numeric??`auto`,style:e.style??`long`}))}function V(e){let t=Intl;return t.DurationFormat?N(I,`${String(e.locale??``)}|${e.style??``}`,()=>new t.DurationFormat(e.locale,{style:e.style})):null}var H=60,U=3600,W=86400,G=604800,K=2629800,q=31557600,ce=[{scale:1,thresholdToPromote:H,unit:`second`},{scale:H,thresholdToPromote:U/H,unit:`minute`},{scale:U,thresholdToPromote:W/U,unit:`hour`},{scale:W,thresholdToPromote:G/W,unit:`day`},{scale:G,thresholdToPromote:K/G,unit:`week`},{scale:K,thresholdToPromote:12,unit:`month`},{scale:q,thresholdToPromote:1/0,unit:`year`}];function le(e){Number.isFinite(e)||o(`formatRelative received a non-finite time difference.`);let t=Math.round(e);for(let{scale:e,thresholdToPromote:n,unit:r}of ce){let i=Math.round(t/e);if(Math.abs(i)<n)return{unit:r,value:i}}return{unit:`year`,value:Math.round(t/q)}}var ue=[`years`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`,`microseconds`,`nanoseconds`];function de(e){let t=[];for(let n of ue){let r=Math.abs(e[n]);r!==0&&t.push(`${r} ${r===1?n.slice(0,-1):n}`)}return t.length===0?`0 seconds`:t.join(`, `)}function J(t,n,r,i){if(r.tz)return r.tz;let a=t instanceof e.Temporal.ZonedDateTime?t.timeZoneId:void 0,s=n instanceof e.Temporal.ZonedDateTime?n.timeZoneId:void 0;return a&&s&&a!==s&&o(`${i} received ZonedDateTime inputs with different time zones. Pass options.tz explicitly.`),a??s}function fe(t,n={}){let r=n.tz??(t instanceof e.Temporal.ZonedDateTime?t.timeZoneId:void 0);return z(n,r).format(new Date(p(t,{tz:r}).epochMilliseconds))}function pe(e,t,n={}){let r=J(e,t,n,`formatRange`);return z(n,r).formatRange(new Date(p(e,{tz:r}).epochMilliseconds),new Date(p(t,{tz:r}).epochMilliseconds))}function me(e,t,n={}){let r=J(e,t,n,`formatRangeParts`);return z(n,r).formatRangeToParts(new Date(p(e,{tz:r}).epochMilliseconds),new Date(p(t,{tz:r}).epochMilliseconds))}function he(e,t={}){return p(e,t).toString()}function ge(e,t={}){return m(e,{tz:c(e,t)}).toString()}function _e(t,n={}){let r=t instanceof e.Temporal.Instant?t:t.toInstant(),i=n.base?n.base instanceof e.Temporal.Instant?n.base:n.base.toInstant():e.Temporal.Now.instant(),{unit:a,value:o}=le((r.epochMilliseconds-i.epochMilliseconds)/1e3);return B(n).format(o,a)}function Y(t){try{return e.Temporal.Duration.from(t)}catch{o(`Invalid duration input: "${String(t)}". Expected an ISO 8601 duration string or Temporal.DurationLike.`)}}function ve(e,t={}){let n=Y(e),r=V(t);return r?r.format(n):de(n)}function ye(t,n={}){let r=n.tz??(t instanceof e.Temporal.ZonedDateTime?t.timeZoneId:void 0);return z(n,r).formatToParts(new Date(p(t,{tz:r}).epochMilliseconds))}function be(e,t={}){let{unit:n,value:r}=e;return`${t.locale?new Intl.NumberFormat(t.locale).format(r):String(r)} ${r===1?n:`${n}s`}`}var X=new WeakMap;function xe(e){let t=X.get(e);if(t)return t;let n=Object.keys(e).map(t=>({key:t,ms:Z(e[t])})).sort((e,t)=>e.ms-t.ms);return X.set(e,n),n}function Se(t,n,r={},i=e.Temporal.Now.instant()){let a=p(t,r).epochMilliseconds-i.epochMilliseconds;for(let{key:e,ms:t}of xe(n))if(a<=t)return e;return null}function Z(t){let n=e.Temporal.Duration.from(t);return(n.years??0)*12*f+(n.months??0)*f+(n.weeks??0)*7*864e5+(n.days??0)*864e5+(n.hours??0)*36e5+(n.minutes??0)*6e4+(n.seconds??0)*1e3+(n.milliseconds??0)+(n.microseconds??0)/1e3+(n.nanoseconds??0)/1e6}var Ce=[{field:`years`,unit:`year`},{field:`months`,unit:`month`},{field:`weeks`,unit:`week`},{field:`days`,unit:`day`},{field:`hours`,unit:`hour`},{field:`minutes`,unit:`minute`},{field:`seconds`,unit:`second`},{field:`milliseconds`,unit:`millisecond`}];function Q(t,n){return e.Temporal.ZonedDateTime.compare(t,n)<=0?n.since(t,{largestUnit:`year`}):t.since(n,{largestUnit:`year`})}function $(e){for(let{field:t,unit:n}of Ce){let r=Math.abs(e[t]);if(r>0)return{unit:n,value:r}}return{unit:`millisecond`,value:0}}function we(t,n,r={}){let i=n??e.Temporal.Now.instant();if(!r.tz&&t instanceof e.Temporal.Instant&&i instanceof e.Temporal.Instant)return $(Q(t.toZonedDateTimeISO(`UTC`),i.toZonedDateTimeISO(`UTC`)));let a=l([t,i],r);return $(Q(m(t,{tz:a}),m(i,{tz:a})))}function Te(t,r,i,a={}){let o=c(t,a),s=m(t,{...a,tz:o}),l=m(r,{...a,tz:o});if(e.Temporal.ZonedDateTime.compare(s.add(i),s)<=0)throw new n(`dateRange: step must advance the date forward`);return Ee(s,l,i)}function*Ee(t,n,r){let i=t;for(;e.Temporal.ZonedDateTime.compare(i,n)<=0;)yield i,i=i.add(r)}function De(e,t,n={}){let{count:r,frequency:i,interval:a=1,until:o}=t,s=c(e,n),l=i===`daily`?{days:a}:i===`weekly`?{weeks:a}:i===`monthly`?{months:a}:{years:a},u=o===void 0?void 0:p(o,{...n,tz:s});return Oe(m(e,{...n,tz:s}),l,r,u)}function*Oe(t,n,r,i){let a=t,o=0;for(;!(r!==void 0&&o>=r||i!==void 0&&e.Temporal.Instant.compare(a.toInstant(),i)>0);)yield a,o++,a=a.add(n)}exports.TempoError=t,exports.TempoInvalidInputError=n,exports.TempoInvalidTzError=r,exports.TempoMissingTzError=i,exports.TempoUnsupportedInputError=a,Object.defineProperty(exports,"Temporal",{enumerable:!0,get:function(){return e.Temporal}}),exports.clamp=j,exports.dateRange=Te,exports.difference=x,exports.endOf=ne,exports.expires=Se,exports.format=fe,exports.formatDuration=ve,exports.formatInstant=he,exports.formatParts=ye,exports.formatRange=pe,exports.formatRangeParts=me,exports.formatRelative=_e,exports.formatZoned=ge,exports.humanize=be,exports.inTz=ee,exports.isAfter=ae,exports.isBefore=ie,exports.isSame=oe,exports.isValid=S,exports.now=h,exports.nowInstant=g,exports.parse=C,exports.parseDuration=Y,exports.parseInstant=b,exports.parsePlainDate=v,exports.parsePlainDateTime=y,exports.parseZoned=_,exports.recurrence=De,exports.shift=te,exports.startOf=O,exports.timeDiff=we,exports.toInstant=p,exports.within=se;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@js-temporal/polyfill");var t=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},n=class extends t{},r=class extends t{},i=class extends t{},a=class extends t{};function o(e,t=n){throw new t(e)}function s(t){try{e.Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(t)}catch{o(`Unknown or invalid timezone: "${t}". Expected an IANA timezone name or UTC offset.`,r)}return t}function c(t,n){let r=n.timeZone??(t instanceof e.Temporal.ZonedDateTime?t.timeZoneId:void 0);return r||o(`This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.`,i),s(r)}function l(t,n){if(n.timeZone)return s(n.timeZone);let r;for(let n of t)n instanceof e.Temporal.ZonedDateTime&&(r?r!==n.timeZoneId&&o(`Inputs use different time zones. Pass options.timeZone explicitly.`):r=n.timeZoneId);return r||o(`This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.`,i),r}function u(t,n){return e.Temporal.Instant.compare(t,n)<=0?[t,n]:[n,t]}var d=new Set([`day`,`month`,`week`,`year`]);function f(t,n={}){if(t instanceof e.Temporal.Instant)return t;if(t instanceof e.Temporal.ZonedDateTime)return t.toInstant();n.timeZone||o(`This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.`,i);let r=s(n.timeZone);if(t instanceof e.Temporal.PlainDateTime)return t.toZonedDateTime(r,{disambiguation:n.disambiguation}).toInstant();if(t instanceof e.Temporal.PlainDate)return t.toZonedDateTime({timeZone:r}).toInstant();o(`Unsupported time input type: ${String(t)}`,a)}function p(t,n){let r=s(n.timeZone);if(t instanceof e.Temporal.ZonedDateTime)return t.withTimeZone(r);if(t instanceof e.Temporal.Instant)return t.toZonedDateTimeISO(r);if(t instanceof e.Temporal.PlainDateTime)return t.toZonedDateTime(r,{disambiguation:n.disambiguation});if(t instanceof e.Temporal.PlainDate)return t.toZonedDateTime({timeZone:r});o(`Unsupported time input type: ${String(t)}`,a)}function m(e,t){return p(e,{timeZone:t})}function h(t,n){try{return n.as===`zonedDateTime`?e.Temporal.ZonedDateTime.from(t):n.as===`instant`?e.Temporal.Instant.from(t):n.as===`plainDateTime`?e.Temporal.PlainDateTime.from(t):e.Temporal.PlainDate.from(t)}catch{o(`Invalid ${n.as} ISO 8601 string: "${t}".`)}}function g(t){return e.Temporal.Now.zonedDateTimeISO(s(t.timeZone))}function ee(){return e.Temporal.Now.instant()}function _(e,t,n={}){let r=c(e,n);return p(e,{disambiguation:n.disambiguation,timeZone:r}).add(t)}function v(t){let{end:n,largestUnit:r,roundingIncrement:i,roundingMode:a,smallestUnit:o,start:s}=t,c={largestUnit:r,roundingIncrement:i,roundingMode:a,smallestUnit:o};if(!(r!==void 0&&d.has(r)||o!==void 0&&d.has(o))&&s instanceof e.Temporal.Instant&&n instanceof e.Temporal.Instant)return n.since(s,c);let u=l([s,n],t),f={disambiguation:t.disambiguation,timeZone:u};return p(n,f).since(p(s,f),c)}function y(t){return t instanceof e.Temporal.Instant||t instanceof e.Temporal.ZonedDateTime||t instanceof e.Temporal.PlainDateTime||t instanceof e.Temporal.PlainDate}var b={hour:0,microsecond:0,millisecond:0,minute:0,nanosecond:0,second:0},x={day:b,hour:{microsecond:0,millisecond:0,minute:0,nanosecond:0,second:0},minute:{microsecond:0,millisecond:0,nanosecond:0,second:0},month:{...b,day:1},year:{...b,day:1,month:1}};function S(e,t,n){let r=p(e,n);if(t===`week`){let e=(r.dayOfWeek-(n.weekStartsOn??1)+7)%7;return r.subtract({days:e}).with(b).toInstant()}return r.with(x[t]).toInstant()}var C={day:{days:1},hour:{hours:1},minute:{minutes:1},month:{months:1},week:{weeks:1},year:{years:1}};function w(e,t,n={}){let r=c(e,n);return S(e,t,{timeZone:r,weekStartsOn:n.weekStartsOn}).toZonedDateTimeISO(r)}function T(e,t,n={}){let r=c(e,n);return S(e,t,{timeZone:r,weekStartsOn:n.weekStartsOn}).toZonedDateTimeISO(r).add(C[t]).subtract({nanoseconds:1})}function E(t,n,r){if(!r.unit)return e.Temporal.Instant.compare(f(t,r),f(n,r));let i={timeZone:l([t,n],r),weekStartsOn:r.weekStartsOn};return e.Temporal.Instant.compare(S(t,r.unit,i),S(n,r.unit,i))}function D({end:e,start:t,value:n,...r}){if(!r.unit){let i=f(n,r),[a,o]=u(f(t,r),f(e,r));return{lower:a,target:i,upper:o}}let i={timeZone:l([n,t,e],r),weekStartsOn:r.weekStartsOn},a=S(n,r.unit,i),[o,s]=u(S(t,r.unit,i),S(e,r.unit,i));return{lower:o,target:a,upper:s}}function te(e,t,n={}){return E(e,t,n)<0}function ne(e,t,n={}){return E(e,t,n)>0}function re(e,t,n={}){return E(e,t,n)===0}function O(t){let{lower:n,target:r,upper:i}=D(t);return e.Temporal.Instant.compare(n,r)<=0&&e.Temporal.Instant.compare(r,i)<=0}function k(t){let{lower:n,target:r,upper:i}=D(t),a=e.Temporal.Instant.compare(r,n)<0?n:e.Temporal.Instant.compare(r,i)>0?i:r;return t.value instanceof e.Temporal.ZonedDateTime?a.toZonedDateTimeISO(t.timeZone??t.value.timeZoneId):a}var A=128;function j(e,t,n){let r=e.get(t);if(r!==void 0)return r;if(e.size>=A){let t=e.keys().next().value;t!==void 0&&e.delete(t)}let i=n();return e.set(t,i),i}var M=new Map,N=new Map,P=new Map,F={"date-only":{dateStyle:`short`},long:{dateStyle:`full`,timeStyle:`long`},medium:{dateStyle:`medium`,timeStyle:`short`},short:{dateStyle:`short`,timeStyle:`short`},"time-only":{timeStyle:`short`}};function I(e){return JSON.stringify(Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,String(t)]))}function L(e,t){let n=e.timeZone??t,r=e.locale;if(e.intl!==void 0)return j(M,`${String(r??``)}|intl|${n??``}|${I(e.intl)}`,()=>{let t=n===void 0?e.intl:{...e.intl,timeZone:n};return new Intl.DateTimeFormat(r,t)});let i=e.pattern??`medium`;return j(M,`${String(r??``)}|${i}|${n??``}`,()=>new Intl.DateTimeFormat(r,{...F[i],timeZone:n}))}function R(e){return j(N,`${String(e.locale??``)}|${e.numeric??`auto`}|${e.style??`long`}`,()=>new Intl.RelativeTimeFormat(e.locale,{numeric:e.numeric??`auto`,style:e.style??`long`}))}function z(e){let t=Intl;return t.DurationFormat?j(P,`${String(e.locale??``)}|${e.style??``}`,()=>new t.DurationFormat(e.locale,{style:e.style})):null}var B=60,V=3600,H=86400,U=604800,W=2629800,G=31557600,K=[{scale:1,thresholdToPromote:B,unit:`second`},{scale:B,thresholdToPromote:V/B,unit:`minute`},{scale:V,thresholdToPromote:H/V,unit:`hour`},{scale:H,thresholdToPromote:U/H,unit:`day`},{scale:U,thresholdToPromote:W/U,unit:`week`},{scale:W,thresholdToPromote:12,unit:`month`},{scale:G,thresholdToPromote:1/0,unit:`year`}];function q(e){Number.isFinite(e)||o(`formatRelative received a non-finite time difference.`);let t=Math.round(e);for(let{scale:e,thresholdToPromote:n,unit:r}of K){let i=Math.round(t/e);if(Math.abs(i)<n)return{unit:r,value:i}}return{unit:`year`,value:Math.round(t/G)}}var ie=[`years`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`,`microseconds`,`nanoseconds`];function J(e){let t=[];for(let n of ie){let r=Math.abs(e[n]);r!==0&&t.push(`${r} ${r===1?n.slice(0,-1):n}`)}return t.length===0?`0 seconds`:t.join(`, `)}function Y(t,n,r,i){if(r.timeZone)return r.timeZone;let a=t instanceof e.Temporal.ZonedDateTime?t.timeZoneId:void 0,s=n instanceof e.Temporal.ZonedDateTime?n.timeZoneId:void 0;return a&&s&&a!==s&&o(`${i} received ZonedDateTime inputs with different time zones. Pass options.timeZone explicitly.`),a??s}function ae(t,n={}){let r=n.timeZone??(t instanceof e.Temporal.ZonedDateTime?t.timeZoneId:void 0);return L(n,r).format(new Date(f(t,{timeZone:r}).epochMilliseconds))}function oe(e,t,n={}){let r=Y(e,t,n,`formatRange`);return L(n,r).formatRange(new Date(f(e,{timeZone:r}).epochMilliseconds),new Date(f(t,{timeZone:r}).epochMilliseconds))}function se(e,t,n={}){let r=Y(e,t,n,`formatRangeParts`);return L(n,r).formatRangeToParts(new Date(f(e,{timeZone:r}).epochMilliseconds),new Date(f(t,{timeZone:r}).epochMilliseconds))}function ce(e,t={}){return f(e,t).toString()}function le(e,t={}){return p(e,{timeZone:c(e,t)}).toString()}function ue(t,n={}){let r=t instanceof e.Temporal.Instant?t:t.toInstant(),i=n.base?n.base instanceof e.Temporal.Instant?n.base:n.base.toInstant():e.Temporal.Now.instant(),{unit:a,value:o}=q((r.epochMilliseconds-i.epochMilliseconds)/1e3);return R(n).format(o,a)}function X(t){try{return e.Temporal.Duration.from(t)}catch{o(`Invalid duration input: "${String(t)}". Expected an ISO 8601 duration string or Temporal.DurationLike.`)}}function de(e,t={}){let n=X(e),r=z(t);return r?r.format(n):J(n)}function fe(t,n={}){let r=n.timeZone??(t instanceof e.Temporal.ZonedDateTime?t.timeZoneId:void 0);return L(n,r).formatToParts(new Date(f(t,{timeZone:r}).epochMilliseconds))}function pe(e,t={}){let{unit:n,value:r}=e;return`${t.locale?new Intl.NumberFormat(t.locale).format(r):String(r)} ${r===1?n:`${n}s`}`}var Z={day:864e5,hour:36e5,microsecond:1/1e3,millisecond:1,minute:6e4,nanosecond:1/1e6,second:1e3,week:6048e5},me=[{field:`years`,unit:`year`},{field:`months`,unit:`month`},{field:`weeks`,unit:`week`},{field:`days`,unit:`day`},{field:`hours`,unit:`hour`},{field:`minutes`,unit:`minute`},{field:`seconds`,unit:`second`},{field:`milliseconds`,unit:`millisecond`}];function Q(t){let r=e.Temporal.Duration.from(t);if(r.years||r.months)throw new n(`classifyExpiry thresholds cannot contain months or years. Use fixed elapsed-time units.`);return r.weeks*Z.week+r.days*Z.day+r.hours*Z.hour+r.minutes*Z.minute+r.seconds*Z.second+r.milliseconds+r.microseconds*Z.microsecond+r.nanoseconds*Z.nanosecond}function he(t){let n=t.relativeTo??e.Temporal.Now.instant(),r=f(t.value,t).epochMilliseconds-n.epochMilliseconds;return Object.entries(t.thresholds).map(([e,t])=>({key:e,max:Q(t)})).sort((e,t)=>e.max-t.max).find(({max:e})=>r<=e)?.key??null}function $(e){for(let{field:t,unit:n}of me){let r=Math.abs(e[t]);if(r>0)return{unit:n,value:r}}return{unit:`millisecond`,value:0}}function ge(t,n=e.Temporal.Now.instant(),r={}){if(!r.timeZone&&t instanceof e.Temporal.Instant&&n instanceof e.Temporal.Instant){let r=t.toZonedDateTimeISO(`UTC`),i=n.toZonedDateTimeISO(`UTC`);return $(e.Temporal.ZonedDateTime.compare(r,i)<=0?i.since(r,{largestUnit:`year`}):r.since(i,{largestUnit:`year`}))}let i=l([t,n],r),a=p(t,{timeZone:i}),o=p(n,{timeZone:i});return $(e.Temporal.ZonedDateTime.compare(a,o)<=0?o.since(a,{largestUnit:`year`}):a.since(o,{largestUnit:`year`}))}function _e(t,r,i,a={}){let o=c(t,a),s=p(t,{timeZone:o}),l=p(r,{timeZone:o});if(e.Temporal.ZonedDateTime.compare(s.add(i),s)<=0)throw new n(`dateRange: step must advance time forward.`);return ve(s,l,i)}function*ve(t,n,r){for(let i=t;e.Temporal.ZonedDateTime.compare(i,n)<=0;i=i.add(r))yield i}function ye(e,t,n={}){let r=c(e,n),i=t.frequency===`daily`?{days:t.interval??1}:t.frequency===`weekly`?{weeks:t.interval??1}:t.frequency===`monthly`?{months:t.interval??1}:{years:t.interval??1},a=t.until?f(t.until,{timeZone:r}):void 0;return be(p(e,{timeZone:r}),i,t.count,a)}function*be(t,n,r,i){for(let a=t,o=0;r===void 0||o<r;a=a.add(n),o++){if(i&&e.Temporal.Instant.compare(a.toInstant(),i)>0)return;yield a}}exports.TempoError=t,exports.TempoInvalidInputError=n,exports.TempoInvalidTzError=r,exports.TempoMissingTzError=i,exports.TempoUnsupportedInputError=a,Object.defineProperty(exports,"Temporal",{enumerable:!0,get:function(){return e.Temporal}}),exports.clamp=k,exports.classifyExpiry=he,exports.contains=O,exports.dateRange=_e,exports.difference=v,exports.endOf=T,exports.format=ae,exports.formatDuration=de,exports.formatInstant=ce,exports.formatParts=fe,exports.formatRange=oe,exports.formatRangeParts=se,exports.formatRelative=ue,exports.formatZoned=le,exports.humanize=pe,exports.inTimeZone=m,exports.isAfter=ne,exports.isBefore=te,exports.isSame=re,exports.isValid=y,exports.now=g,exports.nowInstant=ee,exports.parse=h,exports.parseDuration=X,exports.recurrence=ye,exports.shift=_,exports.startOf=w,exports.timeDiff=ge,exports.toInstant=f;
|
|
2
2
|
//# sourceMappingURL=tempo.cjs.map
|