@vielzeug/tempo 2.1.2 → 2.2.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/dist/_tz.cjs +1 -1
- package/dist/_tz.cjs.map +1 -1
- package/dist/_tz.d.ts.map +1 -1
- package/dist/_tz.js +2 -2
- package/dist/_tz.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +25 -25
- package/dist/core.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -2
- package/dist/errors.js.map +1 -1
- package/dist/format.cjs +1 -1
- package/dist/format.cjs.map +1 -1
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +67 -67
- package/dist/format.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/package.json +1 -1
package/dist/_tz.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./errors.cjs");let t=require("@js-temporal/polyfill");function n(n){try{t.Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(n)}catch{e.fail(`Unknown or invalid timezone: "${n}". Expected an IANA timezone name or UTC offset.`,e.TempoInvalidTzError)}return n}function r(r,i){let a=i.timeZone??(r instanceof t.Temporal.ZonedDateTime?r.timeZoneId:void 0);return a||e.fail(`This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.`,e.TempoMissingTzError),n(a)}function i(r,i){if(i.timeZone)return n(i.timeZone);let a;for(let n of r)n instanceof t.Temporal.ZonedDateTime&&(a?a!==n.timeZoneId&&e.fail(`Inputs use different time zones. Pass options.timeZone explicitly.`):a=n.timeZoneId);return a||e.fail(`This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.`,e.TempoMissingTzError),a}var a=new Set([`day`,`month`,`week`,`year`]);exports.CALENDAR_UNITS=a,exports.inferSharedTimeZone=i,exports.inferTimeZone=r,exports.validateTimeZone=n;
|
|
1
|
+
const e=require("./errors.cjs");let t=require("@js-temporal/polyfill");function n(n){try{t.Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(n)}catch(t){e.fail(`Unknown or invalid timezone: "${n}". Expected an IANA timezone name or UTC offset.`,e.TempoInvalidTzError,{cause:t})}return n}function r(r,i){let a=i.timeZone??(r instanceof t.Temporal.ZonedDateTime?r.timeZoneId:void 0);return a||e.fail(`This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.`,e.TempoMissingTzError),n(a)}function i(r,i){if(i.timeZone)return n(i.timeZone);let a;for(let n of r)n instanceof t.Temporal.ZonedDateTime&&(a?a!==n.timeZoneId&&e.fail(`Inputs use different time zones. Pass options.timeZone explicitly.`):a=n.timeZoneId);return a||e.fail(`This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.`,e.TempoMissingTzError),a}var a=new Set([`day`,`month`,`week`,`year`]);exports.CALENDAR_UNITS=a,exports.inferSharedTimeZone=i,exports.inferTimeZone=r,exports.validateTimeZone=n;
|
|
2
2
|
//# sourceMappingURL=_tz.cjs.map
|
package/dist/_tz.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_tz.cjs","names":[],"sources":["../src/_tz.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { fail, TempoInvalidTzError, TempoMissingTzError } from './errors';\nimport type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';\n\nexport function validateTimeZone(timeZone: string): string {\n try {\n Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(timeZone);\n } catch {\n fail(\n `Unknown or invalid timezone: \"${timeZone}\". Expected an IANA timezone name or UTC offset.`,\n TempoInvalidTzError,\n );\n }\n\n return timeZone;\n}\n\nexport function inferTimeZone(input: TimeInput, options: TimeZoneOptions): string {\n const timeZone = options.timeZone ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n if (!timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return validateTimeZone(timeZone);\n}\n\nexport function inferSharedTimeZone(inputs: readonly TimeInput[], options: TimeZoneOptions): string {\n if (options.timeZone) return validateTimeZone(options.timeZone);\n\n let inferred: string | undefined;\n\n for (const input of inputs) {\n if (!(input instanceof Temporal.ZonedDateTime)) continue;\n\n if (!inferred) inferred = input.timeZoneId;\n else if (inferred !== input.timeZoneId) {\n fail('Inputs use different time zones. Pass options.timeZone explicitly.');\n }\n }\n\n if (!inferred) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return inferred;\n}\n\nexport const CALENDAR_UNITS = new Set<CalendarUnit>(['day', 'month', 'week', 'year']);\n"],"mappings":"uEAIA,SAAgB,EAAiB,EAA0B,CACzD,GAAI,CACF,EAAA,SAAS,QAAQ,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,CAAQ,CACvE,
|
|
1
|
+
{"version":3,"file":"_tz.cjs","names":[],"sources":["../src/_tz.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { fail, TempoInvalidTzError, TempoMissingTzError } from './errors';\nimport type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';\n\nexport function validateTimeZone(timeZone: string): string {\n try {\n Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(timeZone);\n } catch (error) {\n fail(\n `Unknown or invalid timezone: \"${timeZone}\". Expected an IANA timezone name or UTC offset.`,\n TempoInvalidTzError,\n { cause: error },\n );\n }\n\n return timeZone;\n}\n\nexport function inferTimeZone(input: TimeInput, options: TimeZoneOptions): string {\n const timeZone = options.timeZone ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n if (!timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return validateTimeZone(timeZone);\n}\n\nexport function inferSharedTimeZone(inputs: readonly TimeInput[], options: TimeZoneOptions): string {\n if (options.timeZone) return validateTimeZone(options.timeZone);\n\n let inferred: string | undefined;\n\n for (const input of inputs) {\n if (!(input instanceof Temporal.ZonedDateTime)) continue;\n\n if (!inferred) inferred = input.timeZoneId;\n else if (inferred !== input.timeZoneId) {\n fail('Inputs use different time zones. Pass options.timeZone explicitly.');\n }\n }\n\n if (!inferred) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return inferred;\n}\n\nexport const CALENDAR_UNITS = new Set<CalendarUnit>(['day', 'month', 'week', 'year']);\n"],"mappings":"uEAIA,SAAgB,EAAiB,EAA0B,CACzD,GAAI,CACF,EAAA,SAAS,QAAQ,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,CAAQ,CACvE,OAAS,EAAO,CACd,EAAA,KACE,iCAAiC,EAAS,kDAC1C,EAAA,oBACA,CAAE,MAAO,CAAM,CACjB,CACF,CAEA,OAAO,CACT,CAEA,SAAgB,EAAc,EAAkB,EAAkC,CAChF,IAAM,EAAW,EAAQ,WAAa,aAAiB,EAAA,SAAS,cAAgB,EAAM,WAAa,IAAA,IASnG,OAPK,GACH,EAAA,KACE,0FACA,EAAA,mBACF,EAGK,EAAiB,CAAQ,CAClC,CAEA,SAAgB,EAAoB,EAA8B,EAAkC,CAClG,GAAI,EAAQ,SAAU,OAAO,EAAiB,EAAQ,QAAQ,EAE9D,IAAI,EAEJ,IAAK,IAAM,KAAS,EACZ,aAAiB,EAAA,SAAS,gBAE3B,EACI,IAAa,EAAM,YAC1B,EAAA,KAAK,oEAAoE,EAF5D,EAAW,EAAM,YAalC,OAPK,GACH,EAAA,KACE,0FACA,EAAA,mBACF,EAGK,CACT,CAEA,IAAa,EAAiB,IAAI,IAAkB,CAAC,MAAO,QAAS,OAAQ,MAAM,CAAC"}
|
package/dist/_tz.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_tz.d.ts","sourceRoot":"","sources":["../src/_tz.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAExE,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"_tz.d.ts","sourceRoot":"","sources":["../src/_tz.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAExE,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAYzD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,GAAG,MAAM,CAWhF;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,EAAE,OAAO,EAAE,eAAe,GAAG,MAAM,CAsBlG;AAED,eAAO,MAAM,cAAc,mBAA0D,CAAC"}
|
package/dist/_tz.js
CHANGED
|
@@ -4,8 +4,8 @@ import { Temporal as r } from "@js-temporal/polyfill";
|
|
|
4
4
|
function i(t) {
|
|
5
5
|
try {
|
|
6
6
|
r.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(t);
|
|
7
|
-
} catch {
|
|
8
|
-
n(`Unknown or invalid timezone: "${t}". Expected an IANA timezone name or UTC offset.`, e);
|
|
7
|
+
} catch (r) {
|
|
8
|
+
n(`Unknown or invalid timezone: "${t}". Expected an IANA timezone name or UTC offset.`, e, { cause: r });
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
}
|
package/dist/_tz.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_tz.js","names":[],"sources":["../src/_tz.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { fail, TempoInvalidTzError, TempoMissingTzError } from './errors';\nimport type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';\n\nexport function validateTimeZone(timeZone: string): string {\n try {\n Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(timeZone);\n } catch {\n fail(\n `Unknown or invalid timezone: \"${timeZone}\". Expected an IANA timezone name or UTC offset.`,\n TempoInvalidTzError,\n );\n }\n\n return timeZone;\n}\n\nexport function inferTimeZone(input: TimeInput, options: TimeZoneOptions): string {\n const timeZone = options.timeZone ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n if (!timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return validateTimeZone(timeZone);\n}\n\nexport function inferSharedTimeZone(inputs: readonly TimeInput[], options: TimeZoneOptions): string {\n if (options.timeZone) return validateTimeZone(options.timeZone);\n\n let inferred: string | undefined;\n\n for (const input of inputs) {\n if (!(input instanceof Temporal.ZonedDateTime)) continue;\n\n if (!inferred) inferred = input.timeZoneId;\n else if (inferred !== input.timeZoneId) {\n fail('Inputs use different time zones. Pass options.timeZone explicitly.');\n }\n }\n\n if (!inferred) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return inferred;\n}\n\nexport const CALENDAR_UNITS = new Set<CalendarUnit>(['day', 'month', 'week', 'year']);\n"],"mappings":";;;AAIA,SAAgB,EAAiB,GAA0B;CACzD,IAAI;EACF,EAAS,QAAQ,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,CAAQ;CACvE,
|
|
1
|
+
{"version":3,"file":"_tz.js","names":[],"sources":["../src/_tz.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { fail, TempoInvalidTzError, TempoMissingTzError } from './errors';\nimport type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';\n\nexport function validateTimeZone(timeZone: string): string {\n try {\n Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(timeZone);\n } catch (error) {\n fail(\n `Unknown or invalid timezone: \"${timeZone}\". Expected an IANA timezone name or UTC offset.`,\n TempoInvalidTzError,\n { cause: error },\n );\n }\n\n return timeZone;\n}\n\nexport function inferTimeZone(input: TimeInput, options: TimeZoneOptions): string {\n const timeZone = options.timeZone ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n if (!timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return validateTimeZone(timeZone);\n}\n\nexport function inferSharedTimeZone(inputs: readonly TimeInput[], options: TimeZoneOptions): string {\n if (options.timeZone) return validateTimeZone(options.timeZone);\n\n let inferred: string | undefined;\n\n for (const input of inputs) {\n if (!(input instanceof Temporal.ZonedDateTime)) continue;\n\n if (!inferred) inferred = input.timeZoneId;\n else if (inferred !== input.timeZoneId) {\n fail('Inputs use different time zones. Pass options.timeZone explicitly.');\n }\n }\n\n if (!inferred) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return inferred;\n}\n\nexport const CALENDAR_UNITS = new Set<CalendarUnit>(['day', 'month', 'week', 'year']);\n"],"mappings":";;;AAIA,SAAgB,EAAiB,GAA0B;CACzD,IAAI;EACF,EAAS,QAAQ,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,CAAQ;CACvE,SAAS,GAAO;EACd,EACE,iCAAiC,EAAS,mDAC1C,GACA,EAAE,OAAO,EAAM,CACjB;CACF;CAEA,OAAO;AACT;AAEA,SAAgB,EAAc,GAAkB,GAAkC;CAChF,IAAM,IAAW,EAAQ,aAAa,aAAiB,EAAS,gBAAgB,EAAM,aAAa,KAAA;CASnG,OAPK,KACH,EACE,2FACA,CACF,GAGK,EAAiB,CAAQ;AAClC;AAEA,SAAgB,EAAoB,GAA8B,GAAkC;CAClG,IAAI,EAAQ,UAAU,OAAO,EAAiB,EAAQ,QAAQ;CAE9D,IAAI;CAEJ,KAAK,IAAM,KAAS,GACZ,aAAiB,EAAS,kBAE3B,IACI,MAAa,EAAM,cAC1B,EAAK,oEAAoE,IAF5D,IAAW,EAAM;CAalC,OAPK,KACH,EACE,2FACA,CACF,GAGK;AACT;AAEA,IAAa,oBAAiB,IAAI,IAAkB;CAAC;CAAO;CAAS;CAAQ;AAAM,CAAC"}
|
package/dist/core.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(t,n){try{return n.as===`zonedDateTime`?r.Temporal.ZonedDateTime.from(t):n.as===`instant`?r.Temporal.Instant.from(t):n.as===`plainDateTime`?r.Temporal.PlainDateTime.from(t):r.Temporal.PlainDate.from(t)}catch{e.fail(`Invalid ${n.as} ISO 8601 string: "${t}"
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./_tz.cjs"),n=require("./_convert.cjs");let r=require("@js-temporal/polyfill");function i(t,n){try{return n.as===`zonedDateTime`?r.Temporal.ZonedDateTime.from(t):n.as===`instant`?r.Temporal.Instant.from(t):n.as===`plainDateTime`?r.Temporal.PlainDateTime.from(t):r.Temporal.PlainDate.from(t)}catch(r){e.fail(`Invalid ${n.as} ISO 8601 string: "${t}".`,e.TempoInvalidInputError,{cause:r})}}function a(e){return r.Temporal.Now.zonedDateTimeISO(t.validateTimeZone(e.timeZone))}function o(){return r.Temporal.Now.instant()}function s(e,r,i={}){let a=t.inferTimeZone(e,i);return n.toZoned(e,{disambiguation:i.disambiguation,timeZone:a}).add(r)}function c(e){let{end:i,largestUnit:a,roundingIncrement:o,roundingMode:s,smallestUnit:c,start:l}=e,u={largestUnit:a,roundingIncrement:o,roundingMode:s,smallestUnit:c};if(!(a!==void 0&&t.CALENDAR_UNITS.has(a)||c!==void 0&&t.CALENDAR_UNITS.has(c))&&l instanceof r.Temporal.Instant&&i instanceof r.Temporal.Instant)return i.since(l,u);let d=t.inferSharedTimeZone([l,i],e),f={disambiguation:e.disambiguation,timeZone:d};return n.toZoned(i,f).since(n.toZoned(l,f),u)}function l(e){return e instanceof r.Temporal.Instant||e instanceof r.Temporal.ZonedDateTime||e instanceof r.Temporal.PlainDateTime||e instanceof r.Temporal.PlainDate}exports.difference=c,exports.isValid=l,exports.now=a,exports.nowInstant=o,exports.parse=i,exports.shift=s;
|
|
2
2
|
//# sourceMappingURL=core.cjs.map
|
package/dist/core.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { toZoned } from './_convert';\nimport { CALENDAR_UNITS, inferSharedTimeZone, inferTimeZone, validateTimeZone } from './_tz';\nimport { fail } from './errors';\nimport type { CalendarUnit, DifferenceInput, ParseAs, ShiftOptions, TimeInput } from './types';\n\n/** Parse intentionally requires an explicit result kind: time strings are ambiguous at system boundaries. */\nexport function parse(input: string, options: { as: 'zonedDateTime' }): Temporal.ZonedDateTime;\nexport function parse(input: string, options: { as: 'instant' }): Temporal.Instant;\nexport function parse(input: string, options: { as: 'plainDateTime' }): Temporal.PlainDateTime;\nexport function parse(input: string, options: { as: 'plainDate' }): Temporal.PlainDate;\nexport function parse(input: string, options: { as: ParseAs }): TimeInput {\n try {\n if (options.as === 'zonedDateTime') return Temporal.ZonedDateTime.from(input);\n\n if (options.as === 'instant') return Temporal.Instant.from(input);\n\n if (options.as === 'plainDateTime') return Temporal.PlainDateTime.from(input);\n\n return Temporal.PlainDate.from(input);\n } catch {\n fail(`Invalid ${options.as} ISO 8601 string: \"${input}\"
|
|
1
|
+
{"version":3,"file":"core.cjs","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { toZoned } from './_convert';\nimport { CALENDAR_UNITS, inferSharedTimeZone, inferTimeZone, validateTimeZone } from './_tz';\nimport { fail, TempoInvalidInputError } from './errors';\nimport type { CalendarUnit, DifferenceInput, ParseAs, ShiftOptions, TimeInput } from './types';\n\n/** Parse intentionally requires an explicit result kind: time strings are ambiguous at system boundaries. */\nexport function parse(input: string, options: { as: 'zonedDateTime' }): Temporal.ZonedDateTime;\nexport function parse(input: string, options: { as: 'instant' }): Temporal.Instant;\nexport function parse(input: string, options: { as: 'plainDateTime' }): Temporal.PlainDateTime;\nexport function parse(input: string, options: { as: 'plainDate' }): Temporal.PlainDate;\nexport function parse(input: string, options: { as: ParseAs }): TimeInput {\n try {\n if (options.as === 'zonedDateTime') return Temporal.ZonedDateTime.from(input);\n\n if (options.as === 'instant') return Temporal.Instant.from(input);\n\n if (options.as === 'plainDateTime') return Temporal.PlainDateTime.from(input);\n\n return Temporal.PlainDate.from(input);\n } catch (error) {\n fail(`Invalid ${options.as} ISO 8601 string: \"${input}\".`, TempoInvalidInputError, { cause: error });\n }\n}\n\nexport function now(options: { timeZone: string }): Temporal.ZonedDateTime {\n return Temporal.Now.zonedDateTimeISO(validateTimeZone(options.timeZone));\n}\n\nexport function nowInstant(): Temporal.Instant {\n return Temporal.Now.instant();\n}\n\nexport function shift(\n input: Temporal.ZonedDateTime,\n duration: Temporal.DurationLike,\n options?: ShiftOptions,\n): Temporal.ZonedDateTime;\nexport function shift(\n input: Exclude<TimeInput, Temporal.ZonedDateTime>,\n duration: Temporal.DurationLike,\n options: ShiftOptions & { timeZone: string },\n): Temporal.ZonedDateTime;\nexport function shift(\n input: TimeInput,\n duration: Temporal.DurationLike,\n options: ShiftOptions = {},\n): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n\n return toZoned(input, { disambiguation: options.disambiguation, timeZone }).add(duration);\n}\n\nexport function difference(input: DifferenceInput): Temporal.Duration {\n const { end, largestUnit, roundingIncrement, roundingMode, smallestUnit, start } = input;\n const rounding = { largestUnit, roundingIncrement, roundingMode, smallestUnit };\n const needsCalendar =\n (largestUnit !== undefined && CALENDAR_UNITS.has(largestUnit as CalendarUnit)) ||\n (smallestUnit !== undefined && CALENDAR_UNITS.has(smallestUnit as CalendarUnit));\n\n if (!needsCalendar && start instanceof Temporal.Instant && end instanceof Temporal.Instant) {\n return end.since(start, rounding as Temporal.DifferenceOptions<Temporal.TimeUnit>);\n }\n\n const timeZone = inferSharedTimeZone([start, end], input);\n const options = { disambiguation: input.disambiguation, timeZone };\n\n return toZoned(end, options).since(toZoned(start, options), rounding);\n}\n\nexport function isValid(value: unknown): value is TimeInput {\n return (\n value instanceof Temporal.Instant ||\n value instanceof Temporal.ZonedDateTime ||\n value instanceof Temporal.PlainDateTime ||\n value instanceof Temporal.PlainDate\n );\n}\n"],"mappings":"0HAWA,SAAgB,EAAM,EAAe,EAAqC,CACxE,GAAI,CAOF,OANI,EAAQ,KAAO,gBAAwB,EAAA,SAAS,cAAc,KAAK,CAAK,EAExE,EAAQ,KAAO,UAAkB,EAAA,SAAS,QAAQ,KAAK,CAAK,EAE5D,EAAQ,KAAO,gBAAwB,EAAA,SAAS,cAAc,KAAK,CAAK,EAErE,EAAA,SAAS,UAAU,KAAK,CAAK,CACtC,OAAS,EAAO,CACd,EAAA,KAAK,WAAW,EAAQ,GAAG,qBAAqB,EAAM,IAAK,EAAA,uBAAwB,CAAE,MAAO,CAAM,CAAC,CACrG,CACF,CAEA,SAAgB,EAAI,EAAuD,CACzE,OAAO,EAAA,SAAS,IAAI,iBAAiB,EAAA,iBAAiB,EAAQ,QAAQ,CAAC,CACzE,CAEA,SAAgB,GAA+B,CAC7C,OAAO,EAAA,SAAS,IAAI,QAAQ,CAC9B,CAYA,SAAgB,EACd,EACA,EACA,EAAwB,CAAC,EACD,CACxB,IAAM,EAAW,EAAA,cAAc,EAAO,CAAO,EAE7C,OAAO,EAAA,QAAQ,EAAO,CAAE,eAAgB,EAAQ,eAAgB,UAAS,CAAC,CAAC,CAAC,IAAI,CAAQ,CAC1F,CAEA,SAAgB,EAAW,EAA2C,CACpE,GAAM,CAAE,MAAK,cAAa,oBAAmB,eAAc,eAAc,SAAU,EAC7E,EAAW,CAAE,cAAa,oBAAmB,eAAc,cAAa,EAK9E,GAAI,EAHD,IAAgB,IAAA,IAAa,EAAA,eAAe,IAAI,CAA2B,GAC3E,IAAiB,IAAA,IAAa,EAAA,eAAe,IAAI,CAA4B,IAE1D,aAAiB,EAAA,SAAS,SAAW,aAAe,EAAA,SAAS,QACjF,OAAO,EAAI,MAAM,EAAO,CAAyD,EAGnF,IAAM,EAAW,EAAA,oBAAoB,CAAC,EAAO,CAAG,EAAG,CAAK,EAClD,EAAU,CAAE,eAAgB,EAAM,eAAgB,UAAS,EAEjE,OAAO,EAAA,QAAQ,EAAK,CAAO,CAAC,CAAC,MAAM,EAAA,QAAQ,EAAO,CAAO,EAAG,CAAQ,CACtE,CAEA,SAAgB,EAAQ,EAAoC,CAC1D,OACE,aAAiB,EAAA,SAAS,SAC1B,aAAiB,EAAA,SAAS,eAC1B,aAAiB,EAAA,SAAS,eAC1B,aAAiB,EAAA,SAAS,SAE9B"}
|
package/dist/core.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CALENDAR_UNITS as
|
|
3
|
-
import { toZoned as
|
|
4
|
-
import { Temporal as
|
|
1
|
+
import { TempoInvalidInputError as e, fail as t } from "./errors.js";
|
|
2
|
+
import { CALENDAR_UNITS as n, inferSharedTimeZone as r, inferTimeZone as i, validateTimeZone as a } from "./_tz.js";
|
|
3
|
+
import { toZoned as o } from "./_convert.js";
|
|
4
|
+
import { Temporal as s } from "@js-temporal/polyfill";
|
|
5
5
|
//#region src/core.ts
|
|
6
|
-
function
|
|
6
|
+
function c(n, r) {
|
|
7
7
|
try {
|
|
8
|
-
return
|
|
9
|
-
} catch {
|
|
10
|
-
|
|
8
|
+
return r.as === "zonedDateTime" ? s.ZonedDateTime.from(n) : r.as === "instant" ? s.Instant.from(n) : r.as === "plainDateTime" ? s.PlainDateTime.from(n) : s.PlainDate.from(n);
|
|
9
|
+
} catch (i) {
|
|
10
|
+
t(`Invalid ${r.as} ISO 8601 string: "${n}".`, e, { cause: i });
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
return
|
|
13
|
+
function l(e) {
|
|
14
|
+
return s.Now.zonedDateTimeISO(a(e.timeZone));
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
return
|
|
16
|
+
function u() {
|
|
17
|
+
return s.Now.instant();
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
let
|
|
21
|
-
return
|
|
19
|
+
function d(e, t, n = {}) {
|
|
20
|
+
let r = i(e, n);
|
|
21
|
+
return o(e, {
|
|
22
22
|
disambiguation: n.disambiguation,
|
|
23
|
-
timeZone:
|
|
23
|
+
timeZone: r
|
|
24
24
|
}).add(t);
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
let { end:
|
|
26
|
+
function f(e) {
|
|
27
|
+
let { end: t, largestUnit: i, roundingIncrement: a, roundingMode: c, smallestUnit: l, start: u } = e, d = {
|
|
28
28
|
largestUnit: i,
|
|
29
|
-
roundingIncrement:
|
|
29
|
+
roundingIncrement: a,
|
|
30
30
|
roundingMode: c,
|
|
31
31
|
smallestUnit: l
|
|
32
32
|
};
|
|
33
|
-
if (!(i !== void 0 &&
|
|
34
|
-
let f =
|
|
33
|
+
if (!(i !== void 0 && n.has(i) || l !== void 0 && n.has(l)) && u instanceof s.Instant && t instanceof s.Instant) return t.since(u, d);
|
|
34
|
+
let f = r([u, t], e), p = {
|
|
35
35
|
disambiguation: e.disambiguation,
|
|
36
36
|
timeZone: f
|
|
37
37
|
};
|
|
38
|
-
return
|
|
38
|
+
return o(t, p).since(o(u, p), d);
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
return e instanceof
|
|
40
|
+
function p(e) {
|
|
41
|
+
return e instanceof s.Instant || e instanceof s.ZonedDateTime || e instanceof s.PlainDateTime || e instanceof s.PlainDate;
|
|
42
42
|
}
|
|
43
43
|
//#endregion
|
|
44
|
-
export {
|
|
44
|
+
export { f as difference, p as isValid, l as now, u as nowInstant, c as parse, d as shift };
|
|
45
45
|
|
|
46
46
|
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { toZoned } from './_convert';\nimport { CALENDAR_UNITS, inferSharedTimeZone, inferTimeZone, validateTimeZone } from './_tz';\nimport { fail } from './errors';\nimport type { CalendarUnit, DifferenceInput, ParseAs, ShiftOptions, TimeInput } from './types';\n\n/** Parse intentionally requires an explicit result kind: time strings are ambiguous at system boundaries. */\nexport function parse(input: string, options: { as: 'zonedDateTime' }): Temporal.ZonedDateTime;\nexport function parse(input: string, options: { as: 'instant' }): Temporal.Instant;\nexport function parse(input: string, options: { as: 'plainDateTime' }): Temporal.PlainDateTime;\nexport function parse(input: string, options: { as: 'plainDate' }): Temporal.PlainDate;\nexport function parse(input: string, options: { as: ParseAs }): TimeInput {\n try {\n if (options.as === 'zonedDateTime') return Temporal.ZonedDateTime.from(input);\n\n if (options.as === 'instant') return Temporal.Instant.from(input);\n\n if (options.as === 'plainDateTime') return Temporal.PlainDateTime.from(input);\n\n return Temporal.PlainDate.from(input);\n } catch {\n fail(`Invalid ${options.as} ISO 8601 string: \"${input}\"
|
|
1
|
+
{"version":3,"file":"core.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { toZoned } from './_convert';\nimport { CALENDAR_UNITS, inferSharedTimeZone, inferTimeZone, validateTimeZone } from './_tz';\nimport { fail, TempoInvalidInputError } from './errors';\nimport type { CalendarUnit, DifferenceInput, ParseAs, ShiftOptions, TimeInput } from './types';\n\n/** Parse intentionally requires an explicit result kind: time strings are ambiguous at system boundaries. */\nexport function parse(input: string, options: { as: 'zonedDateTime' }): Temporal.ZonedDateTime;\nexport function parse(input: string, options: { as: 'instant' }): Temporal.Instant;\nexport function parse(input: string, options: { as: 'plainDateTime' }): Temporal.PlainDateTime;\nexport function parse(input: string, options: { as: 'plainDate' }): Temporal.PlainDate;\nexport function parse(input: string, options: { as: ParseAs }): TimeInput {\n try {\n if (options.as === 'zonedDateTime') return Temporal.ZonedDateTime.from(input);\n\n if (options.as === 'instant') return Temporal.Instant.from(input);\n\n if (options.as === 'plainDateTime') return Temporal.PlainDateTime.from(input);\n\n return Temporal.PlainDate.from(input);\n } catch (error) {\n fail(`Invalid ${options.as} ISO 8601 string: \"${input}\".`, TempoInvalidInputError, { cause: error });\n }\n}\n\nexport function now(options: { timeZone: string }): Temporal.ZonedDateTime {\n return Temporal.Now.zonedDateTimeISO(validateTimeZone(options.timeZone));\n}\n\nexport function nowInstant(): Temporal.Instant {\n return Temporal.Now.instant();\n}\n\nexport function shift(\n input: Temporal.ZonedDateTime,\n duration: Temporal.DurationLike,\n options?: ShiftOptions,\n): Temporal.ZonedDateTime;\nexport function shift(\n input: Exclude<TimeInput, Temporal.ZonedDateTime>,\n duration: Temporal.DurationLike,\n options: ShiftOptions & { timeZone: string },\n): Temporal.ZonedDateTime;\nexport function shift(\n input: TimeInput,\n duration: Temporal.DurationLike,\n options: ShiftOptions = {},\n): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n\n return toZoned(input, { disambiguation: options.disambiguation, timeZone }).add(duration);\n}\n\nexport function difference(input: DifferenceInput): Temporal.Duration {\n const { end, largestUnit, roundingIncrement, roundingMode, smallestUnit, start } = input;\n const rounding = { largestUnit, roundingIncrement, roundingMode, smallestUnit };\n const needsCalendar =\n (largestUnit !== undefined && CALENDAR_UNITS.has(largestUnit as CalendarUnit)) ||\n (smallestUnit !== undefined && CALENDAR_UNITS.has(smallestUnit as CalendarUnit));\n\n if (!needsCalendar && start instanceof Temporal.Instant && end instanceof Temporal.Instant) {\n return end.since(start, rounding as Temporal.DifferenceOptions<Temporal.TimeUnit>);\n }\n\n const timeZone = inferSharedTimeZone([start, end], input);\n const options = { disambiguation: input.disambiguation, timeZone };\n\n return toZoned(end, options).since(toZoned(start, options), rounding);\n}\n\nexport function isValid(value: unknown): value is TimeInput {\n return (\n value instanceof Temporal.Instant ||\n value instanceof Temporal.ZonedDateTime ||\n value instanceof Temporal.PlainDateTime ||\n value instanceof Temporal.PlainDate\n );\n}\n"],"mappings":";;;;;AAWA,SAAgB,EAAM,GAAe,GAAqC;CACxE,IAAI;EAOF,OANI,EAAQ,OAAO,kBAAwB,EAAS,cAAc,KAAK,CAAK,IAExE,EAAQ,OAAO,YAAkB,EAAS,QAAQ,KAAK,CAAK,IAE5D,EAAQ,OAAO,kBAAwB,EAAS,cAAc,KAAK,CAAK,IAErE,EAAS,UAAU,KAAK,CAAK;CACtC,SAAS,GAAO;EACd,EAAK,WAAW,EAAQ,GAAG,qBAAqB,EAAM,KAAK,GAAwB,EAAE,OAAO,EAAM,CAAC;CACrG;AACF;AAEA,SAAgB,EAAI,GAAuD;CACzE,OAAO,EAAS,IAAI,iBAAiB,EAAiB,EAAQ,QAAQ,CAAC;AACzE;AAEA,SAAgB,IAA+B;CAC7C,OAAO,EAAS,IAAI,QAAQ;AAC9B;AAYA,SAAgB,EACd,GACA,GACA,IAAwB,CAAC,GACD;CACxB,IAAM,IAAW,EAAc,GAAO,CAAO;CAE7C,OAAO,EAAQ,GAAO;EAAE,gBAAgB,EAAQ;EAAgB;CAAS,CAAC,CAAC,CAAC,IAAI,CAAQ;AAC1F;AAEA,SAAgB,EAAW,GAA2C;CACpE,IAAM,EAAE,QAAK,gBAAa,sBAAmB,iBAAc,iBAAc,aAAU,GAC7E,IAAW;EAAE;EAAa;EAAmB;EAAc;CAAa;CAK9E,IAAI,EAHD,MAAgB,KAAA,KAAa,EAAe,IAAI,CAA2B,KAC3E,MAAiB,KAAA,KAAa,EAAe,IAAI,CAA4B,MAE1D,aAAiB,EAAS,WAAW,aAAe,EAAS,SACjF,OAAO,EAAI,MAAM,GAAO,CAAyD;CAGnF,IAAM,IAAW,EAAoB,CAAC,GAAO,CAAG,GAAG,CAAK,GAClD,IAAU;EAAE,gBAAgB,EAAM;EAAgB;CAAS;CAEjE,OAAO,EAAQ,GAAK,CAAO,CAAC,CAAC,MAAM,EAAQ,GAAO,CAAO,GAAG,CAAQ;AACtE;AAEA,SAAgB,EAAQ,GAAoC;CAC1D,OACE,aAAiB,EAAS,WAC1B,aAAiB,EAAS,iBAC1B,aAAiB,EAAS,iBAC1B,aAAiB,EAAS;AAE9B"}
|
package/dist/errors.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},t=class extends e{},n=class extends e{},r=class extends e{},i=class extends e{};function a(e,n=t){throw new n(e)}exports.TempoError=e,exports.TempoInvalidInputError=t,exports.TempoInvalidTzError=n,exports.TempoMissingTzError=r,exports.TempoUnsupportedInputError=i,exports.fail=a;
|
|
1
|
+
var e=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},t=class extends e{},n=class extends e{},r=class extends e{},i=class extends e{};function a(e,n=t,r){throw new n(e,r)}exports.TempoError=e,exports.TempoInvalidInputError=t,exports.TempoInvalidTzError=n,exports.TempoMissingTzError=r,exports.TempoUnsupportedInputError=i,exports.fail=a;
|
|
2
2
|
//# sourceMappingURL=errors.cjs.map
|
package/dist/errors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all tempo errors. Use `instanceof TempoError` to catch any tempo-originated error. */\nexport class TempoError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a date/time input string or value cannot be parsed. */\nexport class TempoInvalidInputError extends TempoError {}\n\n/** Thrown when the provided timezone identifier is unknown or invalid. */\nexport class TempoInvalidTzError extends TempoError {}\n\n/** Thrown when an operation requires a timezone but none was supplied. */\nexport class TempoMissingTzError extends TempoError {}\n\n/** Thrown when an input type is not supported by the called operation. */\nexport class TempoUnsupportedInputError extends TempoError {}\n\n// ─── Error helpers ────────────────────────────────────────────────────────────\n\ntype TempoErrorCtor = new (message: string) => TempoError;\n\nexport function fail(message: string, Class: TempoErrorCtor = TempoInvalidInputError): never {\n throw new Class(message);\n}\n"],"mappings":"AACA,IAAa,EAAb,cAAgC,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,EAAb,cAA4C,CAAW,CAAC,EAG3C,EAAb,cAAyC,CAAW,CAAC,EAGxC,EAAb,cAAyC,CAAW,CAAC,EAGxC,EAAb,cAAgD,CAAW,CAAC,EAM5D,SAAgB,EAAK,EAAiB,EAAwB,
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all tempo errors. Use `instanceof TempoError` to catch any tempo-originated error. */\nexport class TempoError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a date/time input string or value cannot be parsed. */\nexport class TempoInvalidInputError extends TempoError {}\n\n/** Thrown when the provided timezone identifier is unknown or invalid. */\nexport class TempoInvalidTzError extends TempoError {}\n\n/** Thrown when an operation requires a timezone but none was supplied. */\nexport class TempoMissingTzError extends TempoError {}\n\n/** Thrown when an input type is not supported by the called operation. */\nexport class TempoUnsupportedInputError extends TempoError {}\n\n// ─── Error helpers ────────────────────────────────────────────────────────────\n\ntype TempoErrorCtor = new (message: string, opts?: ErrorOptions) => TempoError;\n\nexport function fail(message: string, Class: TempoErrorCtor = TempoInvalidInputError, opts?: ErrorOptions): never {\n throw new Class(message, opts);\n}\n"],"mappings":"AACA,IAAa,EAAb,cAAgC,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,EAAb,cAA4C,CAAW,CAAC,EAG3C,EAAb,cAAyC,CAAW,CAAC,EAGxC,EAAb,cAAyC,CAAW,CAAC,EAGxC,EAAb,cAAgD,CAAW,CAAC,EAM5D,SAAgB,EAAK,EAAiB,EAAwB,EAAwB,EAA4B,CAChH,MAAM,IAAI,EAAM,EAAS,CAAI,CAC/B"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare class TempoMissingTzError extends TempoError {
|
|
|
14
14
|
/** Thrown when an input type is not supported by the called operation. */
|
|
15
15
|
export declare class TempoUnsupportedInputError extends TempoError {
|
|
16
16
|
}
|
|
17
|
-
type TempoErrorCtor = new (message: string) => TempoError;
|
|
18
|
-
export declare function fail(message: string, Class?: TempoErrorCtor): never;
|
|
17
|
+
type TempoErrorCtor = new (message: string, opts?: ErrorOptions) => TempoError;
|
|
18
|
+
export declare function fail(message: string, Class?: TempoErrorCtor, opts?: ErrorOptions): never;
|
|
19
19
|
export {};
|
|
20
20
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,sEAAsE;AACtE,qBAAa,sBAAuB,SAAQ,UAAU;CAAG;AAEzD,0EAA0E;AAC1E,qBAAa,mBAAoB,SAAQ,UAAU;CAAG;AAEtD,0EAA0E;AAC1E,qBAAa,mBAAoB,SAAQ,UAAU;CAAG;AAEtD,0EAA0E;AAC1E,qBAAa,0BAA2B,SAAQ,UAAU;CAAG;AAI7D,KAAK,cAAc,GAAG,KAAK,OAAO,EAAE,MAAM,KAAK,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,sEAAsE;AACtE,qBAAa,sBAAuB,SAAQ,UAAU;CAAG;AAEzD,0EAA0E;AAC1E,qBAAa,mBAAoB,SAAQ,UAAU;CAAG;AAEtD,0EAA0E;AAC1E,qBAAa,mBAAoB,SAAQ,UAAU;CAAG;AAEtD,0EAA0E;AAC1E,qBAAa,0BAA2B,SAAQ,UAAU;CAAG;AAI7D,KAAK,cAAc,GAAG,KAAK,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,KAAK,UAAU,CAAC;AAE/E,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,cAAuC,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,KAAK,CAEhH"}
|
package/dist/errors.js
CHANGED
|
@@ -4,8 +4,8 @@ var e = class extends Error {
|
|
|
4
4
|
super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
|
|
5
5
|
}
|
|
6
6
|
}, t = class extends e {}, n = class extends e {}, r = class extends e {}, i = class extends e {};
|
|
7
|
-
function a(e, n = t) {
|
|
8
|
-
throw new n(e);
|
|
7
|
+
function a(e, n = t, r) {
|
|
8
|
+
throw new n(e, r);
|
|
9
9
|
}
|
|
10
10
|
//#endregion
|
|
11
11
|
export { e as TempoError, t as TempoInvalidInputError, n as TempoInvalidTzError, r as TempoMissingTzError, i as TempoUnsupportedInputError, a as fail };
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all tempo errors. Use `instanceof TempoError` to catch any tempo-originated error. */\nexport class TempoError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a date/time input string or value cannot be parsed. */\nexport class TempoInvalidInputError extends TempoError {}\n\n/** Thrown when the provided timezone identifier is unknown or invalid. */\nexport class TempoInvalidTzError extends TempoError {}\n\n/** Thrown when an operation requires a timezone but none was supplied. */\nexport class TempoMissingTzError extends TempoError {}\n\n/** Thrown when an input type is not supported by the called operation. */\nexport class TempoUnsupportedInputError extends TempoError {}\n\n// ─── Error helpers ────────────────────────────────────────────────────────────\n\ntype TempoErrorCtor = new (message: string) => TempoError;\n\nexport function fail(message: string, Class: TempoErrorCtor = TempoInvalidInputError): never {\n throw new Class(message);\n}\n"],"mappings":";AACA,IAAa,IAAb,cAAgC,MAAM;CACpC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;AACF,GAGa,IAAb,cAA4C,EAAW,CAAC,GAG3C,IAAb,cAAyC,EAAW,CAAC,GAGxC,IAAb,cAAyC,EAAW,CAAC,GAGxC,IAAb,cAAgD,EAAW,CAAC;AAM5D,SAAgB,EAAK,GAAiB,IAAwB,
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all tempo errors. Use `instanceof TempoError` to catch any tempo-originated error. */\nexport class TempoError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a date/time input string or value cannot be parsed. */\nexport class TempoInvalidInputError extends TempoError {}\n\n/** Thrown when the provided timezone identifier is unknown or invalid. */\nexport class TempoInvalidTzError extends TempoError {}\n\n/** Thrown when an operation requires a timezone but none was supplied. */\nexport class TempoMissingTzError extends TempoError {}\n\n/** Thrown when an input type is not supported by the called operation. */\nexport class TempoUnsupportedInputError extends TempoError {}\n\n// ─── Error helpers ────────────────────────────────────────────────────────────\n\ntype TempoErrorCtor = new (message: string, opts?: ErrorOptions) => TempoError;\n\nexport function fail(message: string, Class: TempoErrorCtor = TempoInvalidInputError, opts?: ErrorOptions): never {\n throw new Class(message, opts);\n}\n"],"mappings":";AACA,IAAa,IAAb,cAAgC,MAAM;CACpC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;AACF,GAGa,IAAb,cAA4C,EAAW,CAAC,GAG3C,IAAb,cAAyC,EAAW,CAAC,GAGxC,IAAb,cAAyC,EAAW,CAAC,GAGxC,IAAb,cAAgD,EAAW,CAAC;AAM5D,SAAgB,EAAK,GAAiB,IAAwB,GAAwB,GAA4B;CAChH,MAAM,IAAI,EAAM,GAAS,CAAI;AAC/B"}
|
package/dist/format.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");var i=128;function a(e,t,n){let r=e.get(t);if(r!==void 0)return r;if(e.size>=i){let t=e.keys().next().value;t!==void 0&&e.delete(t)}let a=n();return e.set(t,a),a}var o=new Map,s=new Map,c=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 u(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 d(e,t){let n=e.timeZone??t,r=e.locale;if(e.intl!==void 0)return a(o,`${String(r??``)}|intl|${n??``}|${u(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 a(o,`${String(r??``)}|${i}|${n??``}`,()=>new Intl.DateTimeFormat(r,{...l[i],timeZone:n}))}function f(e){return a(s,`${String(e.locale??``)}|${e.numeric??`auto`}|${e.style??`long`}`,()=>new Intl.RelativeTimeFormat(e.locale,{numeric:e.numeric??`auto`,style:e.style??`long`}))}function p(e){let t=Intl;return t.DurationFormat?a(c,`${String(e.locale??``)}|${e.style??``}`,()=>new t.DurationFormat(e.locale,{style:e.style})):null}var m=60,h=3600,g=86400,_=604800,v=2629800,y=31557600,b=[{scale:1,thresholdToPromote:m,unit:`second`},{scale:m,thresholdToPromote:h/m,unit:`minute`},{scale:h,thresholdToPromote:g/h,unit:`hour`},{scale:g,thresholdToPromote:_/g,unit:`day`},{scale:_,thresholdToPromote:v/_,unit:`week`},{scale:v,thresholdToPromote:12,unit:`month`},{scale:y,thresholdToPromote:1/0,unit:`year`}];function x(t){Number.isFinite(t)||e.fail(`formatRelative received a non-finite time difference.`);let n=Math.round(t);for(let{scale:e,thresholdToPromote:t,unit:r}of b){let i=Math.round(n/e);if(Math.abs(i)<t)return{unit:r,value:i}}return{unit:`year`,value:Math.round(n/y)}}var S=[`years`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`,`microseconds`,`nanoseconds`];function C(e){let t=[];for(let n of S){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 w(t,n,i,a){if(i.timeZone)return i.timeZone;let o=t instanceof r.Temporal.ZonedDateTime?t.timeZoneId:void 0,s=n instanceof r.Temporal.ZonedDateTime?n.timeZoneId:void 0;return o&&s&&o!==s&&e.fail(`${a} received ZonedDateTime inputs with different time zones. Pass options.timeZone explicitly.`),o??s}function T(e,t={}){let i=t.timeZone??(e instanceof r.Temporal.ZonedDateTime?e.timeZoneId:void 0);return d(t,i).format(new Date(n.toInstant(e,{timeZone:i}).epochMilliseconds))}function E(e,t,r={}){let i=w(e,t,r,`formatRange`);return d(r,i).formatRange(new Date(n.toInstant(e,{timeZone:i}).epochMilliseconds),new Date(n.toInstant(t,{timeZone:i}).epochMilliseconds))}function D(e,t,r={}){let i=w(e,t,r,`formatRangeParts`);return d(r,i).formatRangeToParts(new Date(n.toInstant(e,{timeZone:i}).epochMilliseconds),new Date(n.toInstant(t,{timeZone:i}).epochMilliseconds))}function O(e,t={}){return n.toInstant(e,t).toString()}function k(e,r={}){let i=t.inferTimeZone(e,r);return n.toZoned(e,{timeZone:i}).toString()}function A(e,t={}){let n=e instanceof r.Temporal.Instant?e:e.toInstant(),i=t.base?t.base instanceof r.Temporal.Instant?t.base:t.base.toInstant():r.Temporal.Now.instant(),{unit:a,value:o}=x((n.epochMilliseconds-i.epochMilliseconds)/1e3);return f(t).format(o,a)}function j(t){try{return r.Temporal.Duration.from(t)}catch{e.fail(`Invalid duration input: "${String(t)}". Expected an ISO 8601 duration string or Temporal.DurationLike
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./_tz.cjs"),n=require("./_convert.cjs");let r=require("@js-temporal/polyfill");var i=128;function a(e,t,n){let r=e.get(t);if(r!==void 0)return r;if(e.size>=i){let t=e.keys().next().value;t!==void 0&&e.delete(t)}let a=n();return e.set(t,a),a}var o=new Map,s=new Map,c=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 u(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 d(e,t){let n=e.timeZone??t,r=e.locale;if(e.intl!==void 0)return a(o,`${String(r??``)}|intl|${n??``}|${u(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 a(o,`${String(r??``)}|${i}|${n??``}`,()=>new Intl.DateTimeFormat(r,{...l[i],timeZone:n}))}function f(e){return a(s,`${String(e.locale??``)}|${e.numeric??`auto`}|${e.style??`long`}`,()=>new Intl.RelativeTimeFormat(e.locale,{numeric:e.numeric??`auto`,style:e.style??`long`}))}function p(e){let t=Intl;return t.DurationFormat?a(c,`${String(e.locale??``)}|${e.style??``}`,()=>new t.DurationFormat(e.locale,{style:e.style})):null}var m=60,h=3600,g=86400,_=604800,v=2629800,y=31557600,b=[{scale:1,thresholdToPromote:m,unit:`second`},{scale:m,thresholdToPromote:h/m,unit:`minute`},{scale:h,thresholdToPromote:g/h,unit:`hour`},{scale:g,thresholdToPromote:_/g,unit:`day`},{scale:_,thresholdToPromote:v/_,unit:`week`},{scale:v,thresholdToPromote:12,unit:`month`},{scale:y,thresholdToPromote:1/0,unit:`year`}];function x(t){Number.isFinite(t)||e.fail(`formatRelative received a non-finite time difference.`);let n=Math.round(t);for(let{scale:e,thresholdToPromote:t,unit:r}of b){let i=Math.round(n/e);if(Math.abs(i)<t)return{unit:r,value:i}}return{unit:`year`,value:Math.round(n/y)}}var S=[`years`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`,`microseconds`,`nanoseconds`];function C(e){let t=[];for(let n of S){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 w(t,n,i,a){if(i.timeZone)return i.timeZone;let o=t instanceof r.Temporal.ZonedDateTime?t.timeZoneId:void 0,s=n instanceof r.Temporal.ZonedDateTime?n.timeZoneId:void 0;return o&&s&&o!==s&&e.fail(`${a} received ZonedDateTime inputs with different time zones. Pass options.timeZone explicitly.`),o??s}function T(e,t={}){let i=t.timeZone??(e instanceof r.Temporal.ZonedDateTime?e.timeZoneId:void 0);return d(t,i).format(new Date(n.toInstant(e,{timeZone:i}).epochMilliseconds))}function E(e,t,r={}){let i=w(e,t,r,`formatRange`);return d(r,i).formatRange(new Date(n.toInstant(e,{timeZone:i}).epochMilliseconds),new Date(n.toInstant(t,{timeZone:i}).epochMilliseconds))}function D(e,t,r={}){let i=w(e,t,r,`formatRangeParts`);return d(r,i).formatRangeToParts(new Date(n.toInstant(e,{timeZone:i}).epochMilliseconds),new Date(n.toInstant(t,{timeZone:i}).epochMilliseconds))}function O(e,t={}){return n.toInstant(e,t).toString()}function k(e,r={}){let i=t.inferTimeZone(e,r);return n.toZoned(e,{timeZone:i}).toString()}function A(e,t={}){let n=e instanceof r.Temporal.Instant?e:e.toInstant(),i=t.base?t.base instanceof r.Temporal.Instant?t.base:t.base.toInstant():r.Temporal.Now.instant(),{unit:a,value:o}=x((n.epochMilliseconds-i.epochMilliseconds)/1e3);return f(t).format(o,a)}function j(t){try{return r.Temporal.Duration.from(t)}catch(n){e.fail(`Invalid duration input: "${String(t)}". Expected an ISO 8601 duration string or Temporal.DurationLike.`,e.TempoInvalidInputError,{cause:n})}}function M(e,t={}){let n=j(e),r=p(t);return r?r.format(n):C(n)}function N(e,t={}){let i=t.timeZone??(e instanceof r.Temporal.ZonedDateTime?e.timeZoneId:void 0);return d(t,i).formatToParts(new Date(n.toInstant(e,{timeZone:i}).epochMilliseconds))}function P(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`}`}exports.format=T,exports.formatDuration=M,exports.formatInstant=O,exports.formatParts=N,exports.formatRange=E,exports.formatRangeParts=D,exports.formatRelative=A,exports.formatZoned=k,exports.humanize=P,exports.parseDuration=j;
|
|
2
2
|
//# sourceMappingURL=format.cjs.map
|
package/dist/format.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.cjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { toInstant, toZoned } from './_convert';\nimport { inferTimeZone } from './_tz';\nimport { fail } from './errors';\nimport type {\n DurationFormatOptions,\n FormatOptions,\n FormatPattern,\n RelativeFormatOptions,\n RelativeTimeInput,\n TimeDiffResult,\n TimeInput,\n TimeZoneOptions,\n} from './types';\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 *\n * Pass `options.timeZone` when `input` is a `PlainDate` or `PlainDateTime`.\n * Inferred from `ZonedDateTime`; ignored for `Instant`.\n *\n * @throws {TempoMissingTzError} When `input` is a `PlainDate` or `PlainDateTime` and `options.timeZone` is omitted.\n * @throws {TempoInvalidTzError} When `options.timeZone` is not a valid IANA timezone or UTC offset.\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`, `PlainDateTime`, or `Instant`.\n * Inferred automatically from a `ZonedDateTime` input.\n *\n * @throws {TempoMissingTzError} When `input` is not a `ZonedDateTime` and `options.timeZone` is omitted.\n * @throws {TempoInvalidTzError} When `options.timeZone` is not a valid IANA timezone or UTC offset.\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 ? unit : `${unit}s`}`;\n}\n"],"mappings":"0HAyBA,IAAM,EAAsB,IAE5B,SAAS,EAAqB,EAAuB,EAAa,EAAqB,CACrF,IAAM,EAAS,EAAM,IAAI,CAAG,EAE5B,GAAI,IAAW,IAAA,GAAW,OAAO,EAEjC,GAAI,EAAM,MAAQ,EAAqB,CACrC,IAAM,EAAS,EAAM,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,MAE/B,IAAW,IAAA,IAAW,EAAM,OAAO,CAAM,CAC/C,CAEA,IAAM,EAAQ,EAAQ,EAItB,OAFA,EAAM,IAAI,EAAK,CAAK,EAEb,CACT,CAEA,IAAM,EAA4B,IAAI,IAChC,EAAgC,IAAI,IACpC,EAA2B,IAAI,IAI/B,EAAoE,CACxE,YAAa,CAAE,UAAW,OAAQ,EAClC,KAAM,CAAE,UAAW,OAAQ,UAAW,MAAO,EAC7C,OAAQ,CAAE,UAAW,SAAU,UAAW,OAAQ,EAClD,MAAO,CAAE,UAAW,QAAS,UAAW,OAAQ,EAChD,YAAa,CAAE,UAAW,OAAQ,CACpC,EAIA,SAAS,EAAqB,EAA6C,CACzE,OAAO,KAAK,UACV,OAAO,QAAQ,CAAO,CAAC,CACpB,QAAQ,EAAG,KAAW,IAAU,IAAA,EAAS,CAAC,CAC1C,MAAM,CAAC,GAAI,CAAC,KAAO,EAAE,cAAc,CAAC,CAAC,CAAC,CACtC,KAAK,CAAC,EAAK,KAAW,CAAC,EAAK,OAAO,CAAK,CAAC,CAAC,CAC/C,CACF,CAEA,SAAS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":["import { Temporal } from '@js-temporal/polyfill';\nimport { toInstant, toZoned } from './_convert';\nimport { inferTimeZone } from './_tz';\nimport { fail, TempoInvalidInputError } from './errors';\nimport type {\n DurationFormatOptions,\n FormatOptions,\n FormatPattern,\n RelativeFormatOptions,\n RelativeTimeInput,\n TimeDiffResult,\n TimeInput,\n TimeZoneOptions,\n} from './types';\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 *\n * Pass `options.timeZone` when `input` is a `PlainDate` or `PlainDateTime`.\n * Inferred from `ZonedDateTime`; ignored for `Instant`.\n *\n * @throws {TempoMissingTzError} When `input` is a `PlainDate` or `PlainDateTime` and `options.timeZone` is omitted.\n * @throws {TempoInvalidTzError} When `options.timeZone` is not a valid IANA timezone or UTC offset.\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`, `PlainDateTime`, or `Instant`.\n * Inferred automatically from a `ZonedDateTime` input.\n *\n * @throws {TempoMissingTzError} When `input` is not a `ZonedDateTime` and `options.timeZone` is omitted.\n * @throws {TempoInvalidTzError} When `options.timeZone` is not a valid IANA timezone or UTC offset.\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 (error) {\n fail(\n `Invalid duration input: \"${String(input)}\". Expected an ISO 8601 duration string or Temporal.DurationLike.`,\n TempoInvalidInputError,\n { cause: error },\n );\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 ? unit : `${unit}s`}`;\n}\n"],"mappings":"0HAyBA,IAAM,EAAsB,IAE5B,SAAS,EAAqB,EAAuB,EAAa,EAAqB,CACrF,IAAM,EAAS,EAAM,IAAI,CAAG,EAE5B,GAAI,IAAW,IAAA,GAAW,OAAO,EAEjC,GAAI,EAAM,MAAQ,EAAqB,CACrC,IAAM,EAAS,EAAM,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,MAE/B,IAAW,IAAA,IAAW,EAAM,OAAO,CAAM,CAC/C,CAEA,IAAM,EAAQ,EAAQ,EAItB,OAFA,EAAM,IAAI,EAAK,CAAK,EAEb,CACT,CAEA,IAAM,EAA4B,IAAI,IAChC,EAAgC,IAAI,IACpC,EAA2B,IAAI,IAI/B,EAAoE,CACxE,YAAa,CAAE,UAAW,OAAQ,EAClC,KAAM,CAAE,UAAW,OAAQ,UAAW,MAAO,EAC7C,OAAQ,CAAE,UAAW,SAAU,UAAW,OAAQ,EAClD,MAAO,CAAE,UAAW,QAAS,UAAW,OAAQ,EAChD,YAAa,CAAE,UAAW,OAAQ,CACpC,EAIA,SAAS,EAAqB,EAA6C,CACzE,OAAO,KAAK,UACV,OAAO,QAAQ,CAAO,CAAC,CACpB,QAAQ,EAAG,KAAW,IAAU,IAAA,EAAS,CAAC,CAC1C,MAAM,CAAC,GAAI,CAAC,KAAO,EAAE,cAAc,CAAC,CAAC,CAAC,CACtC,KAAK,CAAC,EAAK,KAAW,CAAC,EAAK,OAAO,CAAK,CAAC,CAAC,CAC/C,CACF,CAEA,SAAS,EAAc,EAAwB,EA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@@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIjD,OAAO,KAAK,EACV,qBAAqB,EACrB,aAAa,EAEb,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,SAAS,EACT,eAAe,EAChB,MAAM,SAAS,CAAC;AA0MjB;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAI5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAQjG;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,EAChB,GAAG,EAAE,SAAS,EACd,OAAO,GAAE,aAAkB,GAC1B,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,CAQvD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,GAAE,eAAoB,GAAG,MAAM,CAErF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,GAAE,eAAoB,GAAG,MAAM,CAInF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,iBAAiB,EAAE,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAWpG;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,YAAY,GAAG,QAAQ,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,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