temporal-fmt 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/calendarUtils.cjs +4 -259
- package/dist/calendarUtils.cjs.map +1 -1
- package/dist/calendarUtils.js +1 -33
- package/dist/chunk-2JHEV7ZF.js +7 -0
- package/dist/chunk-2JHEV7ZF.js.map +1 -0
- package/dist/chunk-3MZLTVP3.js +2 -0
- package/dist/{chunk-MXXYIMFJ.js.map → chunk-3MZLTVP3.js.map} +1 -1
- package/dist/chunk-4JWGUR4O.js +11 -0
- package/dist/{chunk-AXQLUIDY.js.map → chunk-4JWGUR4O.js.map} +1 -1
- package/dist/chunk-5U5WJ465.js +36 -0
- package/dist/chunk-5U5WJ465.js.map +1 -0
- package/dist/chunk-C5YESWFT.js +2 -0
- package/dist/chunk-C5YESWFT.js.map +1 -0
- package/dist/chunk-C6ZZ62ET.js +2 -0
- package/dist/{chunk-YS52LOMJ.js.map → chunk-C6ZZ62ET.js.map} +1 -1
- package/dist/chunk-EHLRZULM.js +5 -0
- package/dist/{chunk-4ZBGVYLR.js.map → chunk-EHLRZULM.js.map} +1 -1
- package/dist/chunk-F4RGUDA3.js +2 -0
- package/dist/chunk-F4RGUDA3.js.map +1 -0
- package/dist/chunk-J2AQNXF2.js +2 -0
- package/dist/{chunk-GRJQHQLW.js.map → chunk-J2AQNXF2.js.map} +1 -1
- package/dist/chunk-NBXF7V5B.js +2 -0
- package/dist/chunk-NBXF7V5B.js.map +1 -0
- package/dist/chunk-R52YOKI3.js +7 -0
- package/dist/{chunk-M33NSC4E.js.map → chunk-R52YOKI3.js.map} +1 -1
- package/dist/chunk-UJR6DHXY.js +2 -0
- package/dist/chunk-UJR6DHXY.js.map +1 -0
- package/dist/chunk-VQXUMFB2.js +21 -0
- package/dist/{chunk-VHSZL3P3.js.map → chunk-VQXUMFB2.js.map} +1 -1
- package/dist/chunk-XH46JNPK.js +2 -0
- package/dist/chunk-XH46JNPK.js.map +1 -0
- package/dist/chunk-YB6YAG7E.js +35 -0
- package/dist/chunk-YB6YAG7E.js.map +1 -0
- package/dist/chunk-ZGMTY52O.js +2 -0
- package/dist/chunk-ZGMTY52O.js.map +1 -0
- package/dist/duration.cjs +9 -624
- package/dist/duration.cjs.map +1 -1
- package/dist/duration.js +1 -29
- package/dist/format.cjs +18 -769
- package/dist/format.cjs.map +1 -1
- package/dist/format.js +1 -20
- package/dist/formatDuration.d.cts +6 -0
- package/dist/formatDuration.d.ts +6 -0
- package/dist/index.cjs +146 -6672
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -3004
- package/dist/index.js.map +1 -1
- package/dist/interval.cjs +18 -952
- package/dist/interval.cjs.map +1 -1
- package/dist/interval.js +1 -41
- package/dist/localeRegistry.cjs +15 -328
- package/dist/localeRegistry.cjs.map +1 -1
- package/dist/localeRegistry.js +1 -11
- package/dist/localeVocab.d.cts +3 -0
- package/dist/localeVocab.d.ts +3 -0
- package/dist/parse.cjs +53 -1637
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.js +1 -20
- package/dist/parsePattern.d.cts +1 -0
- package/dist/parsePattern.d.ts +1 -0
- package/dist/pattern.d.cts +1 -0
- package/dist/pattern.d.ts +1 -0
- package/dist/recurrence.cjs +20 -450
- package/dist/recurrence.cjs.map +1 -1
- package/dist/recurrence.js +1 -20
- package/dist/relativeTime.cjs +24 -177
- package/dist/relativeTime.cjs.map +1 -1
- package/dist/relativeTime.js +1 -14
- package/dist/rounding.d.cts +1 -0
- package/dist/rounding.d.ts +1 -0
- package/dist/serialization.d.cts +1 -1
- package/dist/serialization.d.ts +1 -1
- package/dist/timezone.cjs +20 -387
- package/dist/timezone.cjs.map +1 -1
- package/dist/timezone.js +1 -26
- package/dist/typeGuards.d.cts +9 -9
- package/dist/typeGuards.d.ts +9 -9
- package/package.json +4 -2
- package/dist/chunk-4ZBGVYLR.js +0 -182
- package/dist/chunk-AXQLUIDY.js +0 -183
- package/dist/chunk-CKVHXFX7.js +0 -902
- package/dist/chunk-CKVHXFX7.js.map +0 -1
- package/dist/chunk-CSUIKL73.js +0 -215
- package/dist/chunk-CSUIKL73.js.map +0 -1
- package/dist/chunk-EDUFSRWJ.js +0 -9
- package/dist/chunk-EDUFSRWJ.js.map +0 -1
- package/dist/chunk-FQA4XJME.js +0 -57
- package/dist/chunk-FQA4XJME.js.map +0 -1
- package/dist/chunk-FTMLZ4EN.js +0 -196
- package/dist/chunk-FTMLZ4EN.js.map +0 -1
- package/dist/chunk-GRJQHQLW.js +0 -170
- package/dist/chunk-JCIMP43G.js +0 -602
- package/dist/chunk-JCIMP43G.js.map +0 -1
- package/dist/chunk-KDYK72Z2.js +0 -75
- package/dist/chunk-KDYK72Z2.js.map +0 -1
- package/dist/chunk-M33NSC4E.js +0 -169
- package/dist/chunk-MXXYIMFJ.js +0 -29
- package/dist/chunk-NFKQ3EXC.js +0 -188
- package/dist/chunk-NFKQ3EXC.js.map +0 -1
- package/dist/chunk-O6GVMBLW.js +0 -403
- package/dist/chunk-O6GVMBLW.js.map +0 -1
- package/dist/chunk-VHSZL3P3.js +0 -242
- package/dist/chunk-VSUCBUTC.js +0 -295
- package/dist/chunk-VSUCBUTC.js.map +0 -1
- package/dist/chunk-YS52LOMJ.js +0 -51
package/dist/parse.js
CHANGED
|
@@ -1,21 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
compileParser,
|
|
3
|
-
parse,
|
|
4
|
-
parseToParts,
|
|
5
|
-
safeParse,
|
|
6
|
-
tryParse
|
|
7
|
-
} from "./chunk-CKVHXFX7.js";
|
|
8
|
-
import "./chunk-M33NSC4E.js";
|
|
9
|
-
import "./chunk-VSUCBUTC.js";
|
|
10
|
-
import "./chunk-EDUFSRWJ.js";
|
|
11
|
-
import "./chunk-MXXYIMFJ.js";
|
|
12
|
-
import "./chunk-O6GVMBLW.js";
|
|
13
|
-
import "./chunk-YS52LOMJ.js";
|
|
14
|
-
export {
|
|
15
|
-
compileParser,
|
|
16
|
-
parse,
|
|
17
|
-
parseToParts,
|
|
18
|
-
safeParse,
|
|
19
|
-
tryParse
|
|
20
|
-
};
|
|
1
|
+
import{c as a,d as b,e as c,f as d,g as e}from"./chunk-YB6YAG7E.js";import"./chunk-R52YOKI3.js";import"./chunk-C5YESWFT.js";import"./chunk-3MZLTVP3.js";import"./chunk-5U5WJ465.js";import"./chunk-C6ZZ62ET.js";export{e as compileParser,a as parse,d as parseToParts,b as safeParse,c as tryParse};
|
|
21
2
|
//# sourceMappingURL=parse.js.map
|
package/dist/parsePattern.d.cts
CHANGED
package/dist/parsePattern.d.ts
CHANGED
package/dist/pattern.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare function isValidTimeZone(raw: string): boolean;
|
|
2
2
|
export declare const FORMAT_ONLY_TOKENS: Set<string>;
|
|
3
|
+
export declare const DIGIT_LEADING_TOKENS: Set<string>;
|
|
3
4
|
export declare function tokenFragment(token: string, locale: string, nextToken?: string): string;
|
|
4
5
|
export declare const UNPADDED_NUMERIC_TOKENS: Set<string>;
|
|
5
6
|
export declare const UNPADDED_NUMERIC_RANGES: Record<string, Array<{
|
package/dist/pattern.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare function isValidTimeZone(raw: string): boolean;
|
|
2
2
|
export declare const FORMAT_ONLY_TOKENS: Set<string>;
|
|
3
|
+
export declare const DIGIT_LEADING_TOKENS: Set<string>;
|
|
3
4
|
export declare function tokenFragment(token: string, locale: string, nextToken?: string): string;
|
|
4
5
|
export declare const UNPADDED_NUMERIC_TOKENS: Set<string>;
|
|
5
6
|
export declare const UNPADDED_NUMERIC_RANGES: Record<string, Array<{
|
package/dist/recurrence.cjs
CHANGED
|
@@ -1,451 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var recurrence_exports = {};
|
|
22
|
-
__export(recurrence_exports, {
|
|
23
|
-
between: () => between,
|
|
24
|
-
formatRRule: () => formatRRule,
|
|
25
|
-
parseRRule: () => parseRRule,
|
|
26
|
-
recurrence: () => recurrence,
|
|
27
|
-
skip: () => skip,
|
|
28
|
-
take: () => take
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(recurrence_exports);
|
|
31
|
-
|
|
32
|
-
// src/isoWeek.ts
|
|
33
|
-
function isGregorianLeapYear(year) {
|
|
34
|
-
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// src/calendarUtils.ts
|
|
38
|
-
function requireFields(view, fields) {
|
|
39
|
-
for (const f of fields) {
|
|
40
|
-
if (typeof view[f] !== "number") {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`temporal-fmt: calendar helper requires "${String(f)}", which this value doesn't have. Pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function daysInMonth(view) {
|
|
48
|
-
requireFields(view, ["year", "month"]);
|
|
49
|
-
const { year, month } = view;
|
|
50
|
-
const LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
51
|
-
if (month === 2 && isGregorianLeapYear(year)) return 29;
|
|
52
|
-
return LENGTHS[month - 1];
|
|
53
|
-
}
|
|
54
|
-
function asDateFieldView(value) {
|
|
55
|
-
if (typeof value !== "object" || value === null) {
|
|
56
|
-
throw new Error(`temporal-fmt: expected a date-carrying Temporal value, got ${String(value)}.`);
|
|
57
|
-
}
|
|
58
|
-
const v = value;
|
|
59
|
-
const out = {};
|
|
60
|
-
if (typeof v.year === "number") out.year = v.year;
|
|
61
|
-
if (typeof v.month === "number") out.month = v.month;
|
|
62
|
-
if (typeof v.day === "number") out.day = v.day;
|
|
63
|
-
if (typeof v.hour === "number") out.hour = v.hour;
|
|
64
|
-
if (typeof v.minute === "number") out.minute = v.minute;
|
|
65
|
-
if (typeof v.second === "number") out.second = v.second;
|
|
66
|
-
if (typeof v.millisecond === "number") out.millisecond = v.millisecond;
|
|
67
|
-
if (typeof v.dayOfWeek === "number") out.dayOfWeek = v.dayOfWeek;
|
|
68
|
-
if (typeof v.calendarId === "string") out.calendarId = v.calendarId;
|
|
69
|
-
if (out.year === void 0 || out.month === void 0 || out.day === void 0) {
|
|
70
|
-
throw new Error(
|
|
71
|
-
`temporal-fmt: value is missing year/month/day fields \u2014 pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
return out;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// src/arithmetic.ts
|
|
78
|
-
function asDateTime(value) {
|
|
79
|
-
return asDateFieldView(value);
|
|
80
|
-
}
|
|
81
|
-
function recomputeDayOfWeek(view) {
|
|
82
|
-
if (typeof view.dayOfWeek !== "number") return;
|
|
83
|
-
/* c8 ignore start @preserve -- unreachable: every call site (add()'s
|
|
84
|
-
'years'/'months' cases, shiftDays()) passes a `result` whose
|
|
85
|
-
year/month/day were just explicitly set, and the value originally
|
|
86
|
-
came from asDateTime()/asDateFieldView(), which throws unless
|
|
87
|
-
year/month/day are all present as numbers. So by the time this guard
|
|
88
|
-
runs, all three are guaranteed valid. Kept in case a future caller
|
|
89
|
-
constructs a DateTimeFieldView bypassing that validation. */
|
|
90
|
-
if (typeof view.year !== "number" || typeof view.month !== "number" || typeof view.day !== "number") return;
|
|
91
|
-
/* c8 ignore stop @preserve */
|
|
92
|
-
const jsDow = new Date(Date.UTC(view.year, view.month - 1, view.day)).getUTCDay();
|
|
93
|
-
view.dayOfWeek = jsDow === 0 ? 7 : jsDow;
|
|
94
|
-
}
|
|
95
|
-
function add(value, amount, unit) {
|
|
96
|
-
const v = asDateTime(value);
|
|
97
|
-
let result = { ...v };
|
|
98
|
-
switch (unit) {
|
|
99
|
-
case "years": {
|
|
100
|
-
/* c8 ignore start @preserve -- the `?? 0` fallback is unreachable:
|
|
101
|
-
asDateTime()/asDateFieldView() (called at the top of add()) throws
|
|
102
|
-
unless year is present as a number, so result.year is never
|
|
103
|
-
undefined here. Kept as a guard against a future change that
|
|
104
|
-
relaxes that validation. */
|
|
105
|
-
result.year = (result.year ?? 0) + amount;
|
|
106
|
-
/* c8 ignore stop @preserve */
|
|
107
|
-
const maxDay = daysInMonth({ year: result.year, month: result.month });
|
|
108
|
-
if (result.day > maxDay) result.day = maxDay;
|
|
109
|
-
recomputeDayOfWeek(result);
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
case "months": {
|
|
113
|
-
/* c8 ignore start @preserve -- both `??` fallbacks are unreachable
|
|
114
|
-
for the same reason as the 'years' case above: asDateFieldView()
|
|
115
|
-
guarantees year and month are present numbers before add() ever
|
|
116
|
-
reaches here. */
|
|
117
|
-
const total = (result.year ?? 0) * 12 + (result.month ?? 1) - 1 + amount;
|
|
118
|
-
/* c8 ignore stop @preserve */
|
|
119
|
-
result.year = Math.floor(total / 12);
|
|
120
|
-
result.month = total % 12 + 1;
|
|
121
|
-
if (result.month < 1) {
|
|
122
|
-
result.month += 12;
|
|
123
|
-
result.year -= 1;
|
|
124
|
-
}
|
|
125
|
-
/* c8 ignore start @preserve -- unreachable: (total % 12) + 1 can never
|
|
126
|
-
exceed 12 for any integer total in JS (its range is [-10, 12] since
|
|
127
|
-
JS's % can return a negative remainder but never one with
|
|
128
|
-
magnitude >= 12, so adding 1 tops out at 12). Only the < 1 branch
|
|
129
|
-
above is reachable; this was written symmetrically with it but the
|
|
130
|
-
overflow direction it guards against can't occur. Kept rather than
|
|
131
|
-
removed since it costs nothing and documents the intent. */
|
|
132
|
-
if (result.month > 12) {
|
|
133
|
-
result.month -= 12;
|
|
134
|
-
result.year += 1;
|
|
135
|
-
}
|
|
136
|
-
/* c8 ignore stop @preserve */
|
|
137
|
-
const maxDay = daysInMonth({ year: result.year, month: result.month });
|
|
138
|
-
if (result.day > maxDay) result.day = maxDay;
|
|
139
|
-
recomputeDayOfWeek(result);
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
case "weeks":
|
|
143
|
-
result = shiftDays(result, amount * 7);
|
|
144
|
-
break;
|
|
145
|
-
case "days":
|
|
146
|
-
result = shiftDays(result, amount);
|
|
147
|
-
break;
|
|
148
|
-
case "hours":
|
|
149
|
-
result = shiftTime(result, amount * 36e5);
|
|
150
|
-
break;
|
|
151
|
-
case "minutes":
|
|
152
|
-
result = shiftTime(result, amount * 6e4);
|
|
153
|
-
break;
|
|
154
|
-
case "seconds":
|
|
155
|
-
result = shiftTime(result, amount * 1e3);
|
|
156
|
-
break;
|
|
157
|
-
case "milliseconds":
|
|
158
|
-
result = shiftTime(result, amount);
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
return result;
|
|
162
|
-
}
|
|
163
|
-
function shiftDays(v, days) {
|
|
164
|
-
const y = v.year, m = v.month, d = v.day;
|
|
165
|
-
const y2 = m <= 2 ? y - 1 : y;
|
|
166
|
-
const era = Math.floor((y2 >= 0 ? y2 : y2 - 399) / 400);
|
|
167
|
-
const yoe = y2 - era * 400;
|
|
168
|
-
const m2 = m > 2 ? m - 3 : m + 9;
|
|
169
|
-
const doy = Math.floor((153 * m2 + 2) / 5) + d - 1;
|
|
170
|
-
const doe = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + doy;
|
|
171
|
-
const totalDays = era * 146097 + doe - 719468 + days;
|
|
172
|
-
const z = totalDays + 719468;
|
|
173
|
-
const era2 = Math.floor((z >= 0 ? z : z - 146096) / 146097);
|
|
174
|
-
const doe2 = z - era2 * 146097;
|
|
175
|
-
const yoe2 = Math.floor((doe2 - Math.floor(doe2 / 1460) + Math.floor(doe2 / 36524) - Math.floor(doe2 / 146096)) / 365);
|
|
176
|
-
const y2out = yoe2 + era2 * 400;
|
|
177
|
-
const doy2 = doe2 - (365 * yoe2 + Math.floor(yoe2 / 4) - Math.floor(yoe2 / 100));
|
|
178
|
-
const mp = Math.floor((5 * doy2 + 2) / 153);
|
|
179
|
-
const d2 = doy2 - Math.floor((153 * mp + 2) / 5) + 1;
|
|
180
|
-
const m2out = mp < 10 ? mp + 3 : mp - 9;
|
|
181
|
-
const yOut = m2out <= 2 ? y2out + 1 : y2out;
|
|
182
|
-
const result = { ...v, year: yOut, month: m2out, day: d2 };
|
|
183
|
-
recomputeDayOfWeek(result);
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
186
|
-
function shiftTime(v, msDelta) {
|
|
187
|
-
const MS_PER_DAY = 864e5;
|
|
188
|
-
const MS_PER_HOUR = 36e5;
|
|
189
|
-
const MS_PER_MINUTE = 6e4;
|
|
190
|
-
const MS_PER_SECOND = 1e3;
|
|
191
|
-
const totalMs = (v.hour ?? 0) * MS_PER_HOUR + (v.minute ?? 0) * MS_PER_MINUTE + (v.second ?? 0) * MS_PER_SECOND + (v.millisecond ?? 0) + msDelta;
|
|
192
|
-
const dayOverflow = Math.floor(totalMs / MS_PER_DAY);
|
|
193
|
-
let withinDay = totalMs % MS_PER_DAY;
|
|
194
|
-
if (withinDay < 0) {
|
|
195
|
-
withinDay += MS_PER_DAY;
|
|
196
|
-
}
|
|
197
|
-
const hour = Math.floor(withinDay / MS_PER_HOUR);
|
|
198
|
-
const minute = Math.floor(withinDay % MS_PER_HOUR / MS_PER_MINUTE);
|
|
199
|
-
const second = Math.floor(withinDay % MS_PER_MINUTE / MS_PER_SECOND);
|
|
200
|
-
const millisecond = withinDay % MS_PER_SECOND;
|
|
201
|
-
const result = { ...v, hour, minute, second, millisecond };
|
|
202
|
-
if (dayOverflow !== 0) {
|
|
203
|
-
return shiftDays(result, dayOverflow);
|
|
204
|
-
}
|
|
205
|
-
return result;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// src/comparison.ts
|
|
209
|
-
function toComparableMs(view) {
|
|
210
|
-
const REFERENCE_YEAR = 2e3;
|
|
211
|
-
const DAYS_PER_YEAR_AVG = 365.2425;
|
|
212
|
-
const MS_PER_DAY = 864e5;
|
|
213
|
-
const MS_PER_HOUR = 36e5;
|
|
214
|
-
const MS_PER_MINUTE = 6e4;
|
|
215
|
-
const MS_PER_SECOND = 1e3;
|
|
216
|
-
const year = view.year;
|
|
217
|
-
const yearsFromRef = year - REFERENCE_YEAR;
|
|
218
|
-
const yearMs = yearsFromRef * DAYS_PER_YEAR_AVG * MS_PER_DAY;
|
|
219
|
-
const CUMULATIVE_DAYS = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
|
|
220
|
-
let doy = CUMULATIVE_DAYS[view.month - 1] + view.day - 1;
|
|
221
|
-
const isLeap = year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
222
|
-
if (view.month > 2 && isLeap) doy += 1;
|
|
223
|
-
const dayMs = doy * MS_PER_DAY;
|
|
224
|
-
const hourMs = (view.hour ?? 0) * MS_PER_HOUR;
|
|
225
|
-
const minuteMs = (view.minute ?? 0) * MS_PER_MINUTE;
|
|
226
|
-
const secondMs = (view.second ?? 0) * MS_PER_SECOND;
|
|
227
|
-
const msMs = view.millisecond ?? 0;
|
|
228
|
-
return yearMs + dayMs + hourMs + minuteMs + secondMs + msMs;
|
|
229
|
-
}
|
|
230
|
-
function asDateTimeFieldView(value) {
|
|
231
|
-
const v = asDateFieldView(value);
|
|
232
|
-
return v;
|
|
233
|
-
}
|
|
234
|
-
function compare(a, b) {
|
|
235
|
-
const av = asDateTimeFieldView(a);
|
|
236
|
-
const bv = asDateTimeFieldView(b);
|
|
237
|
-
const am = toComparableMs(av);
|
|
238
|
-
const bm = toComparableMs(bv);
|
|
239
|
-
if (am < bm) return -1;
|
|
240
|
-
if (am > bm) return 1;
|
|
241
|
-
return 0;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// src/recurrence.ts
|
|
245
|
-
function recurrence(start, rule) {
|
|
246
|
-
let current = start;
|
|
247
|
-
let count = 0;
|
|
248
|
-
const history = [];
|
|
249
|
-
const MAX_HISTORY = 1e4;
|
|
250
|
-
let atEnd = false;
|
|
251
|
-
let atStart = true;
|
|
252
|
-
function matches(value) {
|
|
253
|
-
const v = value;
|
|
254
|
-
if (rule.byWeekday && rule.byWeekday.length > 0) {
|
|
255
|
-
if (!rule.byWeekday.includes(v.dayOfWeek ?? 0)) return false;
|
|
256
|
-
}
|
|
257
|
-
if (rule.byMonthDay && rule.byMonthDay.length > 0) {
|
|
258
|
-
if (!rule.byMonthDay.includes(v.day ?? 0)) return false;
|
|
259
|
-
}
|
|
260
|
-
if (rule.byMonth && rule.byMonth.length > 0) {
|
|
261
|
-
if (!rule.byMonth.includes(v.month ?? 0)) return false;
|
|
262
|
-
}
|
|
263
|
-
if (rule.exDates && rule.exDates.some((d) => compare(d, value) === 0)) return false;
|
|
264
|
-
return true;
|
|
265
|
-
}
|
|
266
|
-
function advance(value, steps) {
|
|
267
|
-
const unit = rule.frequency === "secondly" ? "seconds" : rule.frequency === "minutely" ? "minutes" : rule.frequency === "hourly" ? "hours" : rule.frequency === "daily" ? "days" : rule.frequency === "weekly" ? "weeks" : rule.frequency === "monthly" ? "months" : "years";
|
|
268
|
-
return add(value, steps * rule.interval, unit);
|
|
269
|
-
}
|
|
270
|
-
function recordHistory(value) {
|
|
271
|
-
history.push(value);
|
|
272
|
-
if (history.length > MAX_HISTORY) history.shift();
|
|
273
|
-
}
|
|
274
|
-
function nextMatch(value) {
|
|
275
|
-
let candidate = value;
|
|
276
|
-
let safetyCounter = 0;
|
|
277
|
-
do {
|
|
278
|
-
candidate = advance(candidate, 1);
|
|
279
|
-
safetyCounter++;
|
|
280
|
-
if (safetyCounter > 1e3) {
|
|
281
|
-
atEnd = true;
|
|
282
|
-
return { value: candidate, found: false };
|
|
283
|
-
}
|
|
284
|
-
if (rule.until && compare(candidate, rule.until) > 0) {
|
|
285
|
-
atEnd = true;
|
|
286
|
-
return { value: candidate, found: false };
|
|
287
|
-
}
|
|
288
|
-
} while (!matches(candidate));
|
|
289
|
-
return { value: candidate, found: true };
|
|
290
|
-
}
|
|
291
|
-
return {
|
|
292
|
-
next() {
|
|
293
|
-
if (atEnd) return { value: void 0, done: true };
|
|
294
|
-
if (atStart) {
|
|
295
|
-
atStart = false;
|
|
296
|
-
if (matches(current)) {
|
|
297
|
-
count++;
|
|
298
|
-
if (rule.count !== void 0 && count >= rule.count) atEnd = true;
|
|
299
|
-
if (rule.until && compare(current, rule.until) > 0) {
|
|
300
|
-
atEnd = true;
|
|
301
|
-
return { value: void 0, done: true };
|
|
302
|
-
}
|
|
303
|
-
recordHistory(current);
|
|
304
|
-
return { value: current, done: false };
|
|
305
|
-
}
|
|
306
|
-
const advanced2 = nextMatch(current);
|
|
307
|
-
if (!advanced2.found) return { value: void 0, done: true };
|
|
308
|
-
current = advanced2.value;
|
|
309
|
-
count++;
|
|
310
|
-
if (rule.count !== void 0 && count >= rule.count) atEnd = true;
|
|
311
|
-
recordHistory(current);
|
|
312
|
-
return { value: current, done: false };
|
|
313
|
-
}
|
|
314
|
-
const advanced = nextMatch(current);
|
|
315
|
-
if (!advanced.found) return { value: void 0, done: true };
|
|
316
|
-
current = advanced.value;
|
|
317
|
-
count++;
|
|
318
|
-
if (rule.count !== void 0 && count >= rule.count) atEnd = true;
|
|
319
|
-
recordHistory(current);
|
|
320
|
-
return { value: current, done: false };
|
|
321
|
-
},
|
|
322
|
-
previous() {
|
|
323
|
-
if (history.length === 0) return { value: void 0, done: true };
|
|
324
|
-
const v = history.pop();
|
|
325
|
-
return { value: v, done: false };
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
function take(iter, n) {
|
|
330
|
-
const result = [];
|
|
331
|
-
for (let i = 0; i < n; i++) {
|
|
332
|
-
const r = iter.next();
|
|
333
|
-
if (r.done) break;
|
|
334
|
-
result.push(r.value);
|
|
335
|
-
}
|
|
336
|
-
return result;
|
|
337
|
-
}
|
|
338
|
-
function skip(iter, n) {
|
|
339
|
-
for (let i = 0; i < n; i++) {
|
|
340
|
-
const r = iter.next();
|
|
341
|
-
if (r.done) break;
|
|
342
|
-
}
|
|
343
|
-
return take(iter, Number.MAX_SAFE_INTEGER);
|
|
344
|
-
}
|
|
345
|
-
function between(start, rule, rangeStart, rangeEnd) {
|
|
346
|
-
const iter = recurrence(start, rule);
|
|
347
|
-
const result = [];
|
|
348
|
-
while (true) {
|
|
349
|
-
const r = iter.next();
|
|
350
|
-
if (r.done) break;
|
|
351
|
-
if (compare(r.value, rangeEnd) >= 0) break;
|
|
352
|
-
if (compare(r.value, rangeStart) >= 0) result.push(r.value);
|
|
353
|
-
}
|
|
354
|
-
return result;
|
|
355
|
-
}
|
|
356
|
-
function parseRRule(input) {
|
|
357
|
-
const parts = input.trim().toUpperCase().replace(/^RRULE:/, "").split(";");
|
|
358
|
-
const rule = { frequency: "daily", interval: 1 };
|
|
359
|
-
const frequencies = /* @__PURE__ */ new Set([
|
|
360
|
-
"SECONDLY",
|
|
361
|
-
"MINUTELY",
|
|
362
|
-
"HOURLY",
|
|
363
|
-
"DAILY",
|
|
364
|
-
"WEEKLY",
|
|
365
|
-
"MONTHLY",
|
|
366
|
-
"YEARLY"
|
|
367
|
-
]);
|
|
368
|
-
for (const part of parts) {
|
|
369
|
-
if (!part) continue;
|
|
370
|
-
const eq = part.indexOf("=");
|
|
371
|
-
if (eq < 0) continue;
|
|
372
|
-
const key = part.slice(0, eq);
|
|
373
|
-
const value = part.slice(eq + 1);
|
|
374
|
-
switch (key) {
|
|
375
|
-
case "FREQ":
|
|
376
|
-
if (!frequencies.has(value)) {
|
|
377
|
-
throw new RangeError(`temporal-fmt: unsupported RRULE frequency "${value}".`);
|
|
378
|
-
}
|
|
379
|
-
rule.frequency = value.toLowerCase();
|
|
380
|
-
break;
|
|
381
|
-
case "INTERVAL": {
|
|
382
|
-
const interval = Number(value);
|
|
383
|
-
if (!Number.isSafeInteger(interval) || interval < 1) {
|
|
384
|
-
throw new RangeError(`temporal-fmt: RRULE INTERVAL must be a positive safe integer (got "${value}").`);
|
|
385
|
-
}
|
|
386
|
-
rule.interval = interval;
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
case "COUNT": {
|
|
390
|
-
const count = Number(value);
|
|
391
|
-
if (!Number.isSafeInteger(count) || count < 1) {
|
|
392
|
-
throw new RangeError(`temporal-fmt: RRULE COUNT must be a positive safe integer (got "${value}").`);
|
|
393
|
-
}
|
|
394
|
-
rule.count = count;
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
397
|
-
case "UNTIL":
|
|
398
|
-
rule.until = value;
|
|
399
|
-
break;
|
|
400
|
-
case "BYDAY":
|
|
401
|
-
rule.byWeekday = value.split(",").map((d) => {
|
|
402
|
-
const m = d.match(/^([+-]?\d)?([A-Z]{2})$/);
|
|
403
|
-
if (!m) return 0;
|
|
404
|
-
const wd = m[2];
|
|
405
|
-
const map = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 7 };
|
|
406
|
-
return map[wd] ?? 0;
|
|
407
|
-
});
|
|
408
|
-
break;
|
|
409
|
-
case "BYMONTHDAY": {
|
|
410
|
-
const values = value.split(",").map(Number);
|
|
411
|
-
if (values.some((day) => !Number.isInteger(day) || day === 0 || day < -31 || day > 31)) {
|
|
412
|
-
throw new RangeError(`temporal-fmt: RRULE BYMONTHDAY contains an out-of-range value.`);
|
|
413
|
-
}
|
|
414
|
-
rule.byMonthDay = values;
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
case "BYMONTH": {
|
|
418
|
-
const values = value.split(",").map(Number);
|
|
419
|
-
if (values.some((month) => !Number.isInteger(month) || month < 1 || month > 12)) {
|
|
420
|
-
throw new RangeError(`temporal-fmt: RRULE BYMONTH contains an out-of-range value.`);
|
|
421
|
-
}
|
|
422
|
-
rule.byMonth = values;
|
|
423
|
-
break;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
return rule;
|
|
428
|
-
}
|
|
429
|
-
function formatRRule(rule) {
|
|
430
|
-
const parts = [`FREQ=${rule.frequency.toUpperCase()}`];
|
|
431
|
-
if (rule.interval !== 1) parts.push(`INTERVAL=${rule.interval}`);
|
|
432
|
-
if (rule.count !== void 0) parts.push(`COUNT=${rule.count}`);
|
|
433
|
-
if (rule.until !== void 0) parts.push(`UNTIL=${String(rule.until)}`);
|
|
434
|
-
if (rule.byWeekday && rule.byWeekday.length > 0) {
|
|
435
|
-
const map = { 1: "MO", 2: "TU", 3: "WE", 4: "TH", 5: "FR", 6: "SA", 7: "SU" };
|
|
436
|
-
parts.push(`BYDAY=${rule.byWeekday.map((d) => map[d]).join(",")}`);
|
|
437
|
-
}
|
|
438
|
-
if (rule.byMonthDay && rule.byMonthDay.length > 0) parts.push(`BYMONTHDAY=${rule.byMonthDay.join(",")}`);
|
|
439
|
-
if (rule.byMonth && rule.byMonth.length > 0) parts.push(`BYMONTH=${rule.byMonth.join(",")}`);
|
|
440
|
-
return parts.join(";");
|
|
441
|
-
}
|
|
442
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
443
|
-
0 && (module.exports = {
|
|
444
|
-
between,
|
|
445
|
-
formatRRule,
|
|
446
|
-
parseRRule,
|
|
447
|
-
recurrence,
|
|
448
|
-
skip,
|
|
449
|
-
take
|
|
450
|
-
});
|
|
1
|
+
"use strict";var D=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var C=(n,e)=>{for(var t in e)D(n,t,{get:e[t],enumerable:!0})},H=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of P(e))!A.call(n,o)&&o!==t&&D(n,o,{get:()=>e[o],enumerable:!(r=I(e,o))||r.enumerable});return n};var L=n=>H(D({},"__esModule",{value:!0}),n);var z={};C(z,{between:()=>B,formatRRule:()=>Z,parseRRule:()=>Q,recurrence:()=>W,skip:()=>v,take:()=>j});module.exports=L(z);function S(n){return n%4===0&&n%100!==0||n%400===0}function q(n,e){for(let t of e)if(typeof n[t]!="number")throw new Error(`temporal-fmt: calendar helper requires "${String(t)}", which this value doesn't have. Pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`)}function M(n){q(n,["year","month"]);let{year:e,month:t}=n,r=[31,28,31,30,31,30,31,31,30,31,30,31];return t===2&&S(e)?29:r[t-1]}function k(n){if(typeof n!="object"||n===null)throw new Error(`temporal-fmt: expected a date-carrying Temporal value, got ${String(n)}.`);let e=n,t={};if(typeof e.year=="number"&&(t.year=e.year),typeof e.month=="number"&&(t.month=e.month),typeof e.day=="number"&&(t.day=e.day),typeof e.hour=="number"&&(t.hour=e.hour),typeof e.minute=="number"&&(t.minute=e.minute),typeof e.second=="number"&&(t.second=e.second),typeof e.millisecond=="number"&&(t.millisecond=e.millisecond),typeof e.dayOfWeek=="number"&&(t.dayOfWeek=e.dayOfWeek),typeof e.calendarId=="string"&&(t.calendarId=e.calendarId),t.year===void 0||t.month===void 0||t.day===void 0)throw new Error("temporal-fmt: value is missing year/month/day fields \u2014 pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.");return t}function $(n){return k(n)}function _(n){if(typeof n.dayOfWeek!="number")return;/* c8 ignore start @preserve -- unreachable: every call site (add()'s
|
|
2
|
+
'years'/'months' cases, shiftDays()) passes a `result` whose
|
|
3
|
+
year/month/day were just explicitly set, and the value originally
|
|
4
|
+
came from asDateTime()/asDateFieldView(), which throws unless
|
|
5
|
+
year/month/day are all present as numbers. So by the time this guard
|
|
6
|
+
runs, all three are guaranteed valid. Kept in case a future caller
|
|
7
|
+
constructs a DateTimeFieldView bypassing that validation. */if(typeof n.year!="number"||typeof n.month!="number"||typeof n.day!="number")return;/* c8 ignore stop @preserve */let e=new Date(Date.UTC(n.year,n.month-1,n.day)).getUTCDay();n.dayOfWeek=e===0?7:e}function g(n,e,t){let o={...$(n)};switch(t){case"years":{/* c8 ignore start @preserve -- the `?? 0` fallback is unreachable:
|
|
8
|
+
asDateTime()/asDateFieldView() (called at the top of add()) throws
|
|
9
|
+
unless year is present as a number, so result.year is never
|
|
10
|
+
undefined here. Kept as a guard against a future change that
|
|
11
|
+
relaxes that validation. */o.year=(o.year??0)+e;/* c8 ignore stop @preserve */let s=M({year:o.year,month:o.month});o.day>s&&(o.day=s),_(o);break}case"months":{/* c8 ignore start @preserve -- both `??` fallbacks are unreachable
|
|
12
|
+
for the same reason as the 'years' case above: asDateFieldView()
|
|
13
|
+
guarantees year and month are present numbers before add() ever
|
|
14
|
+
reaches here. */let s=(o.year??0)*12+(o.month??1)-1+e;/* c8 ignore stop @preserve */o.year=Math.floor(s/12),o.month=s%12+1,o.month<1&&(o.month+=12,o.year-=1);/* c8 ignore start @preserve -- unreachable: (total % 12) + 1 can never
|
|
15
|
+
exceed 12 for any integer total in JS (its range is [-10, 12] since
|
|
16
|
+
JS's % can return a negative remainder but never one with
|
|
17
|
+
magnitude >= 12, so adding 1 tops out at 12). Only the < 1 branch
|
|
18
|
+
above is reachable; this was written symmetrically with it but the
|
|
19
|
+
overflow direction it guards against can't occur. Kept rather than
|
|
20
|
+
removed since it costs nothing and documents the intent. */o.month>12&&(o.month-=12,o.year+=1);/* c8 ignore stop @preserve */let u=M({year:o.year,month:o.month});o.day>u&&(o.day=u),_(o);break}case"weeks":o=R(o,e*7);break;case"days":o=R(o,e);break;case"hours":o=w(o,e*36e5);break;case"minutes":o=w(o,e*6e4);break;case"seconds":o=w(o,e*1e3);break;case"milliseconds":o=w(o,e);break}return o}function R(n,e){let t=n.year,r=n.month,o=n.day,s=r<=2?t-1:t,u=Math.floor((s>=0?s:s-399)/400),i=s-u*400,a=r>2?r-3:r+9,m=Math.floor((153*a+2)/5)+o-1,y=i*365+Math.floor(i/4)-Math.floor(i/100)+m,d=u*146097+y-719468+e+719468,c=Math.floor((d>=0?d:d-146096)/146097),f=d-c*146097,h=Math.floor((f-Math.floor(f/1460)+Math.floor(f/36524)-Math.floor(f/146096))/365),E=h+c*400,x=f-(365*h+Math.floor(h/4)-Math.floor(h/100)),p=Math.floor((5*x+2)/153),N=x-Math.floor((153*p+2)/5)+1,T=p<10?p+3:p-9,V=T<=2?E+1:E,O={...n,year:V,month:T,day:N};return _(O),O}function w(n,e){let u=(n.hour??0)*36e5+(n.minute??0)*6e4+(n.second??0)*1e3+(n.millisecond??0)+e,i=Math.floor(u/864e5),a=u%864e5;a<0&&(a+=864e5);let m=Math.floor(a/36e5),y=Math.floor(a%36e5/6e4),l=Math.floor(a%6e4/1e3),d=a%1e3,c={...n,hour:m,minute:y,second:l,millisecond:d};return i!==0?R(c,i):c}function Y(n){let e=n.year,t=n.month,r=n.day,o=t<=2?e-1:e,s=Math.floor((o>=0?o:o-399)/400),u=o-s*400,i=t>2?t-3:t+9,a=Math.floor((153*i+2)/5)+r-1,m=u*365+Math.floor(u/4)-Math.floor(u/100)+a;return(s*146097+m-719468)*864e5+(n.hour??0)*36e5+(n.minute??0)*6e4+(n.second??0)*1e3+(n.millisecond??0)}function F(n){return k(n)}function b(n,e){let t=F(n),r=F(e),o=Y(t),s=Y(r);return o<s?-1:o>s?1:0}function W(n,e){let t=n,r=0,o=[],s=1e4,u=!1,i=!0;function a(d){let c=d;return!(e.byWeekday&&e.byWeekday.length>0&&!e.byWeekday.includes(c.dayOfWeek??0)||e.byMonthDay&&e.byMonthDay.length>0&&!e.byMonthDay.includes(c.day??0)||e.byMonth&&e.byMonth.length>0&&!e.byMonth.includes(c.month??0)||e.exDates&&e.exDates.some(f=>b(f,d)===0))}function m(d,c){let f=e.frequency==="secondly"?"seconds":e.frequency==="minutely"?"minutes":e.frequency==="hourly"?"hours":e.frequency==="daily"?"days":e.frequency==="weekly"?"weeks":e.frequency==="monthly"?"months":"years";return g(d,c*e.interval,f)}function y(d){o.push(d),o.length>s&&o.shift()}function l(d){let c=d,f=0;do{if(c=m(c,1),f++,f>1e3)return u=!0,{value:c,found:!1};if(e.until&&b(c,e.until)>0)return u=!0,{value:c,found:!1}}while(!a(c));return{value:c,found:!0}}return{next(){if(u)return{value:void 0,done:!0};if(i){if(i=!1,a(t))return r++,e.count!==void 0&&r>=e.count&&(u=!0),e.until&&b(t,e.until)>0?(u=!0,{value:void 0,done:!0}):(y(t),{value:t,done:!1});let c=l(t);return c.found?(t=c.value,r++,e.count!==void 0&&r>=e.count&&(u=!0),y(t),{value:t,done:!1}):{value:void 0,done:!0}}let d=l(t);return d.found?(t=d.value,r++,e.count!==void 0&&r>=e.count&&(u=!0),y(t),{value:t,done:!1}):{value:void 0,done:!0}},previous(){return o.length===0?{value:void 0,done:!0}:{value:o.pop(),done:!1}}}}function j(n,e){let t=[];for(let r=0;r<e;r++){let o=n.next();if(o.done)break;t.push(o.value)}return t}var U=1e5;function v(n,e){for(let r=0;r<e&&!n.next().done;r++);let t=[];for(;t.length<U;){let r=n.next();if(r.done)return t;t.push(r.value)}throw new RangeError(`temporal-fmt: skip() collected ${U} occurrences and the rule is still producing \u2014 add a count or until to the rule, or use take(iter, n) for a bounded read.`)}function B(n,e,t,r){let o=W(n,e),s=[];for(;;){let u=o.next();if(u.done||b(u.value,r)>=0)break;b(u.value,t)>=0&&s.push(u.value)}return s}function Q(n){let e=n.trim().toUpperCase().replace(/^RRULE:/,"").split(";"),t={frequency:"daily",interval:1},r=new Set(["SECONDLY","MINUTELY","HOURLY","DAILY","WEEKLY","MONTHLY","YEARLY"]);for(let o of e){if(!o)continue;let s=o.indexOf("=");if(s<0)continue;let u=o.slice(0,s),i=o.slice(s+1);switch(u){case"FREQ":if(!r.has(i))throw new RangeError(`temporal-fmt: unsupported RRULE frequency "${i}".`);t.frequency=i.toLowerCase();break;case"INTERVAL":{let a=Number(i);if(!Number.isSafeInteger(a)||a<1)throw new RangeError(`temporal-fmt: RRULE INTERVAL must be a positive safe integer (got "${i}").`);t.interval=a;break}case"COUNT":{let a=Number(i);if(!Number.isSafeInteger(a)||a<1)throw new RangeError(`temporal-fmt: RRULE COUNT must be a positive safe integer (got "${i}").`);t.count=a;break}case"UNTIL":t.until=i;break;case"BYDAY":t.byWeekday=i.split(",").map(a=>{let m=a.match(/^([+-]?\d)?([A-Z]{2})$/);if(!m)return 0;let y=m[2];return{MO:1,TU:2,WE:3,TH:4,FR:5,SA:6,SU:7}[y]??0});break;case"BYMONTHDAY":{let a=i.split(",").map(Number);if(a.some(m=>!Number.isInteger(m)||m===0||m<-31||m>31))throw new RangeError("temporal-fmt: RRULE BYMONTHDAY contains an out-of-range value.");t.byMonthDay=a;break}case"BYMONTH":{let a=i.split(",").map(Number);if(a.some(m=>!Number.isInteger(m)||m<1||m>12))throw new RangeError("temporal-fmt: RRULE BYMONTH contains an out-of-range value.");t.byMonth=a;break}}}return t}function Z(n){let e=[`FREQ=${n.frequency.toUpperCase()}`];if(n.interval!==1&&e.push(`INTERVAL=${n.interval}`),n.count!==void 0&&e.push(`COUNT=${n.count}`),n.until!==void 0&&e.push(`UNTIL=${String(n.until)}`),n.byWeekday&&n.byWeekday.length>0){let t={1:"MO",2:"TU",3:"WE",4:"TH",5:"FR",6:"SA",7:"SU"};e.push(`BYDAY=${n.byWeekday.map(r=>t[r]).join(",")}`)}return n.byMonthDay&&n.byMonthDay.length>0&&e.push(`BYMONTHDAY=${n.byMonthDay.join(",")}`),n.byMonth&&n.byMonth.length>0&&e.push(`BYMONTH=${n.byMonth.join(",")}`),e.join(";")}0&&(module.exports={between,formatRRule,parseRRule,recurrence,skip,take});
|
|
451
21
|
//# sourceMappingURL=recurrence.cjs.map
|