@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.
Files changed (68) hide show
  1. package/README.md +18 -43
  2. package/dist/_convert.cjs +1 -1
  3. package/dist/_convert.cjs.map +1 -1
  4. package/dist/_convert.d.ts +9 -43
  5. package/dist/_convert.d.ts.map +1 -1
  6. package/dist/_convert.js +12 -10
  7. package/dist/_convert.js.map +1 -1
  8. package/dist/_floor.cjs +1 -1
  9. package/dist/_floor.cjs.map +1 -1
  10. package/dist/_floor.d.ts +3 -7
  11. package/dist/_floor.d.ts.map +1 -1
  12. package/dist/_floor.js +1 -4
  13. package/dist/_floor.js.map +1 -1
  14. package/dist/_tz.cjs +1 -1
  15. package/dist/_tz.cjs.map +1 -1
  16. package/dist/_tz.d.ts +4 -11
  17. package/dist/_tz.d.ts.map +1 -1
  18. package/dist/_tz.js +8 -16
  19. package/dist/_tz.js.map +1 -1
  20. package/dist/boundary.cjs +1 -1
  21. package/dist/boundary.cjs.map +1 -1
  22. package/dist/boundary.d.ts +0 -21
  23. package/dist/boundary.d.ts.map +1 -1
  24. package/dist/boundary.js +2 -2
  25. package/dist/boundary.js.map +1 -1
  26. package/dist/classify.cjs +1 -1
  27. package/dist/classify.cjs.map +1 -1
  28. package/dist/classify.d.ts +3 -45
  29. package/dist/classify.d.ts.map +1 -1
  30. package/dist/classify.js +33 -31
  31. package/dist/classify.js.map +1 -1
  32. package/dist/compare.cjs +1 -1
  33. package/dist/compare.cjs.map +1 -1
  34. package/dist/compare.d.ts +6 -70
  35. package/dist/compare.d.ts.map +1 -1
  36. package/dist/compare.js +31 -45
  37. package/dist/compare.js.map +1 -1
  38. package/dist/core.cjs +1 -1
  39. package/dist/core.cjs.map +1 -1
  40. package/dist/core.d.ts +21 -131
  41. package/dist/core.d.ts.map +1 -1
  42. package/dist/core.js +30 -73
  43. package/dist/core.js.map +1 -1
  44. package/dist/format.cjs +1 -1
  45. package/dist/format.cjs.map +1 -1
  46. package/dist/format.d.ts +17 -17
  47. package/dist/format.d.ts.map +1 -1
  48. package/dist/format.js +10 -10
  49. package/dist/format.js.map +1 -1
  50. package/dist/index.cjs +1 -1
  51. package/dist/index.d.ts +5 -5
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +9 -9
  54. package/dist/range.cjs +1 -1
  55. package/dist/range.cjs.map +1 -1
  56. package/dist/range.d.ts +3 -57
  57. package/dist/range.d.ts.map +1 -1
  58. package/dist/range.js +9 -20
  59. package/dist/range.js.map +1 -1
  60. package/dist/tempo.cjs +1 -1
  61. package/dist/tempo.cjs.map +1 -1
  62. package/dist/tempo.iife.js +1 -1
  63. package/dist/tempo.iife.js.map +1 -1
  64. package/dist/tempo.js +1 -1
  65. package/dist/tempo.js.map +1 -1
  66. package/dist/types.d.ts +34 -36
  67. package/dist/types.d.ts.map +1 -1
  68. package/package.json +1 -1
package/README.md CHANGED
@@ -1,63 +1,37 @@
1
1
  # @vielzeug/tempo
2
2
 
3
- > Temporal-powered parsing, timezone conversion, arithmetic (DST-safe), and Intl formatting for modern TypeScript.
3
+ Temporal utilities with explicit parsing and timezone rules.
4
4
 
5
- [![npm version](https://img.shields.io/npm/v/@vielzeug/tempo)](https://www.npmjs.com/package/@vielzeug/tempo) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
-
7
- <details>
8
- <summary>Quick Reference</summary>
9
-
10
- **Package:** `@vielzeug/tempo` &nbsp;·&nbsp; **Category:** Date-time
11
-
12
- **Key exports:** `now`, `parsePlainDateTime`, `parseInstant`, `parse`, `toInstant`, `inTz`, `shift`, `difference`, `format`, `formatRelative`, `isBefore`, `isAfter`, `isSame`, `startOf`, `endOf`, `expires`, `timeDiff`, `recurrence`
13
-
14
- **When to use:** Temporal-powered parsing, timezone conversion, arithmetic (DST-safe), and Intl formatting for modern TypeScript.
15
-
16
- **Related:** [@vielzeug/arsenal](https://vielzeug.dev/arsenal/)
17
-
18
- </details>
19
-
20
- `@vielzeug/tempo` is part of Vielzeug and ships as a zero-dependency TypeScript package with ESM+CJS output.
5
+ `@vielzeug/tempo` ships ESM and CJS output. It depends on `@js-temporal/polyfill` and re-exports `Temporal` so all consumers use one implementation and version.
21
6
 
22
7
  ## Installation
23
8
 
24
9
  ```sh
25
10
  pnpm add @vielzeug/tempo
26
- npm install @vielzeug/tempo
27
- yarn add @vielzeug/tempo
28
11
  ```
29
12
 
30
13
  ## Quick Start
31
14
 
32
- ```ts
33
- import { format, formatInstant, inTz, parsePlainDateTime, shift, toInstant } from '@vielzeug/tempo';
34
-
35
- // Parse a wall-clock string (no timezone attached)
36
- const localMeeting = parsePlainDateTime('2026-03-21T10:30:00');
15
+ Parse a wall-clock input, resolve it to an instant, then format its zoned display value.
37
16
 
38
- // Convert to an absolute instant using the user's timezone
39
- const meetingInstant = toInstant(localMeeting, { tz: 'America/New_York' });
40
-
41
- // Project to a zoned view and subtract 15 minutes (DST-safe)
42
- const meetingNY = inTz(meetingInstant, 'America/New_York');
43
- const reminder = shift(meetingNY, { minutes: -15 });
17
+ ```ts
18
+ import { format, inTimeZone, parse, shift, toInstant } from '@vielzeug/tempo';
44
19
 
45
- // Format for display
46
- console.log(format(reminder, { pattern: 'short', locale: 'en-US', tz: 'America/New_York' }));
20
+ const local = parse('2026-03-21T10:30:00', { as: 'plainDateTime' });
21
+ const meeting = toInstant(local, { timeZone: 'America/New_York' });
22
+ const reminder = shift(meeting, { minutes: -15 }, { timeZone: 'America/New_York' });
47
23
 
48
- // Format for APIs / logs (stable UTC instant string)
49
- console.log(formatInstant(reminder));
24
+ console.log(format(inTimeZone(reminder, 'America/New_York'), { locale: 'en-US', pattern: 'short' }));
50
25
  ```
51
26
 
52
- Since many function names (`now`, `shift`, `clamp`, `difference`, …) are common in application code, use a namespace import to avoid collisions while still getting full tree-shaking:
27
+ ## API Rules
53
28
 
54
- ```ts
55
- import * as tempo from '@vielzeug/tempo';
56
-
57
- tempo.now('UTC');
58
- tempo.difference(start, end, { largestUnit: 'day', tz: 'UTC' });
59
- tempo.format(meeting, { pattern: 'short', locale: 'en-US', tz: 'America/New_York' });
60
- ```
29
+ - `parse()` always requires `{ as }`; Tempo does not auto-detect strings.
30
+ - `timeZone` is required whenever plain values become instants or zoned values.
31
+ - `disambiguation` controls DST overlaps and gaps.
32
+ - `difference()`, `contains()`, `clamp()`, and `classifyExpiry()` take object inputs.
33
+ - `classifyExpiry()` accepts fixed elapsed-time thresholds only; months and years are rejected.
34
+ - `Temporal` remains exported for advanced Temporal operations and type identity.
61
35
 
62
36
  ## Documentation
63
37
 
@@ -65,7 +39,8 @@ tempo.format(meeting, { pattern: 'short', locale: 'en-US', tz: 'America/New_York
65
39
  - [Usage Guide](https://vielzeug.dev/tempo/usage)
66
40
  - [API Reference](https://vielzeug.dev/tempo/api)
67
41
  - [Examples](https://vielzeug.dev/tempo/examples)
42
+ - [Migration Guide](https://vielzeug.dev/tempo/migration)
68
43
 
69
44
  ## License
70
45
 
71
- MIT © [Helmuth Saatkamp](https://github.com/helmuthdu) — part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
46
+ MIT © Helmuth Saatkamp — part of Vielzeug.
package/dist/_convert.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./errors.cjs"),t=require("./_tz.cjs");let n=require("@js-temporal/polyfill");function r(r,i={}){if(r instanceof n.Temporal.Instant)return r;if(r instanceof n.Temporal.ZonedDateTime)return r.toInstant();if(r instanceof n.Temporal.PlainDateTime)return i.tz||e.fail(`This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.`,e.TempoMissingTzError),r.toZonedDateTime(t.validateTz(i.tz),{disambiguation:i.prefer}).toInstant();if(r instanceof n.Temporal.PlainDate)return i.tz||e.fail(`This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.`,e.TempoMissingTzError),r.toZonedDateTime({timeZone:t.validateTz(i.tz)}).toInstant();e.fail(`Unsupported time input type: ${String(r)}`,e.TempoUnsupportedInputError)}function i(r,i){let a=i,o=t.validateTz(a.tz);if(r instanceof n.Temporal.ZonedDateTime)return r.withTimeZone(o);if(r instanceof n.Temporal.PlainDateTime)return r.toZonedDateTime(o,{disambiguation:a.prefer});if(r instanceof n.Temporal.PlainDate)return r.toZonedDateTime({timeZone:o});if(r instanceof n.Temporal.Instant)return r.toZonedDateTimeISO(o);e.fail(`Unsupported time input type: ${String(r)}`,e.TempoUnsupportedInputError)}function a(e,t){return i(e,{tz:t})}exports.inTz=a,exports.toInstant=r,exports.toZoned=i;
1
+ const e=require("./errors.cjs"),t=require("./_tz.cjs");let n=require("@js-temporal/polyfill");function r(r,i={}){if(r instanceof n.Temporal.Instant)return r;if(r instanceof n.Temporal.ZonedDateTime)return r.toInstant();i.timeZone||e.fail(`This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.`,e.TempoMissingTzError);let a=t.validateTimeZone(i.timeZone);if(r instanceof n.Temporal.PlainDateTime)return r.toZonedDateTime(a,{disambiguation:i.disambiguation}).toInstant();if(r instanceof n.Temporal.PlainDate)return r.toZonedDateTime({timeZone:a}).toInstant();e.fail(`Unsupported time input type: ${String(r)}`,e.TempoUnsupportedInputError)}function i(r,i){let a=t.validateTimeZone(i.timeZone);if(r instanceof n.Temporal.ZonedDateTime)return r.withTimeZone(a);if(r instanceof n.Temporal.Instant)return r.toZonedDateTimeISO(a);if(r instanceof n.Temporal.PlainDateTime)return r.toZonedDateTime(a,{disambiguation:i.disambiguation});if(r instanceof n.Temporal.PlainDate)return r.toZonedDateTime({timeZone:a});e.fail(`Unsupported time input type: ${String(r)}`,e.TempoUnsupportedInputError)}function a(e,t){return i(e,{timeZone:t})}exports.inTimeZone=a,exports.toInstant=r,exports.toZoned=i;
2
2
  //# sourceMappingURL=_convert.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"_convert.cjs","names":[],"sources":["../src/_convert.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { DateTimeDisambiguation, TimeInput } from './types';\n\nimport { validateTz } from './_tz';\nimport { TempoMissingTzError, TempoUnsupportedInputError, fail } from './errors';\n\ntype WithPrefer = { prefer?: DateTimeDisambiguation };\ntype TimeOptionsWithTz = { tz: string };\n\n// ─── Direct resolution ────────────────────────────────────────────────────────\n\n/**\n * Converts any {@link TimeInput} to an absolute `Instant`.\n * Requires `options.tz` when input is a `PlainDate` or `PlainDateTime`.\n */\nexport function toInstant(input: TimeInput, options: WithPrefer & { tz?: string } = {}): Temporal.Instant {\n if (input instanceof Temporal.Instant) return input;\n\n if (input instanceof Temporal.ZonedDateTime) return input.toInstant();\n\n if (input instanceof Temporal.PlainDateTime) {\n if (!options.tz)\n fail('This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.', TempoMissingTzError);\n\n return input\n .toZonedDateTime(validateTz(options.tz), {\n disambiguation: options.prefer as 'compatible' | 'earlier' | 'later' | 'reject' | undefined,\n })\n .toInstant();\n }\n\n if (input instanceof Temporal.PlainDate) {\n if (!options.tz)\n fail('This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.', TempoMissingTzError);\n\n return input.toZonedDateTime({ timeZone: validateTz(options.tz) }).toInstant();\n }\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\n/**\n * Projects any {@link TimeInput} into `options.tz` as a `ZonedDateTime`.\n *\n * When `input` is already a `ZonedDateTime`, it is **re-projected** into `options.tz`\n * via `withTimeZone()` — the wall-clock time changes but the absolute instant is preserved.\n *\n * @example\n * ```ts\n * // Re-projection: same instant, different wall-clock\n * toZoned(parseZoned('2026-03-21T11:00:00+01:00[Europe/Berlin]'), { tz: 'UTC' })\n * // 2026-03-21T10:00:00+00:00[UTC] ← wall-clock changed from 11:00 → 10:00\n * ```\n */\nexport function toZoned(\n input: TimeInput,\n options: TimeOptionsWithTz | (WithPrefer & { tz: string }),\n): Temporal.ZonedDateTime {\n const opts = options as TimeOptionsWithTz & WithPrefer;\n const tz = validateTz(opts.tz);\n\n if (input instanceof Temporal.ZonedDateTime) return input.withTimeZone(tz);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(tz, {\n disambiguation: opts.prefer as 'compatible' | 'earlier' | 'later' | 'reject' | undefined,\n });\n }\n\n if (input instanceof Temporal.PlainDate) {\n return input.toZonedDateTime({ timeZone: tz });\n }\n\n if (input instanceof Temporal.Instant) return input.toZonedDateTimeISO(tz);\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\n/**\n * Projects any {@link TimeInput} into a specific timezone as a `ZonedDateTime`.\n * Unlike {@link toZoned}, this is the clean public API: explicit `tz` string parameter\n * rather than an options bag, signalling intent clearly.\n *\n * When `input` is already a `ZonedDateTime`, it is re-projected — same instant, new zone.\n *\n * @example\n * ```ts\n * inTz(parseInstant('2026-03-21T10:00:00Z'), 'Europe/Berlin')\n * // 2026-03-21T11:00:00+01:00[Europe/Berlin]\n * ```\n */\nexport function inTz(input: TimeInput, tz: string): Temporal.ZonedDateTime {\n return toZoned(input, { tz });\n}\n"],"mappings":"8FAgBA,SAAgB,EAAU,EAAkB,EAAwC,CAAC,EAAqB,CACxG,GAAI,aAAiB,EAAA,SAAS,QAAS,OAAO,EAE9C,GAAI,aAAiB,EAAA,SAAS,cAAe,OAAO,EAAM,UAAU,EAEpE,GAAI,aAAiB,EAAA,SAAS,cAI5B,OAHK,EAAQ,IACX,EAAA,KAAK,oFAAqF,EAAA,mBAAmB,EAExG,EACJ,gBAAgB,EAAA,WAAW,EAAQ,EAAE,EAAG,CACvC,eAAgB,EAAQ,MAC1B,CAAC,CAAC,CACD,UAAU,EAGf,GAAI,aAAiB,EAAA,SAAS,UAI5B,OAHK,EAAQ,IACX,EAAA,KAAK,oFAAqF,EAAA,mBAAmB,EAExG,EAAM,gBAAgB,CAAE,SAAU,EAAA,WAAW,EAAQ,EAAE,CAAE,CAAC,CAAC,CAAC,UAAU,EAG/E,EAAA,KAAK,gCAAgC,OAAO,CAAK,IAAK,EAAA,0BAA0B,CAClF,CAeA,SAAgB,EACd,EACA,EACwB,CACxB,IAAM,EAAO,EACP,EAAK,EAAA,WAAW,EAAK,EAAE,EAE7B,GAAI,aAAiB,EAAA,SAAS,cAAe,OAAO,EAAM,aAAa,CAAE,EAEzE,GAAI,aAAiB,EAAA,SAAS,cAC5B,OAAO,EAAM,gBAAgB,EAAI,CAC/B,eAAgB,EAAK,MACvB,CAAC,EAGH,GAAI,aAAiB,EAAA,SAAS,UAC5B,OAAO,EAAM,gBAAgB,CAAE,SAAU,CAAG,CAAC,EAG/C,GAAI,aAAiB,EAAA,SAAS,QAAS,OAAO,EAAM,mBAAmB,CAAE,EAEzE,EAAA,KAAK,gCAAgC,OAAO,CAAK,IAAK,EAAA,0BAA0B,CAClF,CAeA,SAAgB,EAAK,EAAkB,EAAoC,CACzE,OAAO,EAAQ,EAAO,CAAE,IAAG,CAAC,CAC9B"}
1
+ {"version":3,"file":"_convert.cjs","names":[],"sources":["../src/_convert.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { AbsoluteTime, DisambiguationOptions, TimeInput, TimeZoneOptions, WallTime } from './types';\n\nimport { validateTimeZone } from './_tz';\nimport { TempoMissingTzError, TempoUnsupportedInputError, fail } from './errors';\n\ntype ResolutionOptions = DisambiguationOptions & TimeZoneOptions;\ntype RequiredResolutionOptions = ResolutionOptions & { timeZone: string };\n\nexport function toInstant(input: AbsoluteTime): Temporal.Instant;\nexport function toInstant(input: WallTime, options: RequiredResolutionOptions): Temporal.Instant;\nexport function toInstant(input: TimeInput, options?: ResolutionOptions): Temporal.Instant;\nexport function toInstant(input: TimeInput, options: ResolutionOptions = {}): Temporal.Instant {\n if (input instanceof Temporal.Instant) return input;\n\n if (input instanceof Temporal.ZonedDateTime) return input.toInstant();\n\n if (!options.timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n const timeZone = validateTimeZone(options.timeZone);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(timeZone, { disambiguation: options.disambiguation }).toInstant();\n }\n\n if (input instanceof Temporal.PlainDate) return input.toZonedDateTime({ timeZone }).toInstant();\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\nexport function toZoned(input: TimeInput, options: RequiredResolutionOptions): Temporal.ZonedDateTime {\n const timeZone = validateTimeZone(options.timeZone);\n\n if (input instanceof Temporal.ZonedDateTime) return input.withTimeZone(timeZone);\n\n if (input instanceof Temporal.Instant) return input.toZonedDateTimeISO(timeZone);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(timeZone, { disambiguation: options.disambiguation });\n }\n\n if (input instanceof Temporal.PlainDate) return input.toZonedDateTime({ timeZone });\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\nexport function inTimeZone(input: TimeInput, timeZone: string): Temporal.ZonedDateTime {\n return toZoned(input, { timeZone });\n}\n"],"mappings":"8FAaA,SAAgB,EAAU,EAAkB,EAA6B,CAAC,EAAqB,CAC7F,GAAI,aAAiB,EAAA,SAAS,QAAS,OAAO,EAE9C,GAAI,aAAiB,EAAA,SAAS,cAAe,OAAO,EAAM,UAAU,EAE/D,EAAQ,UACX,EAAA,KACE,0FACA,EAAA,mBACF,EAGF,IAAM,EAAW,EAAA,iBAAiB,EAAQ,QAAQ,EAElD,GAAI,aAAiB,EAAA,SAAS,cAC5B,OAAO,EAAM,gBAAgB,EAAU,CAAE,eAAgB,EAAQ,cAAe,CAAC,CAAC,CAAC,UAAU,EAG/F,GAAI,aAAiB,EAAA,SAAS,UAAW,OAAO,EAAM,gBAAgB,CAAE,UAAS,CAAC,CAAC,CAAC,UAAU,EAE9F,EAAA,KAAK,gCAAgC,OAAO,CAAK,IAAK,EAAA,0BAA0B,CAClF,CAEA,SAAgB,EAAQ,EAAkB,EAA4D,CACpG,IAAM,EAAW,EAAA,iBAAiB,EAAQ,QAAQ,EAElD,GAAI,aAAiB,EAAA,SAAS,cAAe,OAAO,EAAM,aAAa,CAAQ,EAE/E,GAAI,aAAiB,EAAA,SAAS,QAAS,OAAO,EAAM,mBAAmB,CAAQ,EAE/E,GAAI,aAAiB,EAAA,SAAS,cAC5B,OAAO,EAAM,gBAAgB,EAAU,CAAE,eAAgB,EAAQ,cAAe,CAAC,EAGnF,GAAI,aAAiB,EAAA,SAAS,UAAW,OAAO,EAAM,gBAAgB,CAAE,UAAS,CAAC,EAElF,EAAA,KAAK,gCAAgC,OAAO,CAAK,IAAK,EAAA,0BAA0B,CAClF,CAEA,SAAgB,EAAW,EAAkB,EAA0C,CACrF,OAAO,EAAQ,EAAO,CAAE,UAAS,CAAC,CACpC"}
@@ -1,47 +1,13 @@
1
1
  import { Temporal } from '@js-temporal/polyfill';
2
- import type { DateTimeDisambiguation, TimeInput } from './types';
3
- type WithPrefer = {
4
- prefer?: DateTimeDisambiguation;
2
+ import type { AbsoluteTime, DisambiguationOptions, TimeInput, TimeZoneOptions, WallTime } from './types';
3
+ type ResolutionOptions = DisambiguationOptions & TimeZoneOptions;
4
+ type RequiredResolutionOptions = ResolutionOptions & {
5
+ timeZone: string;
5
6
  };
6
- type TimeOptionsWithTz = {
7
- tz: string;
8
- };
9
- /**
10
- * Converts any {@link TimeInput} to an absolute `Instant`.
11
- * Requires `options.tz` when input is a `PlainDate` or `PlainDateTime`.
12
- */
13
- export declare function toInstant(input: TimeInput, options?: WithPrefer & {
14
- tz?: string;
15
- }): Temporal.Instant;
16
- /**
17
- * Projects any {@link TimeInput} into `options.tz` as a `ZonedDateTime`.
18
- *
19
- * When `input` is already a `ZonedDateTime`, it is **re-projected** into `options.tz`
20
- * via `withTimeZone()` — the wall-clock time changes but the absolute instant is preserved.
21
- *
22
- * @example
23
- * ```ts
24
- * // Re-projection: same instant, different wall-clock
25
- * toZoned(parseZoned('2026-03-21T11:00:00+01:00[Europe/Berlin]'), { tz: 'UTC' })
26
- * // 2026-03-21T10:00:00+00:00[UTC] ← wall-clock changed from 11:00 → 10:00
27
- * ```
28
- */
29
- export declare function toZoned(input: TimeInput, options: TimeOptionsWithTz | (WithPrefer & {
30
- tz: string;
31
- })): Temporal.ZonedDateTime;
32
- /**
33
- * Projects any {@link TimeInput} into a specific timezone as a `ZonedDateTime`.
34
- * Unlike {@link toZoned}, this is the clean public API: explicit `tz` string parameter
35
- * rather than an options bag, signalling intent clearly.
36
- *
37
- * When `input` is already a `ZonedDateTime`, it is re-projected — same instant, new zone.
38
- *
39
- * @example
40
- * ```ts
41
- * inTz(parseInstant('2026-03-21T10:00:00Z'), 'Europe/Berlin')
42
- * // 2026-03-21T11:00:00+01:00[Europe/Berlin]
43
- * ```
44
- */
45
- export declare function inTz(input: TimeInput, tz: string): Temporal.ZonedDateTime;
7
+ export declare function toInstant(input: AbsoluteTime): Temporal.Instant;
8
+ export declare function toInstant(input: WallTime, options: RequiredResolutionOptions): Temporal.Instant;
9
+ export declare function toInstant(input: TimeInput, options?: ResolutionOptions): Temporal.Instant;
10
+ export declare function toZoned(input: TimeInput, options: RequiredResolutionOptions): Temporal.ZonedDateTime;
11
+ export declare function inTimeZone(input: TimeInput, timeZone: string): Temporal.ZonedDateTime;
46
12
  export {};
47
13
  //# sourceMappingURL=_convert.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_convert.d.ts","sourceRoot":"","sources":["../src/_convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKjE,KAAK,UAAU,GAAG;IAAE,MAAM,CAAC,EAAE,sBAAsB,CAAA;CAAE,CAAC;AACtD,KAAK,iBAAiB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAIxC;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,GAAE,UAAU,GAAG;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,QAAQ,CAAC,OAAO,CAwBxG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,iBAAiB,GAAG,CAAC,UAAU,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,GACzD,QAAQ,CAAC,aAAa,CAmBxB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,GAAG,QAAQ,CAAC,aAAa,CAEzE"}
1
+ {"version":3,"file":"_convert.d.ts","sourceRoot":"","sources":["../src/_convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKzG,KAAK,iBAAiB,GAAG,qBAAqB,GAAG,eAAe,CAAC;AACjE,KAAK,yBAAyB,GAAG,iBAAiB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E,wBAAgB,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC;AACjE,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,yBAAyB,GAAG,QAAQ,CAAC,OAAO,CAAC;AACjG,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,QAAQ,CAAC,OAAO,CAAC;AAwB3F,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,yBAAyB,GAAG,QAAQ,CAAC,aAAa,CAcpG;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC,aAAa,CAErF"}
package/dist/_convert.js CHANGED
@@ -1,26 +1,28 @@
1
1
  import { TempoMissingTzError as e, TempoUnsupportedInputError as t, fail as n } from "./errors.js";
2
- import { validateTz as r } from "./_tz.js";
2
+ import { validateTimeZone as r } from "./_tz.js";
3
3
  import { Temporal as i } from "@js-temporal/polyfill";
4
4
  //#region src/_convert.ts
5
5
  function a(a, o = {}) {
6
6
  if (a instanceof i.Instant) return a;
7
7
  if (a instanceof i.ZonedDateTime) return a.toInstant();
8
- if (a instanceof i.PlainDateTime) return o.tz || n("This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.", e), a.toZonedDateTime(r(o.tz), { disambiguation: o.prefer }).toInstant();
9
- if (a instanceof i.PlainDate) return o.tz || n("This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.", e), a.toZonedDateTime({ timeZone: r(o.tz) }).toInstant();
8
+ o.timeZone || n("This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.", e);
9
+ let s = r(o.timeZone);
10
+ if (a instanceof i.PlainDateTime) return a.toZonedDateTime(s, { disambiguation: o.disambiguation }).toInstant();
11
+ if (a instanceof i.PlainDate) return a.toZonedDateTime({ timeZone: s }).toInstant();
10
12
  n(`Unsupported time input type: ${String(a)}`, t);
11
13
  }
12
14
  function o(e, a) {
13
- let o = a, s = r(o.tz);
14
- if (e instanceof i.ZonedDateTime) return e.withTimeZone(s);
15
- if (e instanceof i.PlainDateTime) return e.toZonedDateTime(s, { disambiguation: o.prefer });
16
- if (e instanceof i.PlainDate) return e.toZonedDateTime({ timeZone: s });
17
- if (e instanceof i.Instant) return e.toZonedDateTimeISO(s);
15
+ let o = r(a.timeZone);
16
+ if (e instanceof i.ZonedDateTime) return e.withTimeZone(o);
17
+ if (e instanceof i.Instant) return e.toZonedDateTimeISO(o);
18
+ if (e instanceof i.PlainDateTime) return e.toZonedDateTime(o, { disambiguation: a.disambiguation });
19
+ if (e instanceof i.PlainDate) return e.toZonedDateTime({ timeZone: o });
18
20
  n(`Unsupported time input type: ${String(e)}`, t);
19
21
  }
20
22
  function s(e, t) {
21
- return o(e, { tz: t });
23
+ return o(e, { timeZone: t });
22
24
  }
23
25
  //#endregion
24
- export { s as inTz, a as toInstant, o as toZoned };
26
+ export { s as inTimeZone, a as toInstant, o as toZoned };
25
27
 
26
28
  //# sourceMappingURL=_convert.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_convert.js","names":[],"sources":["../src/_convert.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { DateTimeDisambiguation, TimeInput } from './types';\n\nimport { validateTz } from './_tz';\nimport { TempoMissingTzError, TempoUnsupportedInputError, fail } from './errors';\n\ntype WithPrefer = { prefer?: DateTimeDisambiguation };\ntype TimeOptionsWithTz = { tz: string };\n\n// ─── Direct resolution ────────────────────────────────────────────────────────\n\n/**\n * Converts any {@link TimeInput} to an absolute `Instant`.\n * Requires `options.tz` when input is a `PlainDate` or `PlainDateTime`.\n */\nexport function toInstant(input: TimeInput, options: WithPrefer & { tz?: string } = {}): Temporal.Instant {\n if (input instanceof Temporal.Instant) return input;\n\n if (input instanceof Temporal.ZonedDateTime) return input.toInstant();\n\n if (input instanceof Temporal.PlainDateTime) {\n if (!options.tz)\n fail('This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.', TempoMissingTzError);\n\n return input\n .toZonedDateTime(validateTz(options.tz), {\n disambiguation: options.prefer as 'compatible' | 'earlier' | 'later' | 'reject' | undefined,\n })\n .toInstant();\n }\n\n if (input instanceof Temporal.PlainDate) {\n if (!options.tz)\n fail('This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.', TempoMissingTzError);\n\n return input.toZonedDateTime({ timeZone: validateTz(options.tz) }).toInstant();\n }\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\n/**\n * Projects any {@link TimeInput} into `options.tz` as a `ZonedDateTime`.\n *\n * When `input` is already a `ZonedDateTime`, it is **re-projected** into `options.tz`\n * via `withTimeZone()` — the wall-clock time changes but the absolute instant is preserved.\n *\n * @example\n * ```ts\n * // Re-projection: same instant, different wall-clock\n * toZoned(parseZoned('2026-03-21T11:00:00+01:00[Europe/Berlin]'), { tz: 'UTC' })\n * // 2026-03-21T10:00:00+00:00[UTC] ← wall-clock changed from 11:00 → 10:00\n * ```\n */\nexport function toZoned(\n input: TimeInput,\n options: TimeOptionsWithTz | (WithPrefer & { tz: string }),\n): Temporal.ZonedDateTime {\n const opts = options as TimeOptionsWithTz & WithPrefer;\n const tz = validateTz(opts.tz);\n\n if (input instanceof Temporal.ZonedDateTime) return input.withTimeZone(tz);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(tz, {\n disambiguation: opts.prefer as 'compatible' | 'earlier' | 'later' | 'reject' | undefined,\n });\n }\n\n if (input instanceof Temporal.PlainDate) {\n return input.toZonedDateTime({ timeZone: tz });\n }\n\n if (input instanceof Temporal.Instant) return input.toZonedDateTimeISO(tz);\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\n/**\n * Projects any {@link TimeInput} into a specific timezone as a `ZonedDateTime`.\n * Unlike {@link toZoned}, this is the clean public API: explicit `tz` string parameter\n * rather than an options bag, signalling intent clearly.\n *\n * When `input` is already a `ZonedDateTime`, it is re-projected — same instant, new zone.\n *\n * @example\n * ```ts\n * inTz(parseInstant('2026-03-21T10:00:00Z'), 'Europe/Berlin')\n * // 2026-03-21T11:00:00+01:00[Europe/Berlin]\n * ```\n */\nexport function inTz(input: TimeInput, tz: string): Temporal.ZonedDateTime {\n return toZoned(input, { tz });\n}\n"],"mappings":";;;;AAgBA,SAAgB,EAAU,GAAkB,IAAwC,CAAC,GAAqB;CACxG,IAAI,aAAiB,EAAS,SAAS,OAAO;CAE9C,IAAI,aAAiB,EAAS,eAAe,OAAO,EAAM,UAAU;CAEpE,IAAI,aAAiB,EAAS,eAI5B,OAHK,EAAQ,MACX,EAAK,qFAAqF,CAAmB,GAExG,EACJ,gBAAgB,EAAW,EAAQ,EAAE,GAAG,EACvC,gBAAgB,EAAQ,OAC1B,CAAC,CAAC,CACD,UAAU;CAGf,IAAI,aAAiB,EAAS,WAI5B,OAHK,EAAQ,MACX,EAAK,qFAAqF,CAAmB,GAExG,EAAM,gBAAgB,EAAE,UAAU,EAAW,EAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU;CAG/E,EAAK,gCAAgC,OAAO,CAAK,KAAK,CAA0B;AAClF;AAeA,SAAgB,EACd,GACA,GACwB;CACxB,IAAM,IAAO,GACP,IAAK,EAAW,EAAK,EAAE;CAE7B,IAAI,aAAiB,EAAS,eAAe,OAAO,EAAM,aAAa,CAAE;CAEzE,IAAI,aAAiB,EAAS,eAC5B,OAAO,EAAM,gBAAgB,GAAI,EAC/B,gBAAgB,EAAK,OACvB,CAAC;CAGH,IAAI,aAAiB,EAAS,WAC5B,OAAO,EAAM,gBAAgB,EAAE,UAAU,EAAG,CAAC;CAG/C,IAAI,aAAiB,EAAS,SAAS,OAAO,EAAM,mBAAmB,CAAE;CAEzE,EAAK,gCAAgC,OAAO,CAAK,KAAK,CAA0B;AAClF;AAeA,SAAgB,EAAK,GAAkB,GAAoC;CACzE,OAAO,EAAQ,GAAO,EAAE,MAAG,CAAC;AAC9B"}
1
+ {"version":3,"file":"_convert.js","names":[],"sources":["../src/_convert.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { AbsoluteTime, DisambiguationOptions, TimeInput, TimeZoneOptions, WallTime } from './types';\n\nimport { validateTimeZone } from './_tz';\nimport { TempoMissingTzError, TempoUnsupportedInputError, fail } from './errors';\n\ntype ResolutionOptions = DisambiguationOptions & TimeZoneOptions;\ntype RequiredResolutionOptions = ResolutionOptions & { timeZone: string };\n\nexport function toInstant(input: AbsoluteTime): Temporal.Instant;\nexport function toInstant(input: WallTime, options: RequiredResolutionOptions): Temporal.Instant;\nexport function toInstant(input: TimeInput, options?: ResolutionOptions): Temporal.Instant;\nexport function toInstant(input: TimeInput, options: ResolutionOptions = {}): Temporal.Instant {\n if (input instanceof Temporal.Instant) return input;\n\n if (input instanceof Temporal.ZonedDateTime) return input.toInstant();\n\n if (!options.timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n const timeZone = validateTimeZone(options.timeZone);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(timeZone, { disambiguation: options.disambiguation }).toInstant();\n }\n\n if (input instanceof Temporal.PlainDate) return input.toZonedDateTime({ timeZone }).toInstant();\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\nexport function toZoned(input: TimeInput, options: RequiredResolutionOptions): Temporal.ZonedDateTime {\n const timeZone = validateTimeZone(options.timeZone);\n\n if (input instanceof Temporal.ZonedDateTime) return input.withTimeZone(timeZone);\n\n if (input instanceof Temporal.Instant) return input.toZonedDateTimeISO(timeZone);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(timeZone, { disambiguation: options.disambiguation });\n }\n\n if (input instanceof Temporal.PlainDate) return input.toZonedDateTime({ timeZone });\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\nexport function inTimeZone(input: TimeInput, timeZone: string): Temporal.ZonedDateTime {\n return toZoned(input, { timeZone });\n}\n"],"mappings":";;;;AAaA,SAAgB,EAAU,GAAkB,IAA6B,CAAC,GAAqB;CAC7F,IAAI,aAAiB,EAAS,SAAS,OAAO;CAE9C,IAAI,aAAiB,EAAS,eAAe,OAAO,EAAM,UAAU;CAEpE,AAAK,EAAQ,YACX,EACE,2FACA,CACF;CAGF,IAAM,IAAW,EAAiB,EAAQ,QAAQ;CAElD,IAAI,aAAiB,EAAS,eAC5B,OAAO,EAAM,gBAAgB,GAAU,EAAE,gBAAgB,EAAQ,eAAe,CAAC,CAAC,CAAC,UAAU;CAG/F,IAAI,aAAiB,EAAS,WAAW,OAAO,EAAM,gBAAgB,EAAE,YAAS,CAAC,CAAC,CAAC,UAAU;CAE9F,EAAK,gCAAgC,OAAO,CAAK,KAAK,CAA0B;AAClF;AAEA,SAAgB,EAAQ,GAAkB,GAA4D;CACpG,IAAM,IAAW,EAAiB,EAAQ,QAAQ;CAElD,IAAI,aAAiB,EAAS,eAAe,OAAO,EAAM,aAAa,CAAQ;CAE/E,IAAI,aAAiB,EAAS,SAAS,OAAO,EAAM,mBAAmB,CAAQ;CAE/E,IAAI,aAAiB,EAAS,eAC5B,OAAO,EAAM,gBAAgB,GAAU,EAAE,gBAAgB,EAAQ,eAAe,CAAC;CAGnF,IAAI,aAAiB,EAAS,WAAW,OAAO,EAAM,gBAAgB,EAAE,YAAS,CAAC;CAElF,EAAK,gCAAgC,OAAO,CAAK,KAAK,CAA0B;AAClF;AAEA,SAAgB,EAAW,GAAkB,GAA0C;CACrF,OAAO,EAAQ,GAAO,EAAE,YAAS,CAAC;AACpC"}
package/dist/_floor.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./_convert.cjs");require("@js-temporal/polyfill");var t={hour:0,microsecond:0,millisecond:0,minute:0,nanosecond:0,second:0},n={day:t,hour:{microsecond:0,millisecond:0,minute:0,nanosecond:0,second:0},minute:{microsecond:0,millisecond:0,nanosecond:0,second:0},month:{...t,day:1},year:{...t,day:1,month:1}};function r(r,i,a){let o=e.toZoned(r,{prefer:a.prefer,tz:a.tz});if(i===`week`){let e=(o.dayOfWeek-(a.weekStartsOn??1)+7)%7;return o.subtract({days:e}).with(t).toInstant()}return o.with(n[i]).toInstant()}exports.floorToUnit=r;
1
+ const e=require("./_convert.cjs");require("@js-temporal/polyfill");var t={hour:0,microsecond:0,millisecond:0,minute:0,nanosecond:0,second:0},n={day:t,hour:{microsecond:0,millisecond:0,minute:0,nanosecond:0,second:0},minute:{microsecond:0,millisecond:0,nanosecond:0,second:0},month:{...t,day:1},year:{...t,day:1,month:1}};function r(r,i,a){let o=e.toZoned(r,a);if(i===`week`){let e=(o.dayOfWeek-(a.weekStartsOn??1)+7)%7;return o.subtract({days:e}).with(t).toInstant()}return o.with(n[i]).toInstant()}exports.floorToUnit=r;
2
2
  //# sourceMappingURL=_floor.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"_floor.cjs","names":[],"sources":["../src/_floor.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { BoundaryUnit, DateTimeDisambiguation, TimeInput } from './types';\n\nimport { toZoned } from './_convert';\n\n// ─── Floor-to-boundary-unit helper ───────────────────────────────────────────\n\nconst TIME_ZERO: Temporal.ZonedDateTimeLike = {\n hour: 0,\n microsecond: 0,\n millisecond: 0,\n minute: 0,\n nanosecond: 0,\n second: 0,\n};\n\nconst BOUNDARY_CLEAR: Record<Exclude<BoundaryUnit, 'week'>, Temporal.ZonedDateTimeLike> = {\n day: TIME_ZERO,\n hour: { microsecond: 0, millisecond: 0, minute: 0, nanosecond: 0, second: 0 },\n minute: { microsecond: 0, millisecond: 0, nanosecond: 0, second: 0 },\n month: { ...TIME_ZERO, day: 1 },\n year: { ...TIME_ZERO, day: 1, month: 1 },\n};\n\n/**\n * Floors `input` to the start of `unit` in `tz`, returning an `Instant`.\n * Used internally by both `boundary.ts` and `compare.ts` without either depending on the other.\n */\nexport function floorToUnit(\n input: TimeInput,\n unit: BoundaryUnit,\n options: { prefer?: DateTimeDisambiguation; tz: string; weekStartsOn?: number },\n): Temporal.Instant {\n const zoned = toZoned(input, { prefer: options.prefer, tz: options.tz });\n\n if (unit === 'week') {\n const daysToSubtract = (zoned.dayOfWeek - (options.weekStartsOn ?? 1) + 7) % 7;\n\n return zoned.subtract({ days: daysToSubtract }).with(TIME_ZERO).toInstant();\n }\n\n return zoned.with(BOUNDARY_CLEAR[unit]).toInstant();\n}\n"],"mappings":"mEAQA,IAAM,EAAwC,CAC5C,KAAM,EACN,YAAa,EACb,YAAa,EACb,OAAQ,EACR,WAAY,EACZ,OAAQ,CACV,EAEM,EAAoF,CACxF,IAAK,EACL,KAAM,CAAE,YAAa,EAAG,YAAa,EAAG,OAAQ,EAAG,WAAY,EAAG,OAAQ,CAAE,EAC5E,OAAQ,CAAE,YAAa,EAAG,YAAa,EAAG,WAAY,EAAG,OAAQ,CAAE,EACnE,MAAO,CAAE,GAAG,EAAW,IAAK,CAAE,EAC9B,KAAM,CAAE,GAAG,EAAW,IAAK,EAAG,MAAO,CAAE,CACzC,EAMA,SAAgB,EACd,EACA,EACA,EACkB,CAClB,IAAM,EAAQ,EAAA,QAAQ,EAAO,CAAE,OAAQ,EAAQ,OAAQ,GAAI,EAAQ,EAAG,CAAC,EAEvE,GAAI,IAAS,OAAQ,CACnB,IAAM,GAAkB,EAAM,WAAa,EAAQ,cAAgB,GAAK,GAAK,EAE7E,OAAO,EAAM,SAAS,CAAE,KAAM,CAAe,CAAC,CAAC,CAAC,KAAK,CAAS,CAAC,CAAC,UAAU,CAC5E,CAEA,OAAO,EAAM,KAAK,EAAe,EAAK,CAAC,CAAC,UAAU,CACpD"}
1
+ {"version":3,"file":"_floor.cjs","names":[],"sources":["../src/_floor.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { BoundaryUnit, Disambiguation, TimeInput } from './types';\n\nimport { toZoned } from './_convert';\n\nconst TIME_ZERO: Temporal.ZonedDateTimeLike = {\n hour: 0,\n microsecond: 0,\n millisecond: 0,\n minute: 0,\n nanosecond: 0,\n second: 0,\n};\n\nconst BOUNDARY_CLEAR: Record<Exclude<BoundaryUnit, 'week'>, Temporal.ZonedDateTimeLike> = {\n day: TIME_ZERO,\n hour: { microsecond: 0, millisecond: 0, minute: 0, nanosecond: 0, second: 0 },\n minute: { microsecond: 0, millisecond: 0, nanosecond: 0, second: 0 },\n month: { ...TIME_ZERO, day: 1 },\n year: { ...TIME_ZERO, day: 1, month: 1 },\n};\n\nexport function floorToUnit(\n input: TimeInput,\n unit: BoundaryUnit,\n options: { disambiguation?: Disambiguation; timeZone: string; weekStartsOn?: number },\n): Temporal.Instant {\n const zoned = toZoned(input, options);\n\n if (unit === 'week') {\n const daysToSubtract = (zoned.dayOfWeek - (options.weekStartsOn ?? 1) + 7) % 7;\n\n return zoned.subtract({ days: daysToSubtract }).with(TIME_ZERO).toInstant();\n }\n\n return zoned.with(BOUNDARY_CLEAR[unit]).toInstant();\n}\n"],"mappings":"mEAMA,IAAM,EAAwC,CAC5C,KAAM,EACN,YAAa,EACb,YAAa,EACb,OAAQ,EACR,WAAY,EACZ,OAAQ,CACV,EAEM,EAAoF,CACxF,IAAK,EACL,KAAM,CAAE,YAAa,EAAG,YAAa,EAAG,OAAQ,EAAG,WAAY,EAAG,OAAQ,CAAE,EAC5E,OAAQ,CAAE,YAAa,EAAG,YAAa,EAAG,WAAY,EAAG,OAAQ,CAAE,EACnE,MAAO,CAAE,GAAG,EAAW,IAAK,CAAE,EAC9B,KAAM,CAAE,GAAG,EAAW,IAAK,EAAG,MAAO,CAAE,CACzC,EAEA,SAAgB,EACd,EACA,EACA,EACkB,CAClB,IAAM,EAAQ,EAAA,QAAQ,EAAO,CAAO,EAEpC,GAAI,IAAS,OAAQ,CACnB,IAAM,GAAkB,EAAM,WAAa,EAAQ,cAAgB,GAAK,GAAK,EAE7E,OAAO,EAAM,SAAS,CAAE,KAAM,CAAe,CAAC,CAAC,CAAC,KAAK,CAAS,CAAC,CAAC,UAAU,CAC5E,CAEA,OAAO,EAAM,KAAK,EAAe,EAAK,CAAC,CAAC,UAAU,CACpD"}
package/dist/_floor.d.ts CHANGED
@@ -1,12 +1,8 @@
1
1
  import { Temporal } from '@js-temporal/polyfill';
2
- import type { BoundaryUnit, DateTimeDisambiguation, TimeInput } from './types';
3
- /**
4
- * Floors `input` to the start of `unit` in `tz`, returning an `Instant`.
5
- * Used internally by both `boundary.ts` and `compare.ts` without either depending on the other.
6
- */
2
+ import type { BoundaryUnit, Disambiguation, TimeInput } from './types';
7
3
  export declare function floorToUnit(input: TimeInput, unit: BoundaryUnit, options: {
8
- prefer?: DateTimeDisambiguation;
9
- tz: string;
4
+ disambiguation?: Disambiguation;
5
+ timeZone: string;
10
6
  weekStartsOn?: number;
11
7
  }): Temporal.Instant;
12
8
  //# sourceMappingURL=_floor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_floor.d.ts","sourceRoot":"","sources":["../src/_floor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAuB/E;;;GAGG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,sBAAsB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9E,QAAQ,CAAC,OAAO,CAUlB"}
1
+ {"version":3,"file":"_floor.d.ts","sourceRoot":"","sources":["../src/_floor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAqBvE,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE;IAAE,cAAc,CAAC,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GACpF,QAAQ,CAAC,OAAO,CAUlB"}
package/dist/_floor.js CHANGED
@@ -34,10 +34,7 @@ var t = {
34
34
  }
35
35
  };
36
36
  function r(r, i, a) {
37
- let o = e(r, {
38
- prefer: a.prefer,
39
- tz: a.tz
40
- });
37
+ let o = e(r, a);
41
38
  if (i === "week") {
42
39
  let e = (o.dayOfWeek - (a.weekStartsOn ?? 1) + 7) % 7;
43
40
  return o.subtract({ days: e }).with(t).toInstant();
@@ -1 +1 @@
1
- {"version":3,"file":"_floor.js","names":[],"sources":["../src/_floor.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { BoundaryUnit, DateTimeDisambiguation, TimeInput } from './types';\n\nimport { toZoned } from './_convert';\n\n// ─── Floor-to-boundary-unit helper ───────────────────────────────────────────\n\nconst TIME_ZERO: Temporal.ZonedDateTimeLike = {\n hour: 0,\n microsecond: 0,\n millisecond: 0,\n minute: 0,\n nanosecond: 0,\n second: 0,\n};\n\nconst BOUNDARY_CLEAR: Record<Exclude<BoundaryUnit, 'week'>, Temporal.ZonedDateTimeLike> = {\n day: TIME_ZERO,\n hour: { microsecond: 0, millisecond: 0, minute: 0, nanosecond: 0, second: 0 },\n minute: { microsecond: 0, millisecond: 0, nanosecond: 0, second: 0 },\n month: { ...TIME_ZERO, day: 1 },\n year: { ...TIME_ZERO, day: 1, month: 1 },\n};\n\n/**\n * Floors `input` to the start of `unit` in `tz`, returning an `Instant`.\n * Used internally by both `boundary.ts` and `compare.ts` without either depending on the other.\n */\nexport function floorToUnit(\n input: TimeInput,\n unit: BoundaryUnit,\n options: { prefer?: DateTimeDisambiguation; tz: string; weekStartsOn?: number },\n): Temporal.Instant {\n const zoned = toZoned(input, { prefer: options.prefer, tz: options.tz });\n\n if (unit === 'week') {\n const daysToSubtract = (zoned.dayOfWeek - (options.weekStartsOn ?? 1) + 7) % 7;\n\n return zoned.subtract({ days: daysToSubtract }).with(TIME_ZERO).toInstant();\n }\n\n return zoned.with(BOUNDARY_CLEAR[unit]).toInstant();\n}\n"],"mappings":";;;AAQA,IAAM,IAAwC;CAC5C,MAAM;CACN,aAAa;CACb,aAAa;CACb,QAAQ;CACR,YAAY;CACZ,QAAQ;AACV,GAEM,IAAoF;CACxF,KAAK;CACL,MAAM;EAAE,aAAa;EAAG,aAAa;EAAG,QAAQ;EAAG,YAAY;EAAG,QAAQ;CAAE;CAC5E,QAAQ;EAAE,aAAa;EAAG,aAAa;EAAG,YAAY;EAAG,QAAQ;CAAE;CACnE,OAAO;EAAE,GAAG;EAAW,KAAK;CAAE;CAC9B,MAAM;EAAE,GAAG;EAAW,KAAK;EAAG,OAAO;CAAE;AACzC;AAMA,SAAgB,EACd,GACA,GACA,GACkB;CAClB,IAAM,IAAQ,EAAQ,GAAO;EAAE,QAAQ,EAAQ;EAAQ,IAAI,EAAQ;CAAG,CAAC;CAEvE,IAAI,MAAS,QAAQ;EACnB,IAAM,KAAkB,EAAM,aAAa,EAAQ,gBAAgB,KAAK,KAAK;EAE7E,OAAO,EAAM,SAAS,EAAE,MAAM,EAAe,CAAC,CAAC,CAAC,KAAK,CAAS,CAAC,CAAC,UAAU;CAC5E;CAEA,OAAO,EAAM,KAAK,EAAe,EAAK,CAAC,CAAC,UAAU;AACpD"}
1
+ {"version":3,"file":"_floor.js","names":[],"sources":["../src/_floor.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { BoundaryUnit, Disambiguation, TimeInput } from './types';\n\nimport { toZoned } from './_convert';\n\nconst TIME_ZERO: Temporal.ZonedDateTimeLike = {\n hour: 0,\n microsecond: 0,\n millisecond: 0,\n minute: 0,\n nanosecond: 0,\n second: 0,\n};\n\nconst BOUNDARY_CLEAR: Record<Exclude<BoundaryUnit, 'week'>, Temporal.ZonedDateTimeLike> = {\n day: TIME_ZERO,\n hour: { microsecond: 0, millisecond: 0, minute: 0, nanosecond: 0, second: 0 },\n minute: { microsecond: 0, millisecond: 0, nanosecond: 0, second: 0 },\n month: { ...TIME_ZERO, day: 1 },\n year: { ...TIME_ZERO, day: 1, month: 1 },\n};\n\nexport function floorToUnit(\n input: TimeInput,\n unit: BoundaryUnit,\n options: { disambiguation?: Disambiguation; timeZone: string; weekStartsOn?: number },\n): Temporal.Instant {\n const zoned = toZoned(input, options);\n\n if (unit === 'week') {\n const daysToSubtract = (zoned.dayOfWeek - (options.weekStartsOn ?? 1) + 7) % 7;\n\n return zoned.subtract({ days: daysToSubtract }).with(TIME_ZERO).toInstant();\n }\n\n return zoned.with(BOUNDARY_CLEAR[unit]).toInstant();\n}\n"],"mappings":";;;AAMA,IAAM,IAAwC;CAC5C,MAAM;CACN,aAAa;CACb,aAAa;CACb,QAAQ;CACR,YAAY;CACZ,QAAQ;AACV,GAEM,IAAoF;CACxF,KAAK;CACL,MAAM;EAAE,aAAa;EAAG,aAAa;EAAG,QAAQ;EAAG,YAAY;EAAG,QAAQ;CAAE;CAC5E,QAAQ;EAAE,aAAa;EAAG,aAAa;EAAG,YAAY;EAAG,QAAQ;CAAE;CACnE,OAAO;EAAE,GAAG;EAAW,KAAK;CAAE;CAC9B,MAAM;EAAE,GAAG;EAAW,KAAK;EAAG,OAAO;CAAE;AACzC;AAEA,SAAgB,EACd,GACA,GACA,GACkB;CAClB,IAAM,IAAQ,EAAQ,GAAO,CAAO;CAEpC,IAAI,MAAS,QAAQ;EACnB,IAAM,KAAkB,EAAM,aAAa,EAAQ,gBAAgB,KAAK,KAAK;EAE7E,OAAO,EAAM,SAAS,EAAE,MAAM,EAAe,CAAC,CAAC,CAAC,KAAK,CAAS,CAAC,CAAC,UAAU;CAC5E;CAEA,OAAO,EAAM,KAAK,EAAe,EAAK,CAAC,CAAC,UAAU;AACpD"}
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 (e.g. "America/New_York") or UTC offset (e.g. "+05:30").`,e.TempoInvalidTzError)}return n}function r(r,i){let a=i.tz??(r instanceof t.Temporal.ZonedDateTime?r.timeZoneId:void 0);return a||e.fail(`This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.`,e.TempoMissingTzError),n(a)}function i(r,i){if(i.tz)return n(i.tz);let a;for(let n of r){if(!(n instanceof t.Temporal.ZonedDateTime))continue;let r=n.timeZoneId;if(!a){a=r;continue}a!==r&&e.fail(`Comparison received ZonedDateTime inputs with different time zones. Pass options.tz explicitly.`)}return a||e.fail(`This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.`,e.TempoMissingTzError),a}function a(e,n){return t.Temporal.Instant.compare(e,n)<=0?[e,n]:[n,e]}var o=new Set([`day`,`month`,`week`,`year`]),s=26298e5;exports.CALENDAR_UNITS=o,exports.MS_PER_MONTH=s,exports.inferSharedTimeZone=i,exports.inferTimeZone=r,exports.normalizeRange=a,exports.validateTz=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{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}function a(e,n){return t.Temporal.Instant.compare(e,n)<=0?[e,n]:[n,e]}var o=new Set([`day`,`month`,`week`,`year`]);exports.CALENDAR_UNITS=o,exports.inferSharedTimeZone=i,exports.inferTimeZone=r,exports.normalizeRange=a,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';\n\nimport type { CalendarUnit, TimeInput } from './types';\n\nimport { TempoInvalidTzError, TempoMissingTzError, fail } from './errors';\n\n// ─── Timezone validation ──────────────────────────────────────────────────────\n\nexport function validateTz(tz: string): string {\n try {\n Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(tz);\n } catch {\n fail(\n `Unknown or invalid timezone: \"${tz}\". Expected an IANA timezone name (e.g. \"America/New_York\") or UTC offset (e.g. \"+05:30\").`,\n TempoInvalidTzError,\n );\n }\n\n return tz;\n}\n\n// ─── Timezone inference ───────────────────────────────────────────────────────\n\nexport function inferTimeZone(input: TimeInput, options: { tz?: string }): string {\n const tz = options.tz ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n if (!tz)\n fail('This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.', TempoMissingTzError);\n\n return validateTz(tz);\n}\n\nexport function inferSharedTimeZone(inputs: TimeInput[], options: { tz?: string }): string {\n if (options.tz) return validateTz(options.tz);\n\n let inferred: string | undefined;\n\n for (const input of inputs) {\n if (!(input instanceof Temporal.ZonedDateTime)) continue;\n\n const tz = input.timeZoneId;\n\n if (!inferred) {\n inferred = tz;\n continue;\n }\n\n if (inferred !== tz) {\n fail('Comparison received ZonedDateTime inputs with different time zones. Pass options.tz explicitly.');\n }\n }\n\n if (!inferred)\n fail('This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.', TempoMissingTzError);\n\n return inferred;\n}\n\n// ─── Range normalization ──────────────────────────────────────────────────────\n\nexport function normalizeRange(start: Temporal.Instant, end: Temporal.Instant): [Temporal.Instant, Temporal.Instant] {\n return Temporal.Instant.compare(start, end) <= 0 ? [start, end] : [end, start];\n}\n\n// ─── Shared constants ─────────────────────────────────────────────────────────\n\n/** Units that require timezone-aware context for calendar-accurate operations. */\nexport const CALENDAR_UNITS = new Set<CalendarUnit>(['day', 'month', 'week', 'year']);\n\n/** Approximate millisecond constants for threshold arithmetic. */\nexport const MS_PER_MONTH = 30.4375 * 86_400_000; // 365.25 / 12 days × 86400 s × 1000\n"],"mappings":"uEAQA,SAAgB,EAAW,EAAoB,CAC7C,GAAI,CACF,EAAA,SAAS,QAAQ,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,CAAE,CACjE,MAAQ,CACN,EAAA,KACE,iCAAiC,EAAG,4FACpC,EAAA,mBACF,CACF,CAEA,OAAO,CACT,CAIA,SAAgB,EAAc,EAAkB,EAAkC,CAChF,IAAM,EAAK,EAAQ,KAAO,aAAiB,EAAA,SAAS,cAAgB,EAAM,WAAa,IAAA,IAKvF,OAHK,GACH,EAAA,KAAK,oFAAqF,EAAA,mBAAmB,EAExG,EAAW,CAAE,CACtB,CAEA,SAAgB,EAAoB,EAAqB,EAAkC,CACzF,GAAI,EAAQ,GAAI,OAAO,EAAW,EAAQ,EAAE,EAE5C,IAAI,EAEJ,IAAK,IAAM,KAAS,EAAQ,CAC1B,GAAI,EAAE,aAAiB,EAAA,SAAS,eAAgB,SAEhD,IAAM,EAAK,EAAM,WAEjB,GAAI,CAAC,EAAU,CACb,EAAW,EACX,QACF,CAEI,IAAa,GACf,EAAA,KAAK,iGAAiG,CAE1G,CAKA,OAHK,GACH,EAAA,KAAK,oFAAqF,EAAA,mBAAmB,EAExG,CACT,CAIA,SAAgB,EAAe,EAAyB,EAA6D,CACnH,OAAO,EAAA,SAAS,QAAQ,QAAQ,EAAO,CAAG,GAAK,EAAI,CAAC,EAAO,CAAG,EAAI,CAAC,EAAK,CAAK,CAC/E,CAKA,IAAa,EAAiB,IAAI,IAAkB,CAAC,MAAO,QAAS,OAAQ,MAAM,CAAC,EAGvE,EAAe"}
1
+ {"version":3,"file":"_tz.cjs","names":[],"sources":["../src/_tz.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';\n\nimport { TempoInvalidTzError, TempoMissingTzError, fail } from './errors';\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 function normalizeRange(start: Temporal.Instant, end: Temporal.Instant): [Temporal.Instant, Temporal.Instant] {\n return Temporal.Instant.compare(start, end) <= 0 ? [start, end] : [end, start];\n}\n\nexport const CALENDAR_UNITS = new Set<CalendarUnit>(['day', 'month', 'week', 'year']);\n"],"mappings":"uEAMA,SAAgB,EAAiB,EAA0B,CACzD,GAAI,CACF,EAAA,SAAS,QAAQ,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,CAAQ,CACvE,MAAQ,CACN,EAAA,KACE,iCAAiC,EAAS,kDAC1C,EAAA,mBACF,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,SAAgB,EAAe,EAAyB,EAA6D,CACnH,OAAO,EAAA,SAAS,QAAQ,QAAQ,EAAO,CAAG,GAAK,EAAI,CAAC,EAAO,CAAG,EAAI,CAAC,EAAK,CAAK,CAC/E,CAEA,IAAa,EAAiB,IAAI,IAAkB,CAAC,MAAO,QAAS,OAAQ,MAAM,CAAC"}
package/dist/_tz.d.ts CHANGED
@@ -1,15 +1,8 @@
1
1
  import { Temporal } from '@js-temporal/polyfill';
2
- import type { CalendarUnit, TimeInput } from './types';
3
- export declare function validateTz(tz: string): string;
4
- export declare function inferTimeZone(input: TimeInput, options: {
5
- tz?: string;
6
- }): string;
7
- export declare function inferSharedTimeZone(inputs: TimeInput[], options: {
8
- tz?: string;
9
- }): string;
2
+ import type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';
3
+ export declare function validateTimeZone(timeZone: string): string;
4
+ export declare function inferTimeZone(input: TimeInput, options: TimeZoneOptions): string;
5
+ export declare function inferSharedTimeZone(inputs: readonly TimeInput[], options: TimeZoneOptions): string;
10
6
  export declare function normalizeRange(start: Temporal.Instant, end: Temporal.Instant): [Temporal.Instant, Temporal.Instant];
11
- /** Units that require timezone-aware context for calendar-accurate operations. */
12
7
  export declare const CALENDAR_UNITS: Set<CalendarUnit>;
13
- /** Approximate millisecond constants for threshold arithmetic. */
14
- export declare const MS_PER_MONTH: number;
15
8
  //# sourceMappingURL=_tz.d.ts.map
package/dist/_tz.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"_tz.d.ts","sourceRoot":"","sources":["../src/_tz.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAMvD,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAW7C;AAID,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAOhF;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAwBzF;AAID,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAEnH;AAID,kFAAkF;AAClF,eAAO,MAAM,cAAc,mBAA0D,CAAC;AAEtF,kEAAkE;AAClE,eAAO,MAAM,YAAY,QAAuB,CAAC"}
1
+ {"version":3,"file":"_tz.d.ts","sourceRoot":"","sources":["../src/_tz.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAIxE,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAWzD;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,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAEnH;AAED,eAAO,MAAM,cAAc,mBAA0D,CAAC"}
package/dist/_tz.js CHANGED
@@ -5,27 +5,19 @@ function i(t) {
5
5
  try {
6
6
  r.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(t);
7
7
  } catch {
8
- n(`Unknown or invalid timezone: "${t}". Expected an IANA timezone name (e.g. "America/New_York") or UTC offset (e.g. "+05:30").`, e);
8
+ n(`Unknown or invalid timezone: "${t}". Expected an IANA timezone name or UTC offset.`, e);
9
9
  }
10
10
  return t;
11
11
  }
12
12
  function a(e, a) {
13
- let o = a.tz ?? (e instanceof r.ZonedDateTime ? e.timeZoneId : void 0);
14
- return o || n("This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.", t), i(o);
13
+ let o = a.timeZone ?? (e instanceof r.ZonedDateTime ? e.timeZoneId : void 0);
14
+ return o || n("This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.", t), i(o);
15
15
  }
16
16
  function o(e, a) {
17
- if (a.tz) return i(a.tz);
17
+ if (a.timeZone) return i(a.timeZone);
18
18
  let o;
19
- for (let t of e) {
20
- if (!(t instanceof r.ZonedDateTime)) continue;
21
- let e = t.timeZoneId;
22
- if (!o) {
23
- o = e;
24
- continue;
25
- }
26
- o !== e && n("Comparison received ZonedDateTime inputs with different time zones. Pass options.tz explicitly.");
27
- }
28
- return o || n("This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.", t), o;
19
+ for (let t of e) t instanceof r.ZonedDateTime && (o ? o !== t.timeZoneId && n("Inputs use different time zones. Pass options.timeZone explicitly.") : o = t.timeZoneId);
20
+ return o || n("This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.", t), o;
29
21
  }
30
22
  function s(e, t) {
31
23
  return r.Instant.compare(e, t) <= 0 ? [e, t] : [t, e];
@@ -35,8 +27,8 @@ var c = /* @__PURE__ */ new Set([
35
27
  "month",
36
28
  "week",
37
29
  "year"
38
- ]), l = 26298e5;
30
+ ]);
39
31
  //#endregion
40
- export { c as CALENDAR_UNITS, l as MS_PER_MONTH, o as inferSharedTimeZone, a as inferTimeZone, s as normalizeRange, i as validateTz };
32
+ export { c as CALENDAR_UNITS, o as inferSharedTimeZone, a as inferTimeZone, s as normalizeRange, i as validateTimeZone };
41
33
 
42
34
  //# sourceMappingURL=_tz.js.map
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';\n\nimport type { CalendarUnit, TimeInput } from './types';\n\nimport { TempoInvalidTzError, TempoMissingTzError, fail } from './errors';\n\n// ─── Timezone validation ──────────────────────────────────────────────────────\n\nexport function validateTz(tz: string): string {\n try {\n Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(tz);\n } catch {\n fail(\n `Unknown or invalid timezone: \"${tz}\". Expected an IANA timezone name (e.g. \"America/New_York\") or UTC offset (e.g. \"+05:30\").`,\n TempoInvalidTzError,\n );\n }\n\n return tz;\n}\n\n// ─── Timezone inference ───────────────────────────────────────────────────────\n\nexport function inferTimeZone(input: TimeInput, options: { tz?: string }): string {\n const tz = options.tz ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n if (!tz)\n fail('This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.', TempoMissingTzError);\n\n return validateTz(tz);\n}\n\nexport function inferSharedTimeZone(inputs: TimeInput[], options: { tz?: string }): string {\n if (options.tz) return validateTz(options.tz);\n\n let inferred: string | undefined;\n\n for (const input of inputs) {\n if (!(input instanceof Temporal.ZonedDateTime)) continue;\n\n const tz = input.timeZoneId;\n\n if (!inferred) {\n inferred = tz;\n continue;\n }\n\n if (inferred !== tz) {\n fail('Comparison received ZonedDateTime inputs with different time zones. Pass options.tz explicitly.');\n }\n }\n\n if (!inferred)\n fail('This operation requires a timezone. Pass options.tz or use a ZonedDateTime input.', TempoMissingTzError);\n\n return inferred;\n}\n\n// ─── Range normalization ──────────────────────────────────────────────────────\n\nexport function normalizeRange(start: Temporal.Instant, end: Temporal.Instant): [Temporal.Instant, Temporal.Instant] {\n return Temporal.Instant.compare(start, end) <= 0 ? [start, end] : [end, start];\n}\n\n// ─── Shared constants ─────────────────────────────────────────────────────────\n\n/** Units that require timezone-aware context for calendar-accurate operations. */\nexport const CALENDAR_UNITS = new Set<CalendarUnit>(['day', 'month', 'week', 'year']);\n\n/** Approximate millisecond constants for threshold arithmetic. */\nexport const MS_PER_MONTH = 30.4375 * 86_400_000; // 365.25 / 12 days × 86400 s × 1000\n"],"mappings":";;;AAQA,SAAgB,EAAW,GAAoB;CAC7C,IAAI;EACF,EAAS,QAAQ,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,CAAE;CACjE,QAAQ;EACN,EACE,iCAAiC,EAAG,6FACpC,CACF;CACF;CAEA,OAAO;AACT;AAIA,SAAgB,EAAc,GAAkB,GAAkC;CAChF,IAAM,IAAK,EAAQ,OAAO,aAAiB,EAAS,gBAAgB,EAAM,aAAa,KAAA;CAKvF,OAHK,KACH,EAAK,qFAAqF,CAAmB,GAExG,EAAW,CAAE;AACtB;AAEA,SAAgB,EAAoB,GAAqB,GAAkC;CACzF,IAAI,EAAQ,IAAI,OAAO,EAAW,EAAQ,EAAE;CAE5C,IAAI;CAEJ,KAAK,IAAM,KAAS,GAAQ;EAC1B,IAAI,EAAE,aAAiB,EAAS,gBAAgB;EAEhD,IAAM,IAAK,EAAM;EAEjB,IAAI,CAAC,GAAU;GACb,IAAW;GACX;EACF;EAEA,AAAI,MAAa,KACf,EAAK,iGAAiG;CAE1G;CAKA,OAHK,KACH,EAAK,qFAAqF,CAAmB,GAExG;AACT;AAIA,SAAgB,EAAe,GAAyB,GAA6D;CACnH,OAAO,EAAS,QAAQ,QAAQ,GAAO,CAAG,KAAK,IAAI,CAAC,GAAO,CAAG,IAAI,CAAC,GAAK,CAAK;AAC/E;AAKA,IAAa,oBAAiB,IAAI,IAAkB;CAAC;CAAO;CAAS;CAAQ;AAAM,CAAC,GAGvE,IAAe"}
1
+ {"version":3,"file":"_tz.js","names":[],"sources":["../src/_tz.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';\n\nimport { TempoInvalidTzError, TempoMissingTzError, fail } from './errors';\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 function normalizeRange(start: Temporal.Instant, end: Temporal.Instant): [Temporal.Instant, Temporal.Instant] {\n return Temporal.Instant.compare(start, end) <= 0 ? [start, end] : [end, start];\n}\n\nexport const CALENDAR_UNITS = new Set<CalendarUnit>(['day', 'month', 'week', 'year']);\n"],"mappings":";;;AAMA,SAAgB,EAAiB,GAA0B;CACzD,IAAI;EACF,EAAS,QAAQ,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,CAAQ;CACvE,QAAQ;EACN,EACE,iCAAiC,EAAS,mDAC1C,CACF;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,SAAgB,EAAe,GAAyB,GAA6D;CACnH,OAAO,EAAS,QAAQ,QAAQ,GAAO,CAAG,KAAK,IAAI,CAAC,GAAO,CAAG,IAAI,CAAC,GAAK,CAAK;AAC/E;AAEA,IAAa,oBAAiB,IAAI,IAAkB;CAAC;CAAO;CAAS;CAAQ;AAAM,CAAC"}
package/dist/boundary.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./_tz.cjs"),t=require("./_floor.cjs");require("@js-temporal/polyfill");var n={day:{days:1},hour:{hours:1},minute:{minutes:1},month:{months:1},week:{weeks:1},year:{years:1}};function r(n,r,i={}){let a=e.inferTimeZone(n,i);return t.floorToUnit(n,r,{tz:a,weekStartsOn:i.weekStartsOn}).toZonedDateTimeISO(a)}function i(r,i,a={}){let o=e.inferTimeZone(r,a);return t.floorToUnit(r,i,{tz:o,weekStartsOn:a.weekStartsOn}).toZonedDateTimeISO(o).add(n[i]).subtract({nanoseconds:1})}exports.endOf=i,exports.startOf=r;
1
+ const e=require("./_tz.cjs"),t=require("./_floor.cjs");require("@js-temporal/polyfill");var n={day:{days:1},hour:{hours:1},minute:{minutes:1},month:{months:1},week:{weeks:1},year:{years:1}};function r(n,r,i={}){let a=e.inferTimeZone(n,i);return t.floorToUnit(n,r,{timeZone:a,weekStartsOn:i.weekStartsOn}).toZonedDateTimeISO(a)}function i(r,i,a={}){let o=e.inferTimeZone(r,a);return t.floorToUnit(r,i,{timeZone:o,weekStartsOn:a.weekStartsOn}).toZonedDateTimeISO(o).add(n[i]).subtract({nanoseconds:1})}exports.endOf=i,exports.startOf=r;
2
2
  //# sourceMappingURL=boundary.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"boundary.cjs","names":[],"sources":["../src/boundary.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { BoundaryOptions, BoundaryUnit, TimeInput } from './types';\n\nimport { floorToUnit } from './_floor';\nimport { inferTimeZone } from './_tz';\n\n// ─── Boundary step durations ──────────────────────────────────────────────────\n\nconst BOUNDARY_STEP: Record<BoundaryUnit, Temporal.DurationLike> = {\n day: { days: 1 },\n hour: { hours: 1 },\n minute: { minutes: 1 },\n month: { months: 1 },\n week: { weeks: 1 },\n year: { years: 1 },\n};\n\n// ─── Public API ───────────────────────────────────────────────────────────────\n\n/**\n * Returns the start of the given `unit` in the inferred or explicit timezone.\n *\n * @example\n * ```ts\n * startOf(parseInstant('2026-03-21T10:15:30Z'), 'day', { tz: 'UTC' })\n * // 2026-03-21T00:00:00+00:00[UTC]\n *\n * startOf(instant, 'week', { tz: 'UTC', weekStartsOn: 1 })\n * // Monday of the current week\n * ```\n */\nexport function startOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const tz = inferTimeZone(input, options);\n\n return floorToUnit(input, unit, { tz, weekStartsOn: options.weekStartsOn }).toZonedDateTimeISO(tz);\n}\n\n/**\n * Returns the last nanosecond of the given `unit` (exactly 1 ns before the next unit starts).\n *\n * @example\n * ```ts\n * endOf(parseInstant('2026-03-21T10:15:30Z'), 'day', { tz: 'UTC' })\n * // 2026-03-21T23:59:59.999999999+00:00[UTC]\n * ```\n */\nexport function endOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const tz = inferTimeZone(input, options);\n const startInstant = floorToUnit(input, unit, { tz, weekStartsOn: options.weekStartsOn });\n\n return startInstant.toZonedDateTimeISO(tz).add(BOUNDARY_STEP[unit]).subtract({ nanoseconds: 1 });\n}\n"],"mappings":"wFASA,IAAM,EAA6D,CACjE,IAAK,CAAE,KAAM,CAAE,EACf,KAAM,CAAE,MAAO,CAAE,EACjB,OAAQ,CAAE,QAAS,CAAE,EACrB,MAAO,CAAE,OAAQ,CAAE,EACnB,KAAM,CAAE,MAAO,CAAE,EACjB,KAAM,CAAE,MAAO,CAAE,CACnB,EAgBA,SAAgB,EAAQ,EAAkB,EAAoB,EAA2B,CAAC,EAA2B,CACnH,IAAM,EAAK,EAAA,cAAc,EAAO,CAAO,EAEvC,OAAO,EAAA,YAAY,EAAO,EAAM,CAAE,KAAI,aAAc,EAAQ,YAAa,CAAC,CAAC,CAAC,mBAAmB,CAAE,CACnG,CAWA,SAAgB,EAAM,EAAkB,EAAoB,EAA2B,CAAC,EAA2B,CACjH,IAAM,EAAK,EAAA,cAAc,EAAO,CAAO,EAGvC,OAFqB,EAAA,YAAY,EAAO,EAAM,CAAE,KAAI,aAAc,EAAQ,YAAa,CAEhF,CAAA,CAAa,mBAAmB,CAAE,CAAC,CAAC,IAAI,EAAc,EAAK,CAAC,CAAC,SAAS,CAAE,YAAa,CAAE,CAAC,CACjG"}
1
+ {"version":3,"file":"boundary.cjs","names":[],"sources":["../src/boundary.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { BoundaryOptions, BoundaryUnit, TimeInput } from './types';\n\nimport { floorToUnit } from './_floor';\nimport { inferTimeZone } from './_tz';\n\nconst BOUNDARY_STEP: Record<BoundaryUnit, Temporal.DurationLike> = {\n day: { days: 1 },\n hour: { hours: 1 },\n minute: { minutes: 1 },\n month: { months: 1 },\n week: { weeks: 1 },\n year: { years: 1 },\n};\n\nexport function startOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n\n return floorToUnit(input, unit, { timeZone, weekStartsOn: options.weekStartsOn }).toZonedDateTimeISO(timeZone);\n}\n\nexport function endOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n const start = floorToUnit(input, unit, { timeZone, weekStartsOn: options.weekStartsOn });\n\n return start.toZonedDateTimeISO(timeZone).add(BOUNDARY_STEP[unit]).subtract({ nanoseconds: 1 });\n}\n"],"mappings":"wFAOA,IAAM,EAA6D,CACjE,IAAK,CAAE,KAAM,CAAE,EACf,KAAM,CAAE,MAAO,CAAE,EACjB,OAAQ,CAAE,QAAS,CAAE,EACrB,MAAO,CAAE,OAAQ,CAAE,EACnB,KAAM,CAAE,MAAO,CAAE,EACjB,KAAM,CAAE,MAAO,CAAE,CACnB,EAEA,SAAgB,EAAQ,EAAkB,EAAoB,EAA2B,CAAC,EAA2B,CACnH,IAAM,EAAW,EAAA,cAAc,EAAO,CAAO,EAE7C,OAAO,EAAA,YAAY,EAAO,EAAM,CAAE,WAAU,aAAc,EAAQ,YAAa,CAAC,CAAC,CAAC,mBAAmB,CAAQ,CAC/G,CAEA,SAAgB,EAAM,EAAkB,EAAoB,EAA2B,CAAC,EAA2B,CACjH,IAAM,EAAW,EAAA,cAAc,EAAO,CAAO,EAG7C,OAFc,EAAA,YAAY,EAAO,EAAM,CAAE,WAAU,aAAc,EAAQ,YAAa,CAE/E,CAAA,CAAM,mBAAmB,CAAQ,CAAC,CAAC,IAAI,EAAc,EAAK,CAAC,CAAC,SAAS,CAAE,YAAa,CAAE,CAAC,CAChG"}
@@ -1,26 +1,5 @@
1
1
  import { Temporal } from '@js-temporal/polyfill';
2
2
  import type { BoundaryOptions, BoundaryUnit, TimeInput } from './types';
3
- /**
4
- * Returns the start of the given `unit` in the inferred or explicit timezone.
5
- *
6
- * @example
7
- * ```ts
8
- * startOf(parseInstant('2026-03-21T10:15:30Z'), 'day', { tz: 'UTC' })
9
- * // 2026-03-21T00:00:00+00:00[UTC]
10
- *
11
- * startOf(instant, 'week', { tz: 'UTC', weekStartsOn: 1 })
12
- * // Monday of the current week
13
- * ```
14
- */
15
3
  export declare function startOf(input: TimeInput, unit: BoundaryUnit, options?: BoundaryOptions): Temporal.ZonedDateTime;
16
- /**
17
- * Returns the last nanosecond of the given `unit` (exactly 1 ns before the next unit starts).
18
- *
19
- * @example
20
- * ```ts
21
- * endOf(parseInstant('2026-03-21T10:15:30Z'), 'day', { tz: 'UTC' })
22
- * // 2026-03-21T23:59:59.999999999+00:00[UTC]
23
- * ```
24
- */
25
4
  export declare function endOf(input: TimeInput, unit: BoundaryUnit, options?: BoundaryOptions): Temporal.ZonedDateTime;
26
5
  //# sourceMappingURL=boundary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../src/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAkBxE;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAAC,aAAa,CAInH;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAAC,aAAa,CAKjH"}
1
+ {"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../src/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAcxE,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAAC,aAAa,CAInH;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAAC,aAAa,CAKjH"}
package/dist/boundary.js CHANGED
@@ -13,14 +13,14 @@ var n = {
13
13
  function r(n, r, i = {}) {
14
14
  let a = e(n, i);
15
15
  return t(n, r, {
16
- tz: a,
16
+ timeZone: a,
17
17
  weekStartsOn: i.weekStartsOn
18
18
  }).toZonedDateTimeISO(a);
19
19
  }
20
20
  function i(r, i, a = {}) {
21
21
  let o = e(r, a);
22
22
  return t(r, i, {
23
- tz: o,
23
+ timeZone: o,
24
24
  weekStartsOn: a.weekStartsOn
25
25
  }).toZonedDateTimeISO(o).add(n[i]).subtract({ nanoseconds: 1 });
26
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"boundary.js","names":[],"sources":["../src/boundary.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { BoundaryOptions, BoundaryUnit, TimeInput } from './types';\n\nimport { floorToUnit } from './_floor';\nimport { inferTimeZone } from './_tz';\n\n// ─── Boundary step durations ──────────────────────────────────────────────────\n\nconst BOUNDARY_STEP: Record<BoundaryUnit, Temporal.DurationLike> = {\n day: { days: 1 },\n hour: { hours: 1 },\n minute: { minutes: 1 },\n month: { months: 1 },\n week: { weeks: 1 },\n year: { years: 1 },\n};\n\n// ─── Public API ───────────────────────────────────────────────────────────────\n\n/**\n * Returns the start of the given `unit` in the inferred or explicit timezone.\n *\n * @example\n * ```ts\n * startOf(parseInstant('2026-03-21T10:15:30Z'), 'day', { tz: 'UTC' })\n * // 2026-03-21T00:00:00+00:00[UTC]\n *\n * startOf(instant, 'week', { tz: 'UTC', weekStartsOn: 1 })\n * // Monday of the current week\n * ```\n */\nexport function startOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const tz = inferTimeZone(input, options);\n\n return floorToUnit(input, unit, { tz, weekStartsOn: options.weekStartsOn }).toZonedDateTimeISO(tz);\n}\n\n/**\n * Returns the last nanosecond of the given `unit` (exactly 1 ns before the next unit starts).\n *\n * @example\n * ```ts\n * endOf(parseInstant('2026-03-21T10:15:30Z'), 'day', { tz: 'UTC' })\n * // 2026-03-21T23:59:59.999999999+00:00[UTC]\n * ```\n */\nexport function endOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const tz = inferTimeZone(input, options);\n const startInstant = floorToUnit(input, unit, { tz, weekStartsOn: options.weekStartsOn });\n\n return startInstant.toZonedDateTimeISO(tz).add(BOUNDARY_STEP[unit]).subtract({ nanoseconds: 1 });\n}\n"],"mappings":";;;;AASA,IAAM,IAA6D;CACjE,KAAK,EAAE,MAAM,EAAE;CACf,MAAM,EAAE,OAAO,EAAE;CACjB,QAAQ,EAAE,SAAS,EAAE;CACrB,OAAO,EAAE,QAAQ,EAAE;CACnB,MAAM,EAAE,OAAO,EAAE;CACjB,MAAM,EAAE,OAAO,EAAE;AACnB;AAgBA,SAAgB,EAAQ,GAAkB,GAAoB,IAA2B,CAAC,GAA2B;CACnH,IAAM,IAAK,EAAc,GAAO,CAAO;CAEvC,OAAO,EAAY,GAAO,GAAM;EAAE;EAAI,cAAc,EAAQ;CAAa,CAAC,CAAC,CAAC,mBAAmB,CAAE;AACnG;AAWA,SAAgB,EAAM,GAAkB,GAAoB,IAA2B,CAAC,GAA2B;CACjH,IAAM,IAAK,EAAc,GAAO,CAAO;CAGvC,OAFqB,EAAY,GAAO,GAAM;EAAE;EAAI,cAAc,EAAQ;CAAa,CAEhF,CAAA,CAAa,mBAAmB,CAAE,CAAC,CAAC,IAAI,EAAc,EAAK,CAAC,CAAC,SAAS,EAAE,aAAa,EAAE,CAAC;AACjG"}
1
+ {"version":3,"file":"boundary.js","names":[],"sources":["../src/boundary.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { BoundaryOptions, BoundaryUnit, TimeInput } from './types';\n\nimport { floorToUnit } from './_floor';\nimport { inferTimeZone } from './_tz';\n\nconst BOUNDARY_STEP: Record<BoundaryUnit, Temporal.DurationLike> = {\n day: { days: 1 },\n hour: { hours: 1 },\n minute: { minutes: 1 },\n month: { months: 1 },\n week: { weeks: 1 },\n year: { years: 1 },\n};\n\nexport function startOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n\n return floorToUnit(input, unit, { timeZone, weekStartsOn: options.weekStartsOn }).toZonedDateTimeISO(timeZone);\n}\n\nexport function endOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n const start = floorToUnit(input, unit, { timeZone, weekStartsOn: options.weekStartsOn });\n\n return start.toZonedDateTimeISO(timeZone).add(BOUNDARY_STEP[unit]).subtract({ nanoseconds: 1 });\n}\n"],"mappings":";;;;AAOA,IAAM,IAA6D;CACjE,KAAK,EAAE,MAAM,EAAE;CACf,MAAM,EAAE,OAAO,EAAE;CACjB,QAAQ,EAAE,SAAS,EAAE;CACrB,OAAO,EAAE,QAAQ,EAAE;CACnB,MAAM,EAAE,OAAO,EAAE;CACjB,MAAM,EAAE,OAAO,EAAE;AACnB;AAEA,SAAgB,EAAQ,GAAkB,GAAoB,IAA2B,CAAC,GAA2B;CACnH,IAAM,IAAW,EAAc,GAAO,CAAO;CAE7C,OAAO,EAAY,GAAO,GAAM;EAAE;EAAU,cAAc,EAAQ;CAAa,CAAC,CAAC,CAAC,mBAAmB,CAAQ;AAC/G;AAEA,SAAgB,EAAM,GAAkB,GAAoB,IAA2B,CAAC,GAA2B;CACjH,IAAM,IAAW,EAAc,GAAO,CAAO;CAG7C,OAFc,EAAY,GAAO,GAAM;EAAE;EAAU,cAAc,EAAQ;CAAa,CAE/E,CAAA,CAAM,mBAAmB,CAAQ,CAAC,CAAC,IAAI,EAAc,EAAK,CAAC,CAAC,SAAS,EAAE,aAAa,EAAE,CAAC;AAChG"}
package/dist/classify.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./_tz.cjs"),t=require("./_convert.cjs");let n=require("@js-temporal/polyfill");var r=new WeakMap;function i(e){let t=r.get(e);if(t)return t;let n=Object.keys(e).map(t=>({key:t,ms:o(e[t])})).sort((e,t)=>e.ms-t.ms);return r.set(e,n),n}function a(e,r,a={},o=n.Temporal.Now.instant()){let s=t.toInstant(e,a).epochMilliseconds-o.epochMilliseconds;for(let{key:e,ms:t}of i(r))if(s<=t)return e;return null}function o(t){let r=n.Temporal.Duration.from(t);return(r.years??0)*12*e.MS_PER_MONTH+(r.months??0)*e.MS_PER_MONTH+(r.weeks??0)*7*864e5+(r.days??0)*864e5+(r.hours??0)*36e5+(r.minutes??0)*6e4+(r.seconds??0)*1e3+(r.milliseconds??0)+(r.microseconds??0)/1e3+(r.nanoseconds??0)/1e6}var s=[{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 c(e,t){return n.Temporal.ZonedDateTime.compare(e,t)<=0?t.since(e,{largestUnit:`year`}):e.since(t,{largestUnit:`year`})}function l(e){for(let{field:t,unit:n}of s){let r=Math.abs(e[t]);if(r>0)return{unit:n,value:r}}return{unit:`millisecond`,value:0}}function u(r,i,a={}){let o=i??n.Temporal.Now.instant();if(!a.tz&&r instanceof n.Temporal.Instant&&o instanceof n.Temporal.Instant)return l(c(r.toZonedDateTimeISO(`UTC`),o.toZonedDateTimeISO(`UTC`)));let s=e.inferSharedTimeZone([r,o],a);return l(c(t.toZoned(r,{tz:s}),t.toZoned(o,{tz:s})))}exports.expires=a,exports.timeDiff=u;
1
+ const e=require("./errors.cjs"),t=require("./_tz.cjs"),n=require("./_convert.cjs");let r=require("@js-temporal/polyfill");var i={day:864e5,hour:36e5,microsecond:1/1e3,millisecond:1,minute:6e4,nanosecond:1/1e6,second:1e3,week:6048e5},a=[{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 o(t){let n=r.Temporal.Duration.from(t);if(n.years||n.months)throw new e.TempoInvalidInputError(`classifyExpiry thresholds cannot contain months or years. Use fixed elapsed-time units.`);return n.weeks*i.week+n.days*i.day+n.hours*i.hour+n.minutes*i.minute+n.seconds*i.second+n.milliseconds+n.microseconds*i.microsecond+n.nanoseconds*i.nanosecond}function s(e){let t=e.relativeTo??r.Temporal.Now.instant(),i=n.toInstant(e.value,e).epochMilliseconds-t.epochMilliseconds;return Object.entries(e.thresholds).map(([e,t])=>({key:e,max:o(t)})).sort((e,t)=>e.max-t.max).find(({max:e})=>i<=e)?.key??null}function c(e){for(let{field:t,unit:n}of a){let r=Math.abs(e[t]);if(r>0)return{unit:n,value:r}}return{unit:`millisecond`,value:0}}function l(e,i=r.Temporal.Now.instant(),a={}){if(!a.timeZone&&e instanceof r.Temporal.Instant&&i instanceof r.Temporal.Instant){let t=e.toZonedDateTimeISO(`UTC`),n=i.toZonedDateTimeISO(`UTC`);return c(r.Temporal.ZonedDateTime.compare(t,n)<=0?n.since(t,{largestUnit:`year`}):t.since(n,{largestUnit:`year`}))}let o=t.inferSharedTimeZone([e,i],a),s=n.toZoned(e,{timeZone:o}),l=n.toZoned(i,{timeZone:o});return c(r.Temporal.ZonedDateTime.compare(s,l)<=0?l.since(s,{largestUnit:`year`}):s.since(l,{largestUnit:`year`}))}exports.classifyExpiry=s,exports.timeDiff=l;
2
2
  //# sourceMappingURL=classify.cjs.map