@vielzeug/tempo 1.0.6 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -43
- package/dist/_convert.cjs +1 -1
- package/dist/_convert.cjs.map +1 -1
- package/dist/_convert.d.ts +9 -43
- package/dist/_convert.d.ts.map +1 -1
- package/dist/_convert.js +12 -10
- package/dist/_convert.js.map +1 -1
- package/dist/_floor.cjs +1 -1
- package/dist/_floor.cjs.map +1 -1
- package/dist/_floor.d.ts +5 -9
- package/dist/_floor.d.ts.map +1 -1
- package/dist/_floor.js +1 -5
- package/dist/_floor.js.map +1 -1
- package/dist/_tz.cjs +1 -1
- package/dist/_tz.cjs.map +1 -1
- package/dist/_tz.d.ts +4 -13
- package/dist/_tz.d.ts.map +1 -1
- package/dist/_tz.js +9 -20
- package/dist/_tz.js.map +1 -1
- package/dist/boundary.cjs +1 -1
- package/dist/boundary.cjs.map +1 -1
- package/dist/boundary.d.ts +1 -22
- package/dist/boundary.d.ts.map +1 -1
- package/dist/boundary.js +2 -3
- package/dist/boundary.js.map +1 -1
- package/dist/classify.cjs +1 -1
- package/dist/classify.cjs.map +1 -1
- package/dist/classify.d.ts +3 -45
- package/dist/classify.d.ts.map +1 -1
- package/dist/classify.js +33 -31
- package/dist/classify.js.map +1 -1
- package/dist/compare.cjs +1 -1
- package/dist/compare.cjs.map +1 -1
- package/dist/compare.d.ts +6 -70
- package/dist/compare.d.ts.map +1 -1
- package/dist/compare.js +38 -49
- package/dist/compare.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +21 -131
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +30 -73
- package/dist/core.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -4
- 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 +24 -18
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +10 -10
- package/dist/format.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/range.cjs +1 -1
- package/dist/range.cjs.map +1 -1
- package/dist/range.d.ts +3 -57
- package/dist/range.d.ts.map +1 -1
- package/dist/range.js +9 -20
- package/dist/range.js.map +1 -1
- package/dist/tempo.cjs +1 -1
- package/dist/tempo.cjs.map +1 -1
- package/dist/tempo.iife.js +1 -1
- package/dist/tempo.iife.js.map +1 -1
- package/dist/tempo.js +1 -1
- package/dist/tempo.js.map +1 -1
- package/dist/types.d.ts +35 -37
- package/dist/types.d.ts.map +1 -1
- package/package.json +23 -18
package/README.md
CHANGED
|
@@ -1,63 +1,37 @@
|
|
|
1
1
|
# @vielzeug/tempo
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Temporal utilities with explicit parsing and timezone rules.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<details>
|
|
8
|
-
<summary>Quick Reference</summary>
|
|
9
|
-
|
|
10
|
-
**Package:** `@vielzeug/tempo` · **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
|
-
|
|
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
|
-
|
|
39
|
-
|
|
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
|
-
|
|
46
|
-
|
|
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
|
-
|
|
49
|
-
console.log(formatInstant(reminder));
|
|
24
|
+
console.log(format(inTimeZone(reminder, 'America/New_York'), { locale: 'en-US', pattern: 'short' }));
|
|
50
25
|
```
|
|
51
26
|
|
|
52
|
-
|
|
27
|
+
## API Rules
|
|
53
28
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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 ©
|
|
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();
|
|
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
|
package/dist/_convert.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_convert.cjs","names":[],"sources":["../src/_convert.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\
|
|
1
|
+
{"version":3,"file":"_convert.cjs","names":[],"sources":["../src/_convert.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { validateTimeZone } from './_tz';\nimport { fail, TempoMissingTzError, TempoUnsupportedInputError } from './errors';\nimport type { AbsoluteTime, DisambiguationOptions, TimeInput, TimeZoneOptions, WallTime } from './types';\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":"8FAWA,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"}
|
package/dist/_convert.d.ts
CHANGED
|
@@ -1,47 +1,13 @@
|
|
|
1
1
|
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
-
import type {
|
|
3
|
-
type
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
package/dist/_convert.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_convert.d.ts","sourceRoot":"","sources":["../src/_convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"_convert.d.ts","sourceRoot":"","sources":["../src/_convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEzG,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 {
|
|
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
|
-
|
|
9
|
-
|
|
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 =
|
|
14
|
-
if (e instanceof i.ZonedDateTime) return e.withTimeZone(
|
|
15
|
-
if (e instanceof i.
|
|
16
|
-
if (e instanceof i.
|
|
17
|
-
if (e instanceof i.
|
|
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, {
|
|
23
|
+
return o(e, { timeZone: t });
|
|
22
24
|
}
|
|
23
25
|
//#endregion
|
|
24
|
-
export { s as
|
|
26
|
+
export { s as inTimeZone, a as toInstant, o as toZoned };
|
|
25
27
|
|
|
26
28
|
//# sourceMappingURL=_convert.js.map
|
package/dist/_convert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_convert.js","names":[],"sources":["../src/_convert.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\
|
|
1
|
+
{"version":3,"file":"_convert.js","names":[],"sources":["../src/_convert.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { validateTimeZone } from './_tz';\nimport { fail, TempoMissingTzError, TempoUnsupportedInputError } from './errors';\nimport type { AbsoluteTime, DisambiguationOptions, TimeInput, TimeZoneOptions, WallTime } from './types';\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":";;;;AAWA,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");
|
|
1
|
+
const e=require("./_convert.cjs");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
|
package/dist/_floor.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_floor.cjs","names":[],"sources":["../src/_floor.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\
|
|
1
|
+
{"version":3,"file":"_floor.cjs","names":[],"sources":["../src/_floor.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { toZoned } from './_convert';\nimport type { BoundaryUnit, Disambiguation, TimeInput, WeekStartDay } from './types';\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?: WeekStartDay },\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":"kCAIA,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
|
-
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
-
import type { BoundaryUnit,
|
|
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
|
-
*/
|
|
1
|
+
import type { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
import type { BoundaryUnit, Disambiguation, TimeInput, WeekStartDay } from './types';
|
|
7
3
|
export declare function floorToUnit(input: TimeInput, unit: BoundaryUnit, options: {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
weekStartsOn?:
|
|
4
|
+
disambiguation?: Disambiguation;
|
|
5
|
+
timeZone: string;
|
|
6
|
+
weekStartsOn?: WeekStartDay;
|
|
11
7
|
}): Temporal.Instant;
|
|
12
8
|
//# sourceMappingURL=_floor.d.ts.map
|
package/dist/_floor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_floor.d.ts","sourceRoot":"","sources":["../src/_floor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"_floor.d.ts","sourceRoot":"","sources":["../src/_floor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAmBrF,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,YAAY,CAAA;CAAE,GAC1F,QAAQ,CAAC,OAAO,CAUlB"}
|
package/dist/_floor.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { toZoned as e } from "./_convert.js";
|
|
2
|
-
import "@js-temporal/polyfill";
|
|
3
2
|
//#region src/_floor.ts
|
|
4
3
|
var t = {
|
|
5
4
|
hour: 0,
|
|
@@ -34,10 +33,7 @@ var t = {
|
|
|
34
33
|
}
|
|
35
34
|
};
|
|
36
35
|
function r(r, i, a) {
|
|
37
|
-
let o = e(r,
|
|
38
|
-
prefer: a.prefer,
|
|
39
|
-
tz: a.tz
|
|
40
|
-
});
|
|
36
|
+
let o = e(r, a);
|
|
41
37
|
if (i === "week") {
|
|
42
38
|
let e = (o.dayOfWeek - (a.weekStartsOn ?? 1) + 7) % 7;
|
|
43
39
|
return o.subtract({ days: e }).with(t).toInstant();
|
package/dist/_floor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_floor.js","names":[],"sources":["../src/_floor.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\
|
|
1
|
+
{"version":3,"file":"_floor.js","names":[],"sources":["../src/_floor.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { toZoned } from './_convert';\nimport type { BoundaryUnit, Disambiguation, TimeInput, WeekStartDay } from './types';\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?: WeekStartDay },\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":";;AAIA,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
|
|
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;
|
|
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';\
|
|
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,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,IAAa,EAAiB,IAAI,IAAkB,CAAC,MAAO,QAAS,OAAQ,MAAM,CAAC"}
|
package/dist/_tz.d.ts
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
tz?: string;
|
|
6
|
-
}): string;
|
|
7
|
-
export declare function inferSharedTimeZone(inputs: TimeInput[], options: {
|
|
8
|
-
tz?: string;
|
|
9
|
-
}): string;
|
|
10
|
-
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. */
|
|
1
|
+
import type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';
|
|
2
|
+
export declare function validateTimeZone(timeZone: string): string;
|
|
3
|
+
export declare function inferTimeZone(input: TimeInput, options: TimeZoneOptions): string;
|
|
4
|
+
export declare function inferSharedTimeZone(inputs: readonly TimeInput[], options: TimeZoneOptions): string;
|
|
12
5
|
export declare const CALENDAR_UNITS: Set<CalendarUnit>;
|
|
13
|
-
/** Approximate millisecond constants for threshold arithmetic. */
|
|
14
|
-
export declare const MS_PER_MONTH: number;
|
|
15
6
|
//# 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":"
|
|
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,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,eAAO,MAAM,cAAc,mBAA0D,CAAC"}
|
package/dist/_tz.js
CHANGED
|
@@ -5,38 +5,27 @@ 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
|
|
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.
|
|
14
|
-
return o || n("This operation requires a
|
|
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.
|
|
17
|
+
if (a.timeZone) return i(a.timeZone);
|
|
18
18
|
let o;
|
|
19
|
-
for (let t of e)
|
|
20
|
-
|
|
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;
|
|
29
|
-
}
|
|
30
|
-
function s(e, t) {
|
|
31
|
-
return r.Instant.compare(e, t) <= 0 ? [e, t] : [t, e];
|
|
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;
|
|
32
21
|
}
|
|
33
|
-
var
|
|
22
|
+
var s = /* @__PURE__ */ new Set([
|
|
34
23
|
"day",
|
|
35
24
|
"month",
|
|
36
25
|
"week",
|
|
37
26
|
"year"
|
|
38
|
-
])
|
|
27
|
+
]);
|
|
39
28
|
//#endregion
|
|
40
|
-
export {
|
|
29
|
+
export { s as CALENDAR_UNITS, o as inferSharedTimeZone, a as inferTimeZone, i as validateTimeZone };
|
|
41
30
|
|
|
42
31
|
//# 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';\
|
|
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,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,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");
|
|
1
|
+
const e=require("./_tz.cjs"),t=require("./_floor.cjs");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
|
package/dist/boundary.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundary.cjs","names":[],"sources":["../src/boundary.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\
|
|
1
|
+
{"version":3,"file":"boundary.cjs","names":[],"sources":["../src/boundary.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { floorToUnit } from './_floor';\nimport { inferTimeZone } from './_tz';\nimport type { BoundaryOptions, BoundaryUnit, TimeInput } from './types';\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":"uDAKA,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"}
|
package/dist/boundary.d.ts
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
import { Temporal } from '@js-temporal/polyfill';
|
|
1
|
+
import type { 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
|
package/dist/boundary.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../src/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../src/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGtD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAWxE,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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { inferTimeZone as e } from "./_tz.js";
|
|
2
2
|
import { floorToUnit as t } from "./_floor.js";
|
|
3
|
-
import "@js-temporal/polyfill";
|
|
4
3
|
//#region src/boundary.ts
|
|
5
4
|
var n = {
|
|
6
5
|
day: { days: 1 },
|
|
@@ -13,14 +12,14 @@ var n = {
|
|
|
13
12
|
function r(n, r, i = {}) {
|
|
14
13
|
let a = e(n, i);
|
|
15
14
|
return t(n, r, {
|
|
16
|
-
|
|
15
|
+
timeZone: a,
|
|
17
16
|
weekStartsOn: i.weekStartsOn
|
|
18
17
|
}).toZonedDateTimeISO(a);
|
|
19
18
|
}
|
|
20
19
|
function i(r, i, a = {}) {
|
|
21
20
|
let o = e(r, a);
|
|
22
21
|
return t(r, i, {
|
|
23
|
-
|
|
22
|
+
timeZone: o,
|
|
24
23
|
weekStartsOn: a.weekStartsOn
|
|
25
24
|
}).toZonedDateTimeISO(o).add(n[i]).subtract({ nanoseconds: 1 });
|
|
26
25
|
}
|
package/dist/boundary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundary.js","names":[],"sources":["../src/boundary.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\
|
|
1
|
+
{"version":3,"file":"boundary.js","names":[],"sources":["../src/boundary.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { floorToUnit } from './_floor';\nimport { inferTimeZone } from './_tz';\nimport type { BoundaryOptions, BoundaryUnit, TimeInput } from './types';\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":";;;AAKA,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("./
|
|
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
|