rrule-temporal 1.0.0 → 1.1.1
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 +109 -6
- package/dist/chunk-6A2XASAM.js +1335 -0
- package/dist/chunk-6VZV7PDA.js +1252 -0
- package/dist/index.cjs +452 -332
- package/dist/index.d.cts +9 -10
- package/dist/index.d.ts +9 -10
- package/dist/index.js +1 -1
- package/dist/totext.cjs +895 -376
- package/dist/totext.js +444 -45
- package/package.json +3 -2
package/dist/totext.cjs
CHANGED
|
@@ -2,7 +2,21 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
6
20
|
var __export = (target, all) => {
|
|
7
21
|
for (var name in all)
|
|
8
22
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -29,62 +43,65 @@ var import_polyfill = require("@js-temporal/polyfill");
|
|
|
29
43
|
function unfoldLine(foldedLine) {
|
|
30
44
|
return foldedLine.replace(/\r?\n[ \t]/g, "");
|
|
31
45
|
}
|
|
32
|
-
function parseDateValues(dateValues, tzid) {
|
|
46
|
+
function parseDateValues(dateValues, tzid, valueType) {
|
|
33
47
|
const dates = [];
|
|
34
48
|
for (const dateValue of dateValues) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
));
|
|
49
|
+
const isDate = valueType === "DATE" || !dateValue.includes("T");
|
|
50
|
+
if (isDate) {
|
|
51
|
+
const isoDate = `${dateValue.slice(0, 4)}-${dateValue.slice(4, 6)}-${dateValue.slice(6, 8)}`;
|
|
52
|
+
dates.push(import_polyfill.Temporal.PlainDate.from(isoDate).toZonedDateTime({ timeZone: tzid }));
|
|
40
53
|
} else {
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
if (/Z$/.test(dateValue)) {
|
|
55
|
+
const iso = `${dateValue.slice(0, 4)}-${dateValue.slice(4, 6)}-${dateValue.slice(6, 8)}T${dateValue.slice(9, 15)}Z`;
|
|
56
|
+
dates.push(import_polyfill.Temporal.Instant.from(iso).toZonedDateTimeISO(tzid || "UTC"));
|
|
57
|
+
} else {
|
|
58
|
+
const isoDate = `${dateValue.slice(0, 4)}-${dateValue.slice(4, 6)}-${dateValue.slice(6, 8)}T${dateValue.slice(9)}`;
|
|
59
|
+
dates.push(import_polyfill.Temporal.PlainDateTime.from(isoDate).toZonedDateTime(tzid));
|
|
60
|
+
}
|
|
43
61
|
}
|
|
44
62
|
}
|
|
45
63
|
return dates;
|
|
46
64
|
}
|
|
47
|
-
function parseRRuleString(input,
|
|
48
|
-
|
|
65
|
+
function parseRRuleString(input, targetTimezone) {
|
|
66
|
+
var _a;
|
|
67
|
+
const unfoldedInput = unfoldLine(input).trim();
|
|
49
68
|
let dtstart;
|
|
50
69
|
let tzid = "UTC";
|
|
51
70
|
let rruleLine;
|
|
52
71
|
let exDate = [];
|
|
53
72
|
let rDate = [];
|
|
54
|
-
if (/^DTSTART/
|
|
55
|
-
const lines = unfoldedInput.split(/\
|
|
56
|
-
const dtLine = lines
|
|
73
|
+
if (/^DTSTART/im.test(unfoldedInput)) {
|
|
74
|
+
const lines = unfoldedInput.split(/\s+/);
|
|
75
|
+
const dtLine = lines.find((line) => line.match(/^DTSTART/i));
|
|
57
76
|
const rrLine = lines.find((line) => line.match(/^RRULE:/i));
|
|
58
77
|
const exLines = lines.filter((line) => line.match(/^EXDATE/i));
|
|
59
78
|
const rLines = lines.filter((line) => line.match(/^RDATE/i));
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
dtstart =
|
|
79
|
+
const dtMatch = dtLine.match(/DTSTART(?:;VALUE=([^;]+))?(?:;TZID=([^:]+))?:(.+)/i);
|
|
80
|
+
if (!dtMatch) throw new Error("Invalid DTSTART in ICS snippet");
|
|
81
|
+
const [, valueType, dtTzid, dtValue] = dtMatch;
|
|
82
|
+
tzid = (_a = dtTzid != null ? dtTzid : targetTimezone) != null ? _a : tzid;
|
|
83
|
+
dtstart = parseDateValues([dtValue], tzid, valueType)[0];
|
|
65
84
|
rruleLine = rrLine;
|
|
66
85
|
for (const exLine of exLines) {
|
|
67
|
-
const exMatch = exLine.match(/EXDATE(?:;TZID=([^:]+))?:(.+)/i);
|
|
86
|
+
const exMatch = exLine.match(/EXDATE(?:;VALUE=([^;]+))?(?:;TZID=([^:]+))?:(.+)/i);
|
|
68
87
|
if (exMatch) {
|
|
69
|
-
const exTzid = exMatch
|
|
70
|
-
const
|
|
71
|
-
|
|
88
|
+
const [, valueType2, exTzid, dateValuesStr] = exMatch;
|
|
89
|
+
const exTimezone = exTzid || tzid;
|
|
90
|
+
const dateValues = dateValuesStr.split(",");
|
|
91
|
+
exDate.push(...parseDateValues(dateValues, exTimezone, valueType2));
|
|
72
92
|
}
|
|
73
93
|
}
|
|
74
94
|
for (const rLine of rLines) {
|
|
75
|
-
const rMatch = rLine.match(/RDATE(?:;TZID=([^:]+))?:(.+)/i);
|
|
95
|
+
const rMatch = rLine.match(/RDATE(?:;VALUE=([^;]+))?(?:;TZID=([^:]+))?:(.+)/i);
|
|
76
96
|
if (rMatch) {
|
|
77
|
-
const rTzid = rMatch
|
|
78
|
-
const
|
|
79
|
-
|
|
97
|
+
const [, valueType2, rTzid, dateValuesStr] = rMatch;
|
|
98
|
+
const rTimezone = rTzid || tzid;
|
|
99
|
+
const dateValues = dateValuesStr.split(",");
|
|
100
|
+
rDate.push(...parseDateValues(dateValues, rTimezone, valueType2));
|
|
80
101
|
}
|
|
81
102
|
}
|
|
82
103
|
} else {
|
|
83
|
-
|
|
84
|
-
throw new Error("dtstart required when parsing RRULE alone");
|
|
85
|
-
dtstart = fallbackDtstart;
|
|
86
|
-
tzid = fallbackDtstart.timeZoneId;
|
|
87
|
-
rruleLine = unfoldedInput.replace(/^RRULE:/i, "RRULE:");
|
|
104
|
+
throw new Error("dtstart required when parsing RRULE alone");
|
|
88
105
|
}
|
|
89
106
|
const parts = rruleLine ? rruleLine.replace(/^RRULE:/i, "").split(";") : [];
|
|
90
107
|
const opts = {
|
|
@@ -109,14 +126,13 @@ function parseRRuleString(input, fallbackDtstart) {
|
|
|
109
126
|
case "UNTIL": {
|
|
110
127
|
if (/Z$/.test(val)) {
|
|
111
128
|
const iso = `${val.slice(0, 4)}-${val.slice(4, 6)}-${val.slice(6, 8)}T${val.slice(9, 15)}Z`;
|
|
112
|
-
opts.until = import_polyfill.Temporal.Instant.from(iso).toZonedDateTimeISO(
|
|
113
|
-
tzid || "UTC"
|
|
114
|
-
);
|
|
129
|
+
opts.until = import_polyfill.Temporal.Instant.from(iso).toZonedDateTimeISO(tzid || "UTC");
|
|
115
130
|
} else {
|
|
116
131
|
const iso = `${val.slice(0, 4)}-${val.slice(4, 6)}-${val.slice(6, 8)}T${val.slice(9, 15)}`;
|
|
117
|
-
opts.until = import_polyfill.Temporal.PlainDateTime.from(iso).toZonedDateTime(
|
|
118
|
-
|
|
119
|
-
|
|
132
|
+
opts.until = import_polyfill.Temporal.PlainDateTime.from(iso).toZonedDateTime(tzid || "UTC");
|
|
133
|
+
if (tzid !== "UTC") {
|
|
134
|
+
throw new Error("UNTIL rule part MUST always be specified as a date with UTC time");
|
|
135
|
+
}
|
|
120
136
|
}
|
|
121
137
|
break;
|
|
122
138
|
}
|
|
@@ -154,20 +170,17 @@ function parseRRuleString(input, fallbackDtstart) {
|
|
|
154
170
|
}
|
|
155
171
|
return opts;
|
|
156
172
|
}
|
|
157
|
-
var RRuleTemporal = class {
|
|
158
|
-
tzid;
|
|
159
|
-
originalDtstart;
|
|
160
|
-
opts;
|
|
161
|
-
maxIterations;
|
|
162
|
-
includeDtstart;
|
|
173
|
+
var RRuleTemporal = class _RRuleTemporal {
|
|
163
174
|
constructor(params) {
|
|
175
|
+
var _a, _b, _c, _d, _e;
|
|
164
176
|
let manual;
|
|
165
177
|
if ("rruleString" in params) {
|
|
166
|
-
|
|
167
|
-
this.tzid =
|
|
168
|
-
this.originalDtstart =
|
|
178
|
+
const parsed = parseRRuleString(params.rruleString, params.tzid);
|
|
179
|
+
this.tzid = (_b = (_a = parsed.tzid) != null ? _a : params.tzid) != null ? _b : "UTC";
|
|
180
|
+
this.originalDtstart = parsed.dtstart;
|
|
181
|
+
manual = __spreadValues(__spreadValues({}, params), parsed);
|
|
169
182
|
} else {
|
|
170
|
-
manual = {
|
|
183
|
+
manual = __spreadValues({}, params);
|
|
171
184
|
if (typeof manual.dtstart === "string") {
|
|
172
185
|
throw new Error("Manual dtstart must be a ZonedDateTime");
|
|
173
186
|
}
|
|
@@ -176,7 +189,7 @@ var RRuleTemporal = class {
|
|
|
176
189
|
this.originalDtstart = manual.dtstart;
|
|
177
190
|
}
|
|
178
191
|
if (!manual.freq) throw new Error("RRULE must include FREQ");
|
|
179
|
-
manual.interval = manual.interval
|
|
192
|
+
manual.interval = (_c = manual.interval) != null ? _c : 1;
|
|
180
193
|
if (manual.interval <= 0) {
|
|
181
194
|
throw new Error("Cannot create RRule: interval must be greater than 0");
|
|
182
195
|
}
|
|
@@ -184,8 +197,8 @@ var RRuleTemporal = class {
|
|
|
184
197
|
throw new Error("Manual until must be a ZonedDateTime");
|
|
185
198
|
}
|
|
186
199
|
this.opts = this.sanitizeOpts(manual);
|
|
187
|
-
this.maxIterations = manual.maxIterations
|
|
188
|
-
this.includeDtstart = manual.includeDtstart
|
|
200
|
+
this.maxIterations = (_d = manual.maxIterations) != null ? _d : 1e4;
|
|
201
|
+
this.includeDtstart = (_e = manual.includeDtstart) != null ? _e : false;
|
|
189
202
|
}
|
|
190
203
|
sanitizeOpts(opts) {
|
|
191
204
|
const validDay = /^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/;
|
|
@@ -222,6 +235,9 @@ var RRuleTemporal = class {
|
|
|
222
235
|
if (opts.bySecond.length === 0) delete opts.bySecond;
|
|
223
236
|
}
|
|
224
237
|
if (opts.bySetPos) {
|
|
238
|
+
if (opts.bySetPos.some((p) => p === 0)) {
|
|
239
|
+
throw new Error("bySetPos may not contain 0");
|
|
240
|
+
}
|
|
225
241
|
opts.bySetPos = opts.bySetPos.filter((n) => Number.isInteger(n) && n !== 0);
|
|
226
242
|
if (opts.bySetPos.length === 0) delete opts.bySetPos;
|
|
227
243
|
}
|
|
@@ -253,9 +269,10 @@ var RRuleTemporal = class {
|
|
|
253
269
|
* present the original date is returned unchanged.
|
|
254
270
|
*/
|
|
255
271
|
expandByTime(base) {
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
const
|
|
272
|
+
var _a, _b, _c;
|
|
273
|
+
const hours = (_a = this.opts.byHour) != null ? _a : [base.hour];
|
|
274
|
+
const minutes = (_b = this.opts.byMinute) != null ? _b : [base.minute];
|
|
275
|
+
const seconds = (_c = this.opts.bySecond) != null ? _c : [base.second];
|
|
259
276
|
const out = [];
|
|
260
277
|
for (const h of hours) {
|
|
261
278
|
for (const m of minutes) {
|
|
@@ -329,8 +346,73 @@ var RRuleTemporal = class {
|
|
|
329
346
|
return dt;
|
|
330
347
|
}
|
|
331
348
|
computeFirst() {
|
|
349
|
+
var _a, _b, _c;
|
|
332
350
|
let zdt = this.originalDtstart;
|
|
333
|
-
if (this.opts.
|
|
351
|
+
if (((_a = this.opts.byWeekNo) == null ? void 0 : _a.length) && ["DAILY", "HOURLY", "MINUTELY", "SECONDLY"].includes(this.opts.freq)) {
|
|
352
|
+
let targetWeek = this.opts.byWeekNo[0];
|
|
353
|
+
let targetYear = zdt.year;
|
|
354
|
+
while (targetYear <= zdt.year + 10) {
|
|
355
|
+
const jan1 = zdt.with({ year: targetYear, month: 1, day: 1 });
|
|
356
|
+
const dec31 = zdt.with({ year: targetYear, month: 12, day: 31 });
|
|
357
|
+
let hasTargetWeek = false;
|
|
358
|
+
if (targetWeek > 0) {
|
|
359
|
+
let maxWeek = 52;
|
|
360
|
+
if (jan1.dayOfWeek === 4 || dec31.dayOfWeek === 4) {
|
|
361
|
+
maxWeek = 53;
|
|
362
|
+
}
|
|
363
|
+
hasTargetWeek = targetWeek <= maxWeek;
|
|
364
|
+
} else {
|
|
365
|
+
let maxWeek = 52;
|
|
366
|
+
if (jan1.dayOfWeek === 4 || dec31.dayOfWeek === 4) {
|
|
367
|
+
maxWeek = 53;
|
|
368
|
+
}
|
|
369
|
+
hasTargetWeek = -targetWeek <= maxWeek;
|
|
370
|
+
}
|
|
371
|
+
if (hasTargetWeek) {
|
|
372
|
+
const firstThursday = jan1.add({ days: (4 - jan1.dayOfWeek + 7) % 7 });
|
|
373
|
+
let weekStart;
|
|
374
|
+
if (targetWeek > 0) {
|
|
375
|
+
weekStart = firstThursday.subtract({ days: 3 }).add({ weeks: targetWeek - 1 });
|
|
376
|
+
} else {
|
|
377
|
+
const lastWeek = jan1.dayOfWeek === 4 || dec31.dayOfWeek === 4 ? 53 : 52;
|
|
378
|
+
weekStart = firstThursday.subtract({ days: 3 }).add({ weeks: lastWeek + targetWeek });
|
|
379
|
+
}
|
|
380
|
+
if ((_b = this.opts.byDay) == null ? void 0 : _b.length) {
|
|
381
|
+
const dayMap = {
|
|
382
|
+
MO: 1,
|
|
383
|
+
TU: 2,
|
|
384
|
+
WE: 3,
|
|
385
|
+
TH: 4,
|
|
386
|
+
FR: 5,
|
|
387
|
+
SA: 6,
|
|
388
|
+
SU: 7
|
|
389
|
+
};
|
|
390
|
+
const targetDays = this.opts.byDay.map((tok) => {
|
|
391
|
+
var _a2;
|
|
392
|
+
return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
|
|
393
|
+
}).filter(Boolean).map((day) => dayMap[day]).filter(Boolean);
|
|
394
|
+
if (targetDays.length) {
|
|
395
|
+
const candidates = targetDays.map((dayOfWeek) => {
|
|
396
|
+
const delta = (dayOfWeek - weekStart.dayOfWeek + 7) % 7;
|
|
397
|
+
return weekStart.add({ days: delta });
|
|
398
|
+
});
|
|
399
|
+
const firstCandidate = candidates.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b))[0];
|
|
400
|
+
if (firstCandidate && import_polyfill.Temporal.ZonedDateTime.compare(firstCandidate, this.originalDtstart) >= 0) {
|
|
401
|
+
zdt = firstCandidate;
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
} else {
|
|
406
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(weekStart, this.originalDtstart) >= 0) {
|
|
407
|
+
zdt = weekStart;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
targetYear++;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
if (((_c = this.opts.byDay) == null ? void 0 : _c.length) && !this.opts.byWeekNo) {
|
|
334
416
|
const dayMap = {
|
|
335
417
|
MO: 1,
|
|
336
418
|
TU: 2,
|
|
@@ -342,12 +424,11 @@ var RRuleTemporal = class {
|
|
|
342
424
|
};
|
|
343
425
|
let deltas = [];
|
|
344
426
|
if (["DAILY", "HOURLY", "MINUTELY", "SECONDLY"].includes(this.opts.freq) && this.opts.byDay.every((tok) => /^[A-Z]{2}$/.test(tok))) {
|
|
345
|
-
deltas = this.opts.byDay.map(
|
|
346
|
-
(tok) => (dayMap[tok] - zdt.dayOfWeek + 7) % 7
|
|
347
|
-
);
|
|
427
|
+
deltas = this.opts.byDay.map((tok) => (dayMap[tok] - zdt.dayOfWeek + 7) % 7);
|
|
348
428
|
} else {
|
|
349
429
|
deltas = this.opts.byDay.map((tok) => {
|
|
350
|
-
|
|
430
|
+
var _a2;
|
|
431
|
+
const wdTok = (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
|
|
351
432
|
return wdTok ? (dayMap[wdTok] - zdt.dayOfWeek + 7) % 7 : null;
|
|
352
433
|
}).filter((d) => d !== null);
|
|
353
434
|
}
|
|
@@ -356,41 +437,27 @@ var RRuleTemporal = class {
|
|
|
356
437
|
}
|
|
357
438
|
}
|
|
358
439
|
const { byHour, byMinute, bySecond } = this.opts;
|
|
440
|
+
if (this.opts.freq === "HOURLY" && !byHour && import_polyfill.Temporal.ZonedDateTime.compare(
|
|
441
|
+
zdt.with({ hour: 0, minute: 0, second: 0, microsecond: 0, nanosecond: 0 }),
|
|
442
|
+
this.originalDtstart
|
|
443
|
+
) > 0) {
|
|
444
|
+
zdt = zdt.with({ hour: 0, minute: 0, second: 0, microsecond: 0, nanosecond: 0 });
|
|
445
|
+
}
|
|
359
446
|
if (byHour || byMinute || bySecond) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
zdt = this.applyTimeOverride(this.rawAdvance(this.originalDtstart));
|
|
447
|
+
const candidates = this.expandByTime(zdt);
|
|
448
|
+
for (const candidate of candidates) {
|
|
449
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, this.originalDtstart) >= 0) {
|
|
450
|
+
return candidate;
|
|
451
|
+
}
|
|
366
452
|
}
|
|
453
|
+
zdt = this.applyTimeOverride(this.rawAdvance(zdt));
|
|
367
454
|
}
|
|
368
455
|
return zdt;
|
|
369
456
|
}
|
|
370
|
-
// inside class RRuleTemporal:
|
|
371
|
-
generateWeeklyOccurrences(sample) {
|
|
372
|
-
const dayMap = {
|
|
373
|
-
MO: 1,
|
|
374
|
-
TU: 2,
|
|
375
|
-
WE: 3,
|
|
376
|
-
TH: 4,
|
|
377
|
-
FR: 5,
|
|
378
|
-
SA: 6,
|
|
379
|
-
SU: 7
|
|
380
|
-
};
|
|
381
|
-
const tokens = this.opts.byDay?.length ? [...this.opts.byDay] : [Object.entries(dayMap).find(([, d]) => d === sample.dayOfWeek)[0]];
|
|
382
|
-
const occs = tokens.flatMap((tok) => {
|
|
383
|
-
const targetDow = dayMap[tok];
|
|
384
|
-
const delta = (targetDow - sample.dayOfWeek + 7) % 7;
|
|
385
|
-
const sameDate = sample.add({ days: delta });
|
|
386
|
-
return this.expandByTime(sameDate);
|
|
387
|
-
});
|
|
388
|
-
return occs.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
389
|
-
}
|
|
390
457
|
// --- NEW: constraint checks ---
|
|
391
458
|
// 2) Replace your matchesByDay with this:
|
|
392
459
|
matchesByDay(zdt) {
|
|
393
|
-
const { byDay } = this.opts;
|
|
460
|
+
const { byDay, freq } = this.opts;
|
|
394
461
|
if (!byDay) return true;
|
|
395
462
|
const dayMap = {
|
|
396
463
|
MO: 1,
|
|
@@ -408,6 +475,10 @@ var RRuleTemporal = class {
|
|
|
408
475
|
const weekday = m[2];
|
|
409
476
|
if (!weekday) continue;
|
|
410
477
|
const wd = dayMap[weekday];
|
|
478
|
+
if (freq === "DAILY") {
|
|
479
|
+
if (zdt.dayOfWeek === wd) return true;
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
411
482
|
if (ord === 0) {
|
|
412
483
|
if (zdt.dayOfWeek === wd) return true;
|
|
413
484
|
continue;
|
|
@@ -433,9 +504,7 @@ var RRuleTemporal = class {
|
|
|
433
504
|
const { byMonthDay } = this.opts;
|
|
434
505
|
if (!byMonthDay) return true;
|
|
435
506
|
const lastDay = zdt.with({ day: 1 }).add({ months: 1 }).subtract({ days: 1 }).day;
|
|
436
|
-
return byMonthDay.some(
|
|
437
|
-
(d) => d > 0 ? zdt.day === d : zdt.day === lastDay + d + 1
|
|
438
|
-
);
|
|
507
|
+
return byMonthDay.some((d) => d > 0 ? zdt.day === d : zdt.day === lastDay + d + 1);
|
|
439
508
|
}
|
|
440
509
|
matchesAll(zdt) {
|
|
441
510
|
return this.matchesByDay(zdt) && this.matchesByMonth(zdt) && this.matchesByMonthDay(zdt) && this.matchesByYearDay(zdt) && this.matchesByWeekNo(zdt);
|
|
@@ -447,19 +516,31 @@ var RRuleTemporal = class {
|
|
|
447
516
|
const last = zdt.with({ month: 12, day: 31 }).dayOfYear;
|
|
448
517
|
return byYearDay.some((d) => d > 0 ? dayOfYear === d : dayOfYear === last + d + 1);
|
|
449
518
|
}
|
|
519
|
+
getIsoWeekInfo(zdt) {
|
|
520
|
+
const thursday = zdt.add({ days: 4 - zdt.dayOfWeek });
|
|
521
|
+
const year = thursday.year;
|
|
522
|
+
const firstThursday = thursday.with({ month: 1, day: 1 }).add({ days: (4 - thursday.with({ month: 1, day: 1 }).dayOfWeek + 7) % 7 });
|
|
523
|
+
const diffDays = thursday.toPlainDate().since(firstThursday.toPlainDate()).days;
|
|
524
|
+
const week = Math.floor(diffDays / 7) + 1;
|
|
525
|
+
return { week, year };
|
|
526
|
+
}
|
|
450
527
|
matchesByWeekNo(zdt) {
|
|
451
|
-
const { byWeekNo
|
|
528
|
+
const { byWeekNo } = this.opts;
|
|
452
529
|
if (!byWeekNo) return true;
|
|
453
|
-
const
|
|
454
|
-
const
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
530
|
+
const { week, year } = this.getIsoWeekInfo(zdt);
|
|
531
|
+
const jan1 = zdt.with({ year, month: 1, day: 1 });
|
|
532
|
+
const dec31 = zdt.with({ year, month: 12, day: 31 });
|
|
533
|
+
let lastWeek = 52;
|
|
534
|
+
if (jan1.dayOfWeek === 4 || dec31.dayOfWeek === 4) {
|
|
535
|
+
lastWeek = 53;
|
|
536
|
+
}
|
|
537
|
+
return byWeekNo.some((wn) => {
|
|
538
|
+
if (wn > 0) {
|
|
539
|
+
return week === wn;
|
|
540
|
+
} else {
|
|
541
|
+
return week === lastWeek + wn + 1;
|
|
542
|
+
}
|
|
543
|
+
});
|
|
463
544
|
}
|
|
464
545
|
options() {
|
|
465
546
|
return this.opts;
|
|
@@ -470,6 +551,7 @@ var RRuleTemporal = class {
|
|
|
470
551
|
* @returns An array of Temporal.ZonedDateTime objects representing all occurrences of the rule.
|
|
471
552
|
*/
|
|
472
553
|
all(iterator) {
|
|
554
|
+
var _a;
|
|
473
555
|
if (!this.opts.count && !this.opts.until && !iterator) {
|
|
474
556
|
throw new Error("all() requires iterator when no COUNT/UNTIL");
|
|
475
557
|
}
|
|
@@ -478,14 +560,14 @@ var RRuleTemporal = class {
|
|
|
478
560
|
if (this.opts.freq === "MONTHLY" && (this.opts.byDay || this.opts.byMonthDay)) {
|
|
479
561
|
const start = this.originalDtstart;
|
|
480
562
|
let monthCursor = start.with({ day: 1 });
|
|
481
|
-
let
|
|
563
|
+
let matchCount = 0;
|
|
482
564
|
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
483
|
-
if (iterator && !iterator(start,
|
|
565
|
+
if (iterator && !iterator(start, matchCount)) {
|
|
484
566
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
485
567
|
}
|
|
486
568
|
dates.push(start);
|
|
487
|
-
|
|
488
|
-
if (this.shouldBreakForCountLimit(
|
|
569
|
+
matchCount++;
|
|
570
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
489
571
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
490
572
|
}
|
|
491
573
|
}
|
|
@@ -493,8 +575,9 @@ var RRuleTemporal = class {
|
|
|
493
575
|
if (++iterationCount > this.maxIterations) {
|
|
494
576
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
495
577
|
}
|
|
496
|
-
|
|
497
|
-
|
|
578
|
+
let occs = this.generateMonthlyOccurrences(monthCursor);
|
|
579
|
+
occs = this.applyBySetPos(occs);
|
|
580
|
+
if (monthCursor.month === start.month && occs.some((o) => import_polyfill.Temporal.ZonedDateTime.compare(o, start) < 0) && occs.some((o) => import_polyfill.Temporal.ZonedDateTime.compare(o, start) === 0)) {
|
|
498
581
|
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
499
582
|
continue outer_month;
|
|
500
583
|
}
|
|
@@ -503,12 +586,12 @@ var RRuleTemporal = class {
|
|
|
503
586
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
504
587
|
break outer_month;
|
|
505
588
|
}
|
|
506
|
-
if (iterator && !iterator(occ,
|
|
589
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
507
590
|
break outer_month;
|
|
508
591
|
}
|
|
509
592
|
dates.push(occ);
|
|
510
|
-
|
|
511
|
-
if (this.shouldBreakForCountLimit(
|
|
593
|
+
matchCount++;
|
|
594
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
512
595
|
break outer_month;
|
|
513
596
|
}
|
|
514
597
|
}
|
|
@@ -517,6 +600,45 @@ var RRuleTemporal = class {
|
|
|
517
600
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
518
601
|
}
|
|
519
602
|
if (this.opts.freq === "WEEKLY") {
|
|
603
|
+
if (this.opts.byYearDay && this.opts.byYearDay.length > 0) {
|
|
604
|
+
const start2 = this.originalDtstart;
|
|
605
|
+
if (this.includeDtstart && !this.matchesAll(start2)) {
|
|
606
|
+
if (iterator && !iterator(start2, 0)) {
|
|
607
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
608
|
+
}
|
|
609
|
+
dates.push(start2);
|
|
610
|
+
if (this.shouldBreakForCountLimit(1)) {
|
|
611
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
let yearCursor = start2.with({ month: 1, day: 1 });
|
|
615
|
+
let matchCount2 = dates.length;
|
|
616
|
+
outer_year_for_weekly: while (true) {
|
|
617
|
+
if (++iterationCount > this.maxIterations) {
|
|
618
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
619
|
+
}
|
|
620
|
+
const occs = this.generateYearlyOccurrences(yearCursor);
|
|
621
|
+
for (const occ of occs) {
|
|
622
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start2) < 0) continue;
|
|
623
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
624
|
+
break outer_year_for_weekly;
|
|
625
|
+
}
|
|
626
|
+
if (iterator && !iterator(occ, matchCount2)) {
|
|
627
|
+
break outer_year_for_weekly;
|
|
628
|
+
}
|
|
629
|
+
dates.push(occ);
|
|
630
|
+
matchCount2++;
|
|
631
|
+
if (this.shouldBreakForCountLimit(matchCount2)) {
|
|
632
|
+
break outer_year_for_weekly;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (this.opts.until && yearCursor.year > this.opts.until.year) {
|
|
636
|
+
break;
|
|
637
|
+
}
|
|
638
|
+
yearCursor = yearCursor.add({ years: 1 });
|
|
639
|
+
}
|
|
640
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
641
|
+
}
|
|
520
642
|
const start = this.originalDtstart;
|
|
521
643
|
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
522
644
|
if (iterator && !iterator(start, 0)) {
|
|
@@ -536,39 +658,44 @@ var RRuleTemporal = class {
|
|
|
536
658
|
SA: 6,
|
|
537
659
|
SU: 7
|
|
538
660
|
};
|
|
539
|
-
const tokens = this.opts.byDay ? [...this.opts.byDay] : [Object.entries(dayMap).find(([, d]) => d === start.dayOfWeek)[0]];
|
|
540
|
-
const dows = tokens.map((tok) => dayMap[tok]).filter((d) => d !== void 0).sort((a, b) => a - b);
|
|
661
|
+
const tokens = this.opts.byDay ? [...this.opts.byDay] : this.opts.byMonthDay && this.opts.byMonthDay.length > 0 ? Object.keys(dayMap) : [Object.entries(dayMap).find(([, d]) => d === start.dayOfWeek)[0]];
|
|
662
|
+
const dows = tokens.map((tok) => dayMap[tok.slice(-2)]).filter((d) => d !== void 0).sort((a, b) => a - b);
|
|
541
663
|
const firstWeekDates = dows.map((dw) => {
|
|
542
664
|
const delta = (dw - start.dayOfWeek + 7) % 7;
|
|
543
665
|
return start.add({ days: delta });
|
|
544
666
|
});
|
|
545
|
-
let firstOccurrence = firstWeekDates.reduce(
|
|
546
|
-
|
|
547
|
-
);
|
|
548
|
-
const wkstDay = dayMap[this.opts.wkst || "MO"] ?? 1;
|
|
667
|
+
let firstOccurrence = firstWeekDates.reduce((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b) <= 0 ? a : b);
|
|
668
|
+
const wkstDay = (_a = dayMap[this.opts.wkst || "MO"]) != null ? _a : 1;
|
|
549
669
|
const firstOccWeekOffset = (firstOccurrence.dayOfWeek - wkstDay + 7) % 7;
|
|
550
670
|
let weekCursor = firstOccurrence.subtract({ days: firstOccWeekOffset });
|
|
551
|
-
let
|
|
671
|
+
let matchCount = 0;
|
|
552
672
|
outer_week: while (true) {
|
|
553
673
|
if (++iterationCount > this.maxIterations) {
|
|
554
674
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
555
675
|
}
|
|
556
|
-
|
|
676
|
+
let occs = dows.flatMap((dw) => {
|
|
557
677
|
const delta = (dw - wkstDay + 7) % 7;
|
|
558
678
|
const sameDate = weekCursor.add({ days: delta });
|
|
559
679
|
return this.expandByTime(sameDate);
|
|
560
680
|
}).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
681
|
+
occs = this.applyBySetPos(occs);
|
|
561
682
|
for (const occ of occs) {
|
|
562
683
|
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
563
684
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
564
685
|
break outer_week;
|
|
565
686
|
}
|
|
566
|
-
if (
|
|
687
|
+
if (!this.matchesByMonth(occ)) {
|
|
688
|
+
continue;
|
|
689
|
+
}
|
|
690
|
+
if (!this.matchesByMonthDay(occ)) {
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
567
694
|
break outer_week;
|
|
568
695
|
}
|
|
569
696
|
dates.push(occ);
|
|
570
|
-
|
|
571
|
-
if (this.shouldBreakForCountLimit(
|
|
697
|
+
matchCount++;
|
|
698
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
572
699
|
break outer_week;
|
|
573
700
|
}
|
|
574
701
|
}
|
|
@@ -576,7 +703,7 @@ var RRuleTemporal = class {
|
|
|
576
703
|
}
|
|
577
704
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
578
705
|
}
|
|
579
|
-
if (this.opts.freq === "MONTHLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
706
|
+
if (this.opts.freq === "MONTHLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay && !this.opts.byYearDay) {
|
|
580
707
|
const start = this.originalDtstart;
|
|
581
708
|
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
582
709
|
if (iterator && !iterator(start, 0)) {
|
|
@@ -589,7 +716,7 @@ var RRuleTemporal = class {
|
|
|
589
716
|
}
|
|
590
717
|
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
591
718
|
let monthOffset = 0;
|
|
592
|
-
let
|
|
719
|
+
let matchCount = dates.length;
|
|
593
720
|
let startMonthIndex = months.findIndex((m) => m >= start.month);
|
|
594
721
|
if (startMonthIndex === -1) {
|
|
595
722
|
startMonthIndex = 0;
|
|
@@ -610,12 +737,12 @@ var RRuleTemporal = class {
|
|
|
610
737
|
break;
|
|
611
738
|
}
|
|
612
739
|
if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, start) >= 0) {
|
|
613
|
-
if (iterator && !iterator(candidate,
|
|
740
|
+
if (iterator && !iterator(candidate, matchCount)) {
|
|
614
741
|
break;
|
|
615
742
|
}
|
|
616
743
|
dates.push(candidate);
|
|
617
|
-
|
|
618
|
-
if (this.shouldBreakForCountLimit(
|
|
744
|
+
matchCount++;
|
|
745
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
619
746
|
break;
|
|
620
747
|
}
|
|
621
748
|
}
|
|
@@ -623,7 +750,7 @@ var RRuleTemporal = class {
|
|
|
623
750
|
}
|
|
624
751
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
625
752
|
}
|
|
626
|
-
if (this.opts.freq === "YEARLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
753
|
+
if (this.opts.freq === "YEARLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay && !this.opts.byYearDay && !this.opts.byWeekNo) {
|
|
627
754
|
const start = this.originalDtstart;
|
|
628
755
|
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
629
756
|
if (iterator && !iterator(start, 0)) {
|
|
@@ -636,7 +763,7 @@ var RRuleTemporal = class {
|
|
|
636
763
|
}
|
|
637
764
|
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
638
765
|
let yearOffset = 0;
|
|
639
|
-
let
|
|
766
|
+
let matchCount = 0;
|
|
640
767
|
while (true) {
|
|
641
768
|
if (++iterationCount > this.maxIterations) {
|
|
642
769
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
@@ -651,12 +778,12 @@ var RRuleTemporal = class {
|
|
|
651
778
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
652
779
|
return dates;
|
|
653
780
|
}
|
|
654
|
-
if (iterator && !iterator(occ,
|
|
781
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
655
782
|
return dates;
|
|
656
783
|
}
|
|
657
784
|
dates.push(occ);
|
|
658
|
-
|
|
659
|
-
if (this.shouldBreakForCountLimit(
|
|
785
|
+
matchCount++;
|
|
786
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
660
787
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
661
788
|
}
|
|
662
789
|
}
|
|
@@ -676,7 +803,7 @@ var RRuleTemporal = class {
|
|
|
676
803
|
}
|
|
677
804
|
}
|
|
678
805
|
let yearCursor = start.with({ month: 1, day: 1 });
|
|
679
|
-
let
|
|
806
|
+
let matchCount = 0;
|
|
680
807
|
outer_year: while (true) {
|
|
681
808
|
if (++iterationCount > this.maxIterations) {
|
|
682
809
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
@@ -687,12 +814,12 @@ var RRuleTemporal = class {
|
|
|
687
814
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
688
815
|
break outer_year;
|
|
689
816
|
}
|
|
690
|
-
if (iterator && !iterator(occ,
|
|
817
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
691
818
|
break outer_year;
|
|
692
819
|
}
|
|
693
820
|
dates.push(occ);
|
|
694
|
-
|
|
695
|
-
if (this.shouldBreakForCountLimit(
|
|
821
|
+
matchCount++;
|
|
822
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
696
823
|
break outer_year;
|
|
697
824
|
}
|
|
698
825
|
}
|
|
@@ -712,7 +839,7 @@ var RRuleTemporal = class {
|
|
|
712
839
|
}
|
|
713
840
|
}
|
|
714
841
|
let yearCursor = start.with({ month: 1, day: 1 });
|
|
715
|
-
let
|
|
842
|
+
let matchCount = 0;
|
|
716
843
|
outer_year2: while (true) {
|
|
717
844
|
if (++iterationCount > this.maxIterations) {
|
|
718
845
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
@@ -723,12 +850,12 @@ var RRuleTemporal = class {
|
|
|
723
850
|
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
724
851
|
break outer_year2;
|
|
725
852
|
}
|
|
726
|
-
if (iterator && !iterator(occ,
|
|
853
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
727
854
|
break outer_year2;
|
|
728
855
|
}
|
|
729
856
|
dates.push(occ);
|
|
730
|
-
|
|
731
|
-
if (this.shouldBreakForCountLimit(
|
|
857
|
+
matchCount++;
|
|
858
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
732
859
|
break outer_year2;
|
|
733
860
|
}
|
|
734
861
|
}
|
|
@@ -736,36 +863,141 @@ var RRuleTemporal = class {
|
|
|
736
863
|
}
|
|
737
864
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
738
865
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
if (
|
|
743
|
-
|
|
866
|
+
if (this.opts.freq === "MONTHLY" && this.opts.byYearDay && this.opts.byYearDay.length > 0 && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
867
|
+
const start = this.originalDtstart;
|
|
868
|
+
let matchCount = 0;
|
|
869
|
+
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
870
|
+
if (iterator && !iterator(start, matchCount)) {
|
|
871
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
872
|
+
}
|
|
873
|
+
dates.push(start);
|
|
874
|
+
matchCount++;
|
|
875
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
876
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
877
|
+
}
|
|
744
878
|
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
879
|
+
let year = start.year;
|
|
880
|
+
const yearDays = [...this.opts.byYearDay].sort((a, b) => a - b);
|
|
881
|
+
const interval = this.opts.interval;
|
|
882
|
+
const startMonthAbs = start.year * 12 + start.month;
|
|
883
|
+
outer_loop: while (true) {
|
|
884
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
885
|
+
break;
|
|
886
|
+
}
|
|
887
|
+
if (++iterationCount > this.maxIterations) {
|
|
888
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
889
|
+
}
|
|
890
|
+
const yearStart = start.with({ year, month: 1, day: 1 });
|
|
891
|
+
const lastDayOfYear = yearStart.with({ month: 12, day: 31 }).dayOfYear;
|
|
892
|
+
for (const yd of yearDays) {
|
|
893
|
+
const dayNum = yd > 0 ? yd : lastDayOfYear + yd + 1;
|
|
894
|
+
if (dayNum <= 0 || dayNum > lastDayOfYear) continue;
|
|
895
|
+
const baseOcc = yearStart.add({ days: dayNum - 1 });
|
|
896
|
+
for (const occ of this.expandByTime(baseOcc)) {
|
|
897
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
898
|
+
if (dates.some((d) => import_polyfill.Temporal.ZonedDateTime.compare(d, occ) === 0)) continue;
|
|
899
|
+
const occMonthAbs = occ.year * 12 + occ.month;
|
|
900
|
+
if ((occMonthAbs - startMonthAbs) % interval !== 0) {
|
|
901
|
+
continue;
|
|
902
|
+
}
|
|
903
|
+
if (!this.matchesByMonth(occ)) {
|
|
904
|
+
continue;
|
|
905
|
+
}
|
|
906
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
907
|
+
break outer_loop;
|
|
908
|
+
}
|
|
909
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
910
|
+
break outer_loop;
|
|
911
|
+
}
|
|
912
|
+
dates.push(occ);
|
|
913
|
+
matchCount++;
|
|
914
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
915
|
+
break outer_loop;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
year++;
|
|
920
|
+
if (this.opts.until && year > this.opts.until.year + 2) {
|
|
921
|
+
break;
|
|
922
|
+
}
|
|
923
|
+
if (!this.opts.until && this.opts.count) {
|
|
924
|
+
const yearsToScan = Math.ceil(this.opts.count / (this.opts.byYearDay.length || 1)) * interval + 5;
|
|
925
|
+
if (year > start.year + yearsToScan) {
|
|
926
|
+
break;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
749
929
|
}
|
|
930
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
750
931
|
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
932
|
+
if (this.opts.freq === "DAILY" && this.opts.bySetPos) {
|
|
933
|
+
let start = this.originalDtstart;
|
|
934
|
+
let matchCount = 0;
|
|
935
|
+
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
936
|
+
if (iterator && !iterator(start, matchCount)) {
|
|
937
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
938
|
+
}
|
|
939
|
+
dates.push(start);
|
|
940
|
+
matchCount++;
|
|
941
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
942
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
943
|
+
}
|
|
754
944
|
}
|
|
755
|
-
|
|
756
|
-
|
|
945
|
+
let dayCursor = start.with({ hour: 0, minute: 0, second: 0, microsecond: 0, nanosecond: 0 });
|
|
946
|
+
outer_daily: while (true) {
|
|
947
|
+
if (++iterationCount > this.maxIterations) {
|
|
948
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
949
|
+
}
|
|
950
|
+
let dayOccs = this.expandByTime(dayCursor);
|
|
951
|
+
dayOccs = dayOccs.filter((occ) => this.matchesAll(occ));
|
|
952
|
+
dayOccs = this.applyBySetPos(dayOccs);
|
|
953
|
+
for (const occ of dayOccs) {
|
|
954
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(occ, start) < 0) continue;
|
|
955
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(occ, this.opts.until) > 0) {
|
|
956
|
+
break outer_daily;
|
|
957
|
+
}
|
|
958
|
+
if (iterator && !iterator(occ, matchCount)) {
|
|
959
|
+
break outer_daily;
|
|
960
|
+
}
|
|
961
|
+
dates.push(occ);
|
|
962
|
+
matchCount++;
|
|
963
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
964
|
+
break outer_daily;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
dayCursor = dayCursor.add({ days: this.opts.interval });
|
|
757
968
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
969
|
+
} else {
|
|
970
|
+
let current = this.computeFirst();
|
|
971
|
+
let matchCount = 0;
|
|
972
|
+
if (this.includeDtstart && import_polyfill.Temporal.ZonedDateTime.compare(current, this.originalDtstart) > 0) {
|
|
973
|
+
if (iterator && !iterator(this.originalDtstart, matchCount)) {
|
|
974
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
761
975
|
}
|
|
762
|
-
dates.push(
|
|
976
|
+
dates.push(this.originalDtstart);
|
|
763
977
|
matchCount++;
|
|
764
978
|
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
979
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
while (true) {
|
|
983
|
+
if (++iterationCount > this.maxIterations) {
|
|
984
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
985
|
+
}
|
|
986
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(current, this.opts.until) > 0) {
|
|
765
987
|
break;
|
|
766
988
|
}
|
|
989
|
+
if (this.matchesAll(current)) {
|
|
990
|
+
if (iterator && !iterator(current, matchCount)) {
|
|
991
|
+
break;
|
|
992
|
+
}
|
|
993
|
+
dates.push(current);
|
|
994
|
+
matchCount++;
|
|
995
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
996
|
+
break;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
current = this.nextCandidateSameDate(current);
|
|
767
1000
|
}
|
|
768
|
-
current = this.nextCandidateSameDate(current);
|
|
769
1001
|
}
|
|
770
1002
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
771
1003
|
}
|
|
@@ -794,9 +1026,7 @@ var RRuleTemporal = class {
|
|
|
794
1026
|
excludeExDates(dates) {
|
|
795
1027
|
if (!this.opts.exDate || this.opts.exDate.length === 0) return dates;
|
|
796
1028
|
return dates.filter((date) => {
|
|
797
|
-
return !this.opts.exDate.some(
|
|
798
|
-
(exDate) => import_polyfill.Temporal.ZonedDateTime.compare(date, exDate) === 0
|
|
799
|
-
);
|
|
1029
|
+
return !this.opts.exDate.some((exDate) => import_polyfill.Temporal.ZonedDateTime.compare(date, exDate) === 0);
|
|
800
1030
|
});
|
|
801
1031
|
}
|
|
802
1032
|
/**
|
|
@@ -846,140 +1076,20 @@ var RRuleTemporal = class {
|
|
|
846
1076
|
between(after, before, inc = false) {
|
|
847
1077
|
const startInst = after instanceof Date ? import_polyfill.Temporal.Instant.from(after.toISOString()) : after.toInstant();
|
|
848
1078
|
const endInst = before instanceof Date ? import_polyfill.Temporal.Instant.from(before.toISOString()) : before.toInstant();
|
|
849
|
-
const
|
|
850
|
-
|
|
851
|
-
if (
|
|
852
|
-
|
|
853
|
-
outer: while (true) {
|
|
854
|
-
if (++iterationCount > this.maxIterations) {
|
|
855
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
856
|
-
}
|
|
857
|
-
const occs = this.generateMonthlyOccurrences(monthCursor);
|
|
858
|
-
for (const occ of occs) {
|
|
859
|
-
const inst = occ.toInstant();
|
|
860
|
-
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
861
|
-
break outer;
|
|
862
|
-
}
|
|
863
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
864
|
-
if (startOk) {
|
|
865
|
-
results.push(occ);
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
869
|
-
}
|
|
870
|
-
return this.mergeRDates(results, startInst, endInst, inc);
|
|
871
|
-
}
|
|
872
|
-
if (this.opts.freq === "YEARLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
873
|
-
const start = this.originalDtstart;
|
|
874
|
-
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
875
|
-
let yearOffset = 0;
|
|
876
|
-
outer: while (true) {
|
|
877
|
-
if (++iterationCount > this.maxIterations) {
|
|
878
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
879
|
-
}
|
|
880
|
-
const year = start.year + yearOffset * this.opts.interval;
|
|
881
|
-
for (const month of months) {
|
|
882
|
-
let occ = start.with({ year, month });
|
|
883
|
-
occ = this.applyTimeOverride(occ);
|
|
884
|
-
const inst = occ.toInstant();
|
|
885
|
-
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
886
|
-
break outer;
|
|
887
|
-
}
|
|
888
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
889
|
-
if (startOk) {
|
|
890
|
-
results.push(occ);
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
yearOffset++;
|
|
894
|
-
}
|
|
895
|
-
return this.mergeRDates(results, startInst, endInst, inc);
|
|
896
|
-
}
|
|
897
|
-
if (this.opts.freq === "YEARLY" && (this.opts.byDay || this.opts.byMonthDay)) {
|
|
898
|
-
const start = this.originalDtstart;
|
|
899
|
-
let yearCursor = start.with({ month: 1, day: 1 });
|
|
900
|
-
outer_year: while (true) {
|
|
901
|
-
if (++iterationCount > this.maxIterations) {
|
|
902
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
903
|
-
}
|
|
904
|
-
const occs = this.generateYearlyOccurrences(yearCursor);
|
|
905
|
-
for (const occ of occs) {
|
|
906
|
-
const inst = occ.toInstant();
|
|
907
|
-
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
908
|
-
break outer_year;
|
|
909
|
-
}
|
|
910
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
911
|
-
if (startOk) {
|
|
912
|
-
results.push(occ);
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
yearCursor = yearCursor.add({ years: this.opts.interval });
|
|
916
|
-
}
|
|
917
|
-
return this.mergeRDates(results, startInst, endInst, inc);
|
|
918
|
-
}
|
|
919
|
-
if (this.opts.freq === "YEARLY" && (this.opts.byYearDay || this.opts.byWeekNo)) {
|
|
920
|
-
const start = this.originalDtstart;
|
|
921
|
-
let yearCursor = start.with({ month: 1, day: 1 });
|
|
922
|
-
outer_year2: while (true) {
|
|
923
|
-
if (++iterationCount > this.maxIterations) {
|
|
924
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
925
|
-
}
|
|
926
|
-
const occs = this.generateYearlyOccurrences(yearCursor);
|
|
927
|
-
for (const occ of occs) {
|
|
928
|
-
const inst = occ.toInstant();
|
|
929
|
-
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) {
|
|
930
|
-
break outer_year2;
|
|
931
|
-
}
|
|
932
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
933
|
-
if (startOk) {
|
|
934
|
-
results.push(occ);
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
yearCursor = yearCursor.add({ years: this.opts.interval });
|
|
938
|
-
}
|
|
939
|
-
return this.mergeRDates(results, startInst, endInst, inc);
|
|
940
|
-
}
|
|
941
|
-
if (this.opts.freq === "WEEKLY") {
|
|
942
|
-
const startInst2 = after instanceof Date ? import_polyfill.Temporal.Instant.from(after.toISOString()) : after.toInstant();
|
|
943
|
-
const endInst2 = before instanceof Date ? import_polyfill.Temporal.Instant.from(before.toISOString()) : before.toInstant();
|
|
944
|
-
let weekCursor = this.computeFirst();
|
|
945
|
-
const results2 = [];
|
|
946
|
-
outer: while (true) {
|
|
947
|
-
if (++iterationCount > this.maxIterations) {
|
|
948
|
-
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in between()`);
|
|
949
|
-
}
|
|
950
|
-
const occs = this.generateWeeklyOccurrences(weekCursor);
|
|
951
|
-
for (const occ of occs) {
|
|
952
|
-
const inst = occ.toInstant();
|
|
953
|
-
if (inc ? import_polyfill.Temporal.Instant.compare(inst, endInst2) > 0 : import_polyfill.Temporal.Instant.compare(inst, endInst2) >= 0) {
|
|
954
|
-
break outer;
|
|
955
|
-
}
|
|
956
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst2) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst2) > 0;
|
|
957
|
-
if (startOk) {
|
|
958
|
-
results2.push(occ);
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
weekCursor = weekCursor.add({ weeks: this.opts.interval });
|
|
962
|
-
}
|
|
963
|
-
return this.mergeRDates(results2, startInst2, endInst2, inc);
|
|
1079
|
+
const beforeZdt = import_polyfill.Temporal.Instant.from(endInst).toZonedDateTimeISO(this.tzid);
|
|
1080
|
+
const tempOpts = __spreadValues({}, this.opts);
|
|
1081
|
+
if (!tempOpts.until || import_polyfill.Temporal.ZonedDateTime.compare(beforeZdt, tempOpts.until) < 0) {
|
|
1082
|
+
tempOpts.until = beforeZdt;
|
|
964
1083
|
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
if (import_polyfill.Temporal.Instant.compare(inst, endInst) >= 0) break;
|
|
975
|
-
}
|
|
976
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
977
|
-
if (startOk && this.matchesAll(current)) {
|
|
978
|
-
results.push(current);
|
|
979
|
-
}
|
|
980
|
-
current = this.nextCandidateSameDate(current);
|
|
981
|
-
}
|
|
982
|
-
return this.mergeRDates(results, startInst, endInst, inc);
|
|
1084
|
+
delete tempOpts.count;
|
|
1085
|
+
const tempRule = new _RRuleTemporal(tempOpts);
|
|
1086
|
+
const allDates = tempRule.all();
|
|
1087
|
+
return allDates.filter((date) => {
|
|
1088
|
+
const inst = date.toInstant();
|
|
1089
|
+
const afterStart = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
1090
|
+
const beforeEnd = inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) <= 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) < 0;
|
|
1091
|
+
return afterStart && beforeEnd;
|
|
1092
|
+
});
|
|
983
1093
|
}
|
|
984
1094
|
/**
|
|
985
1095
|
* Returns the next occurrence of the rule after a specified date.
|
|
@@ -1022,7 +1132,7 @@ var RRuleTemporal = class {
|
|
|
1022
1132
|
toString() {
|
|
1023
1133
|
const iso = this.originalDtstart.toString({ smallestUnit: "second" }).replace(/[-:]/g, "");
|
|
1024
1134
|
const dtLine = `DTSTART;TZID=${this.tzid}:${iso.slice(0, 15)}`;
|
|
1025
|
-
const
|
|
1135
|
+
const rule = [];
|
|
1026
1136
|
const {
|
|
1027
1137
|
freq,
|
|
1028
1138
|
interval,
|
|
@@ -1030,29 +1140,52 @@ var RRuleTemporal = class {
|
|
|
1030
1140
|
until,
|
|
1031
1141
|
byHour,
|
|
1032
1142
|
byMinute,
|
|
1143
|
+
bySecond,
|
|
1033
1144
|
byDay,
|
|
1034
1145
|
byMonth,
|
|
1035
|
-
byMonthDay
|
|
1146
|
+
byMonthDay,
|
|
1147
|
+
bySetPos,
|
|
1148
|
+
byWeekNo,
|
|
1149
|
+
byYearDay,
|
|
1150
|
+
wkst,
|
|
1151
|
+
rDate,
|
|
1152
|
+
exDate
|
|
1036
1153
|
} = this.opts;
|
|
1037
|
-
|
|
1038
|
-
if (interval !== 1)
|
|
1039
|
-
if (count !== void 0)
|
|
1154
|
+
rule.push(`FREQ=${freq}`);
|
|
1155
|
+
if (interval !== 1) rule.push(`INTERVAL=${interval}`);
|
|
1156
|
+
if (count !== void 0) rule.push(`COUNT=${count}`);
|
|
1040
1157
|
if (until) {
|
|
1041
1158
|
const u = until.toInstant().toString().replace(/[-:]/g, "");
|
|
1042
|
-
|
|
1159
|
+
rule.push(`UNTIL=${u.slice(0, 15)}Z`);
|
|
1160
|
+
}
|
|
1161
|
+
if (byHour) rule.push(`BYHOUR=${byHour.join(",")}`);
|
|
1162
|
+
if (byMinute) rule.push(`BYMINUTE=${byMinute.join(",")}`);
|
|
1163
|
+
if (bySecond) rule.push(`BYSECOND=${bySecond.join(",")}`);
|
|
1164
|
+
if (byDay) rule.push(`BYDAY=${byDay.join(",")}`);
|
|
1165
|
+
if (byMonth) rule.push(`BYMONTH=${byMonth.join(",")}`);
|
|
1166
|
+
if (byMonthDay) rule.push(`BYMONTHDAY=${byMonthDay.join(",")}`);
|
|
1167
|
+
if (bySetPos) rule.push(`BYSETPOS=${bySetPos.join(",")}`);
|
|
1168
|
+
if (byWeekNo) rule.push(`BYWEEKNO=${byWeekNo.join(",")}`);
|
|
1169
|
+
if (byYearDay) rule.push(`BYYEARDAY=${byYearDay.join(",")}`);
|
|
1170
|
+
if (wkst) rule.push(`WKST=${wkst}`);
|
|
1171
|
+
const lines = [dtLine, `RRULE:${rule.join(";")}`];
|
|
1172
|
+
if (rDate) {
|
|
1173
|
+
lines.push(`RDATE:${this.joinDates(rDate)}`);
|
|
1043
1174
|
}
|
|
1044
|
-
if (
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1175
|
+
if (exDate) {
|
|
1176
|
+
lines.push(`EXDATE:${this.joinDates(exDate)}`);
|
|
1177
|
+
}
|
|
1178
|
+
return lines.join("\n");
|
|
1179
|
+
}
|
|
1180
|
+
joinDates(dates) {
|
|
1181
|
+
return dates.map((d) => d.toInstant().toString().replace(/[-:]/g, "").slice(0, 15) + "Z");
|
|
1050
1182
|
}
|
|
1051
1183
|
/**
|
|
1052
1184
|
* Given any date in a month, return all the ZonedDateTimes in that month
|
|
1053
1185
|
* matching your opts.byDay and opts.byMonth (or the single "same day" if no BYDAY).
|
|
1054
1186
|
*/
|
|
1055
1187
|
generateMonthlyOccurrences(sample) {
|
|
1188
|
+
var _a;
|
|
1056
1189
|
const { byDay, byMonth, byMonthDay } = this.opts;
|
|
1057
1190
|
if (byMonth && !byMonth.includes(sample.month)) return [];
|
|
1058
1191
|
const lastDay = sample.with({ day: 1 }).add({ months: 1 }).subtract({ days: 1 }).day;
|
|
@@ -1065,10 +1198,12 @@ var RRuleTemporal = class {
|
|
|
1065
1198
|
return [];
|
|
1066
1199
|
}
|
|
1067
1200
|
const dates = byMonthDayHits.map((d) => sample.with({ day: d }));
|
|
1068
|
-
|
|
1201
|
+
let expanded2 = dates.flatMap((z) => this.expandByTime(z)).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1202
|
+
return expanded2;
|
|
1069
1203
|
}
|
|
1070
1204
|
if (!byDay) {
|
|
1071
|
-
|
|
1205
|
+
const expanded2 = this.expandByTime(sample);
|
|
1206
|
+
return expanded2;
|
|
1072
1207
|
}
|
|
1073
1208
|
const dayMap = {
|
|
1074
1209
|
MO: 1,
|
|
@@ -1088,12 +1223,12 @@ var RRuleTemporal = class {
|
|
|
1088
1223
|
let cursor = sample.with({ day: 1 });
|
|
1089
1224
|
while (cursor.month === sample.month) {
|
|
1090
1225
|
const dow = cursor.dayOfWeek;
|
|
1091
|
-
(buckets[dow]
|
|
1226
|
+
(buckets[dow] || (buckets[dow] = [])).push(cursor.day);
|
|
1092
1227
|
cursor = cursor.add({ days: 1 });
|
|
1093
1228
|
}
|
|
1094
1229
|
const byDayHits = [];
|
|
1095
1230
|
for (const { ord, wd } of tokens) {
|
|
1096
|
-
const list2 = buckets[wd]
|
|
1231
|
+
const list2 = (_a = buckets[wd]) != null ? _a : [];
|
|
1097
1232
|
if (!list2.length) continue;
|
|
1098
1233
|
if (ord === 0) {
|
|
1099
1234
|
for (const d of list2) byDayHits.push(d);
|
|
@@ -1112,7 +1247,6 @@ var RRuleTemporal = class {
|
|
|
1112
1247
|
}
|
|
1113
1248
|
const hits = finalDays.map((d) => sample.with({ day: d }));
|
|
1114
1249
|
let expanded = hits.flatMap((z) => this.expandByTime(z)).sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1115
|
-
expanded = this.applyBySetPos(expanded);
|
|
1116
1250
|
return expanded;
|
|
1117
1251
|
}
|
|
1118
1252
|
/**
|
|
@@ -1121,9 +1255,11 @@ var RRuleTemporal = class {
|
|
|
1121
1255
|
* if BYMONTH is not specified.
|
|
1122
1256
|
*/
|
|
1123
1257
|
generateYearlyOccurrences(sample) {
|
|
1124
|
-
|
|
1258
|
+
var _a;
|
|
1259
|
+
const months = this.opts.byMonth ? [...this.opts.byMonth].sort((a, b) => a - b) : this.opts.byMonthDay ? [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] : [this.originalDtstart.month];
|
|
1125
1260
|
let occs = [];
|
|
1126
|
-
|
|
1261
|
+
const hasOrdinalByDay = this.opts.byDay && this.opts.byDay.some((t) => /^[+-]?\d/.test(t));
|
|
1262
|
+
if (hasOrdinalByDay && !this.opts.byMonth) {
|
|
1127
1263
|
const dayMap = {
|
|
1128
1264
|
MO: 1,
|
|
1129
1265
|
TU: 2,
|
|
@@ -1148,9 +1284,7 @@ var RRuleTemporal = class {
|
|
|
1148
1284
|
const delta = (dec31.dayOfWeek - wd + 7) % 7;
|
|
1149
1285
|
dt = dec31.subtract({ days: delta + 7 * (-ord - 1) });
|
|
1150
1286
|
}
|
|
1151
|
-
|
|
1152
|
-
occs.push(...this.expandByTime(dt));
|
|
1153
|
-
}
|
|
1287
|
+
occs.push(...this.expandByTime(dt));
|
|
1154
1288
|
}
|
|
1155
1289
|
} else if (!this.opts.byYearDay && !this.opts.byWeekNo) {
|
|
1156
1290
|
occs = months.flatMap((m) => {
|
|
@@ -1184,7 +1318,10 @@ var RRuleTemporal = class {
|
|
|
1184
1318
|
const firstWeekStart = jan1.subtract({ days: delta });
|
|
1185
1319
|
const lastWeekDiff = sample.with({ month: 12, day: 31 }).toPlainDate().since(firstWeekStart.toPlainDate()).days;
|
|
1186
1320
|
const lastWeek = Math.floor(lastWeekDiff / 7) + 1;
|
|
1187
|
-
const tokens = this.opts.byDay
|
|
1321
|
+
const tokens = ((_a = this.opts.byDay) == null ? void 0 : _a.length) ? this.opts.byDay.map((tok) => {
|
|
1322
|
+
var _a2;
|
|
1323
|
+
return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
|
|
1324
|
+
}) : [this.opts.wkst || "MO"];
|
|
1188
1325
|
for (const weekNo of this.opts.byWeekNo) {
|
|
1189
1326
|
const weekIndex = weekNo > 0 ? weekNo - 1 : lastWeek + weekNo;
|
|
1190
1327
|
const weekStart = firstWeekStart.add({ weeks: weekIndex });
|
|
@@ -1214,36 +1351,11 @@ var RRuleTemporal = class {
|
|
|
1214
1351
|
}
|
|
1215
1352
|
return out.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1216
1353
|
}
|
|
1217
|
-
mergeRDates(list2, startInst, endInst, inc) {
|
|
1218
|
-
if (!this.opts.rDate) return this.excludeExDates(list2);
|
|
1219
|
-
for (const z of this.opts.rDate) {
|
|
1220
|
-
const inst = z.toInstant();
|
|
1221
|
-
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
1222
|
-
const endOk = inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) <= 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) < 0;
|
|
1223
|
-
if (startOk && endOk) list2.push(z);
|
|
1224
|
-
}
|
|
1225
|
-
list2.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1226
|
-
const dedup = [];
|
|
1227
|
-
for (const d of list2) {
|
|
1228
|
-
if (dedup.length === 0 || import_polyfill.Temporal.ZonedDateTime.compare(d, dedup[dedup.length - 1]) !== 0) {
|
|
1229
|
-
dedup.push(d);
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
return this.excludeExDates(dedup);
|
|
1233
|
-
}
|
|
1234
1354
|
};
|
|
1235
1355
|
|
|
1236
1356
|
// src/totext.ts
|
|
1237
1357
|
var en = {
|
|
1238
|
-
weekdayNames: [
|
|
1239
|
-
"Monday",
|
|
1240
|
-
"Tuesday",
|
|
1241
|
-
"Wednesday",
|
|
1242
|
-
"Thursday",
|
|
1243
|
-
"Friday",
|
|
1244
|
-
"Saturday",
|
|
1245
|
-
"Sunday"
|
|
1246
|
-
],
|
|
1358
|
+
weekdayNames: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
|
1247
1359
|
monthNames: [
|
|
1248
1360
|
"January",
|
|
1249
1361
|
"February",
|
|
@@ -1257,21 +1369,401 @@ var en = {
|
|
|
1257
1369
|
"October",
|
|
1258
1370
|
"November",
|
|
1259
1371
|
"December"
|
|
1260
|
-
]
|
|
1372
|
+
],
|
|
1373
|
+
units: {
|
|
1374
|
+
year: { singular: "year", plural: "years" },
|
|
1375
|
+
month: { singular: "month", plural: "months" },
|
|
1376
|
+
week: { singular: "week", plural: "weeks" },
|
|
1377
|
+
day: { singular: "day", plural: "days" },
|
|
1378
|
+
hour: { singular: "hour", plural: "hours" },
|
|
1379
|
+
minute: { singular: "minute", plural: "minutes" },
|
|
1380
|
+
second: { singular: "second", plural: "seconds" }
|
|
1381
|
+
},
|
|
1382
|
+
words: {
|
|
1383
|
+
every: "every",
|
|
1384
|
+
weekday: "weekday",
|
|
1385
|
+
on: "on",
|
|
1386
|
+
in: "in",
|
|
1387
|
+
on_the: "on the",
|
|
1388
|
+
day_of_month: "day of the month",
|
|
1389
|
+
day_of_year: "day of the year",
|
|
1390
|
+
in_week: "in week",
|
|
1391
|
+
at: "at",
|
|
1392
|
+
at_minute: "at minute",
|
|
1393
|
+
at_second: "at second",
|
|
1394
|
+
until: "until",
|
|
1395
|
+
for: "for",
|
|
1396
|
+
time: "time",
|
|
1397
|
+
times: "times",
|
|
1398
|
+
instance: "instance",
|
|
1399
|
+
week_starts_on: "week starts on",
|
|
1400
|
+
with: "with",
|
|
1401
|
+
additional_date: "additional date",
|
|
1402
|
+
additional_dates: "additional dates",
|
|
1403
|
+
excluding: "excluding",
|
|
1404
|
+
date: "date",
|
|
1405
|
+
dates: "dates",
|
|
1406
|
+
and: "and",
|
|
1407
|
+
last: "last"
|
|
1408
|
+
},
|
|
1409
|
+
ordinal: (n) => {
|
|
1410
|
+
const abs = Math.abs(n);
|
|
1411
|
+
const suffix = abs % 10 === 1 && abs % 100 !== 11 ? "st" : abs % 10 === 2 && abs % 100 !== 12 ? "nd" : abs % 10 === 3 && abs % 100 !== 13 ? "rd" : "th";
|
|
1412
|
+
return n < 0 ? `last` : `${abs}${suffix}`;
|
|
1413
|
+
}
|
|
1414
|
+
};
|
|
1415
|
+
var es = {
|
|
1416
|
+
weekdayNames: ["lunes", "martes", "mi\xE9rcoles", "jueves", "viernes", "s\xE1bado", "domingo"],
|
|
1417
|
+
monthNames: [
|
|
1418
|
+
"enero",
|
|
1419
|
+
"febrero",
|
|
1420
|
+
"marzo",
|
|
1421
|
+
"abril",
|
|
1422
|
+
"mayo",
|
|
1423
|
+
"junio",
|
|
1424
|
+
"julio",
|
|
1425
|
+
"agosto",
|
|
1426
|
+
"septiembre",
|
|
1427
|
+
"octubre",
|
|
1428
|
+
"noviembre",
|
|
1429
|
+
"diciembre"
|
|
1430
|
+
],
|
|
1431
|
+
units: {
|
|
1432
|
+
year: { singular: "a\xF1o", plural: "a\xF1os" },
|
|
1433
|
+
month: { singular: "mes", plural: "meses" },
|
|
1434
|
+
week: { singular: "semana", plural: "semanas" },
|
|
1435
|
+
day: { singular: "d\xEDa", plural: "d\xEDas" },
|
|
1436
|
+
hour: { singular: "hora", plural: "horas" },
|
|
1437
|
+
minute: { singular: "minuto", plural: "minutos" },
|
|
1438
|
+
second: { singular: "segundo", plural: "segundos" }
|
|
1439
|
+
},
|
|
1440
|
+
words: {
|
|
1441
|
+
every: "cada",
|
|
1442
|
+
weekday: "d\xEDa de la semana",
|
|
1443
|
+
on: "en",
|
|
1444
|
+
in: "en",
|
|
1445
|
+
on_the: "el",
|
|
1446
|
+
day_of_month: "d\xEDa del mes",
|
|
1447
|
+
day_of_year: "d\xEDa del a\xF1o",
|
|
1448
|
+
in_week: "en la semana",
|
|
1449
|
+
at: "a las",
|
|
1450
|
+
at_minute: "en el minuto",
|
|
1451
|
+
at_second: "en el segundo",
|
|
1452
|
+
until: "hasta",
|
|
1453
|
+
for: "durante",
|
|
1454
|
+
time: "vez",
|
|
1455
|
+
times: "veces",
|
|
1456
|
+
instance: "ocasi\xF3n",
|
|
1457
|
+
week_starts_on: "la semana comienza el",
|
|
1458
|
+
with: "con",
|
|
1459
|
+
additional_date: "fecha adicional",
|
|
1460
|
+
additional_dates: "fechas adicionales",
|
|
1461
|
+
excluding: "excluyendo",
|
|
1462
|
+
date: "fecha",
|
|
1463
|
+
dates: "fechas",
|
|
1464
|
+
and: "y",
|
|
1465
|
+
last: "\xFAltimo"
|
|
1466
|
+
},
|
|
1467
|
+
ordinal: (n) => n < 0 ? "\xFAltimo" : `${Math.abs(n)}\xBA`
|
|
1468
|
+
};
|
|
1469
|
+
var hi = {
|
|
1470
|
+
weekdayNames: ["\u0938\u094B\u092E\u0935\u093E\u0930", "\u092E\u0902\u0917\u0932\u0935\u093E\u0930", "\u092C\u0941\u0927\u0935\u093E\u0930", "\u0917\u0941\u0930\u0941\u0935\u093E\u0930", "\u0936\u0941\u0915\u094D\u0930\u0935\u093E\u0930", "\u0936\u0928\u093F\u0935\u093E\u0930", "\u0930\u0935\u093F\u0935\u093E\u0930"],
|
|
1471
|
+
monthNames: [
|
|
1472
|
+
"\u091C\u0928\u0935\u0930\u0940",
|
|
1473
|
+
"\u092B\u0930\u0935\u0930\u0940",
|
|
1474
|
+
"\u092E\u093E\u0930\u094D\u091A",
|
|
1475
|
+
"\u0905\u092A\u094D\u0930\u0948\u0932",
|
|
1476
|
+
"\u092E\u0908",
|
|
1477
|
+
"\u091C\u0942\u0928",
|
|
1478
|
+
"\u091C\u0941\u0932\u093E\u0908",
|
|
1479
|
+
"\u0905\u0917\u0938\u094D\u0924",
|
|
1480
|
+
"\u0938\u093F\u0924\u0902\u092C\u0930",
|
|
1481
|
+
"\u0905\u0915\u094D\u091F\u0942\u092C\u0930",
|
|
1482
|
+
"\u0928\u0935\u0902\u092C\u0930",
|
|
1483
|
+
"\u0926\u093F\u0938\u0902\u092C\u0930"
|
|
1484
|
+
],
|
|
1485
|
+
units: {
|
|
1486
|
+
year: { singular: "\u0938\u093E\u0932", plural: "\u0938\u093E\u0932" },
|
|
1487
|
+
month: { singular: "\u092E\u0939\u0940\u0928\u093E", plural: "\u092E\u0939\u0940\u0928\u0947" },
|
|
1488
|
+
week: { singular: "\u0938\u092A\u094D\u0924\u093E\u0939", plural: "\u0938\u092A\u094D\u0924\u093E\u0939" },
|
|
1489
|
+
day: { singular: "\u0926\u093F\u0928", plural: "\u0926\u093F\u0928" },
|
|
1490
|
+
hour: { singular: "\u0918\u0902\u091F\u093E", plural: "\u0918\u0902\u091F\u0947" },
|
|
1491
|
+
minute: { singular: "\u092E\u093F\u0928\u091F", plural: "\u092E\u093F\u0928\u091F" },
|
|
1492
|
+
second: { singular: "\u0938\u0947\u0915\u0902\u0921", plural: "\u0938\u0947\u0915\u0902\u0921" }
|
|
1493
|
+
},
|
|
1494
|
+
words: {
|
|
1495
|
+
every: "\u0939\u0930",
|
|
1496
|
+
weekday: "\u0938\u092A\u094D\u0924\u093E\u0939 \u0915\u093E \u0926\u093F\u0928",
|
|
1497
|
+
on: "\u0915\u094B",
|
|
1498
|
+
in: "\u092E\u0947\u0902",
|
|
1499
|
+
on_the: "\u0915\u094B",
|
|
1500
|
+
day_of_month: "\u092E\u0939\u0940\u0928\u0947 \u0915\u093E \u0926\u093F\u0928",
|
|
1501
|
+
day_of_year: "\u0938\u093E\u0932 \u0915\u093E \u0926\u093F\u0928",
|
|
1502
|
+
in_week: "\u0938\u092A\u094D\u0924\u093E\u0939",
|
|
1503
|
+
at: "\u092A\u0930",
|
|
1504
|
+
at_minute: "\u092E\u093F\u0928\u091F \u092A\u0930",
|
|
1505
|
+
at_second: "\u0938\u0947\u0915\u0902\u0921 \u092A\u0930",
|
|
1506
|
+
until: "\u0924\u0915",
|
|
1507
|
+
for: "\u0915\u0947 \u0932\u093F\u090F",
|
|
1508
|
+
time: "\u092C\u093E\u0930",
|
|
1509
|
+
times: "\u092C\u093E\u0930",
|
|
1510
|
+
instance: "\u092C\u093E\u0930",
|
|
1511
|
+
week_starts_on: "\u0938\u092A\u094D\u0924\u093E\u0939 \u0936\u0941\u0930\u0942 \u0939\u094B\u0924\u093E \u0939\u0948",
|
|
1512
|
+
with: "\u0938\u093E\u0925",
|
|
1513
|
+
additional_date: "\u0905\u0924\u093F\u0930\u093F\u0915\u094D\u0924 \u0924\u093E\u0930\u0940\u0916",
|
|
1514
|
+
additional_dates: "\u0905\u0924\u093F\u0930\u093F\u0915\u094D\u0924 \u0924\u093E\u0930\u0940\u0916\u0947\u0902",
|
|
1515
|
+
excluding: "\u0915\u094B \u091B\u094B\u0921\u093C\u0915\u0930",
|
|
1516
|
+
date: "\u0924\u093E\u0930\u0940\u0916",
|
|
1517
|
+
dates: "\u0924\u093E\u0930\u0940\u0916\u0947\u0902",
|
|
1518
|
+
and: "\u0914\u0930",
|
|
1519
|
+
last: "\u0906\u0916\u093F\u0930\u0940"
|
|
1520
|
+
},
|
|
1521
|
+
ordinal: (n) => n < 0 ? "\u0906\u0916\u093F\u0930\u0940" : `${Math.abs(n)}\u0935\u093E\u0902`
|
|
1522
|
+
};
|
|
1523
|
+
var yue = {
|
|
1524
|
+
weekdayNames: ["\u661F\u671F\u4E00", "\u661F\u671F\u4E8C", "\u661F\u671F\u4E09", "\u661F\u671F\u56DB", "\u661F\u671F\u4E94", "\u661F\u671F\u516D", "\u661F\u671F\u65E5"],
|
|
1525
|
+
monthNames: ["\u4E00\u6708", "\u4E8C\u6708", "\u4E09\u6708", "\u56DB\u6708", "\u4E94\u6708", "\u516D\u6708", "\u4E03\u6708", "\u516B\u6708", "\u4E5D\u6708", "\u5341\u6708", "\u5341\u4E00\u6708", "\u5341\u4E8C\u6708"],
|
|
1526
|
+
units: {
|
|
1527
|
+
year: { singular: "\u5E74", plural: "\u5E74" },
|
|
1528
|
+
month: { singular: "\u6708", plural: "\u6708" },
|
|
1529
|
+
week: { singular: "\u9031", plural: "\u9031" },
|
|
1530
|
+
day: { singular: "\u65E5", plural: "\u65E5" },
|
|
1531
|
+
hour: { singular: "\u5C0F\u6642", plural: "\u5C0F\u6642" },
|
|
1532
|
+
minute: { singular: "\u5206\u9418", plural: "\u5206\u9418" },
|
|
1533
|
+
second: { singular: "\u79D2", plural: "\u79D2" }
|
|
1534
|
+
},
|
|
1535
|
+
words: {
|
|
1536
|
+
every: "\u6BCF",
|
|
1537
|
+
weekday: "\u5E73\u65E5",
|
|
1538
|
+
on: "\u5728",
|
|
1539
|
+
in: "\u65BC",
|
|
1540
|
+
on_the: "\u5728",
|
|
1541
|
+
day_of_month: "\u6708\u7684\u65E5\u5B50",
|
|
1542
|
+
day_of_year: "\u5E74\u7684\u65E5\u5B50",
|
|
1543
|
+
in_week: "\u7B2C",
|
|
1544
|
+
at: "\u5728",
|
|
1545
|
+
at_minute: "\u5728\u7B2C",
|
|
1546
|
+
at_second: "\u5728\u7B2C",
|
|
1547
|
+
until: "\u76F4\u5230",
|
|
1548
|
+
for: "\u5171",
|
|
1549
|
+
time: "\u6B21",
|
|
1550
|
+
times: "\u6B21",
|
|
1551
|
+
instance: "\u6B21",
|
|
1552
|
+
week_starts_on: "\u661F\u671F\u958B\u59CB\u65BC",
|
|
1553
|
+
with: "\u5E36\u6709",
|
|
1554
|
+
additional_date: "\u984D\u5916\u65E5\u671F",
|
|
1555
|
+
additional_dates: "\u984D\u5916\u65E5\u671F",
|
|
1556
|
+
excluding: "\u6392\u9664",
|
|
1557
|
+
date: "\u65E5\u671F",
|
|
1558
|
+
dates: "\u65E5\u671F",
|
|
1559
|
+
and: "\u548C",
|
|
1560
|
+
last: "\u6700\u5F8C"
|
|
1561
|
+
},
|
|
1562
|
+
ordinal: (n) => n < 0 ? "\u6700\u5F8C" : `\u7B2C${Math.abs(n)}`
|
|
1261
1563
|
};
|
|
1262
|
-
var
|
|
1564
|
+
var ar = {
|
|
1565
|
+
weekdayNames: ["\u0627\u0644\u0627\u062B\u0646\u064A\u0646", "\u0627\u0644\u062B\u0644\u0627\u062B\u0627\u0621", "\u0627\u0644\u0623\u0631\u0628\u0639\u0627\u0621", "\u0627\u0644\u062E\u0645\u064A\u0633", "\u0627\u0644\u062C\u0645\u0639\u0629", "\u0627\u0644\u0633\u0628\u062A", "\u0627\u0644\u0623\u062D\u062F"],
|
|
1566
|
+
monthNames: [
|
|
1567
|
+
"\u064A\u0646\u0627\u064A\u0631",
|
|
1568
|
+
"\u0641\u0628\u0631\u0627\u064A\u0631",
|
|
1569
|
+
"\u0645\u0627\u0631\u0633",
|
|
1570
|
+
"\u0623\u0628\u0631\u064A\u0644",
|
|
1571
|
+
"\u0645\u0627\u064A\u0648",
|
|
1572
|
+
"\u064A\u0648\u0646\u064A\u0648",
|
|
1573
|
+
"\u064A\u0648\u0644\u064A\u0648",
|
|
1574
|
+
"\u0623\u063A\u0633\u0637\u0633",
|
|
1575
|
+
"\u0633\u0628\u062A\u0645\u0628\u0631",
|
|
1576
|
+
"\u0623\u0643\u062A\u0648\u0628\u0631",
|
|
1577
|
+
"\u0646\u0648\u0641\u0645\u0628\u0631",
|
|
1578
|
+
"\u062F\u064A\u0633\u0645\u0628\u0631"
|
|
1579
|
+
],
|
|
1580
|
+
units: {
|
|
1581
|
+
year: { singular: "\u0633\u0646\u0629", plural: "\u0633\u0646\u0648\u0627\u062A" },
|
|
1582
|
+
month: { singular: "\u0634\u0647\u0631", plural: "\u0623\u0634\u0647\u0631" },
|
|
1583
|
+
week: { singular: "\u0623\u0633\u0628\u0648\u0639", plural: "\u0623\u0633\u0627\u0628\u064A\u0639" },
|
|
1584
|
+
day: { singular: "\u064A\u0648\u0645", plural: "\u0623\u064A\u0627\u0645" },
|
|
1585
|
+
hour: { singular: "\u0633\u0627\u0639\u0629", plural: "\u0633\u0627\u0639\u0627\u062A" },
|
|
1586
|
+
minute: { singular: "\u062F\u0642\u064A\u0642\u0629", plural: "\u062F\u0642\u0627\u0626\u0642" },
|
|
1587
|
+
second: { singular: "\u062B\u0627\u0646\u064A\u0629", plural: "\u062B\u0648\u0627\u0646\u064A" }
|
|
1588
|
+
},
|
|
1589
|
+
words: {
|
|
1590
|
+
every: "\u0643\u0644",
|
|
1591
|
+
weekday: "\u064A\u0648\u0645 \u0645\u0646 \u0623\u064A\u0627\u0645 \u0627\u0644\u0623\u0633\u0628\u0648\u0639",
|
|
1592
|
+
on: "\u0641\u064A",
|
|
1593
|
+
in: "\u0641\u064A",
|
|
1594
|
+
on_the: "\u0641\u064A \u0627\u0644\u0640",
|
|
1595
|
+
day_of_month: "\u064A\u0648\u0645 \u0645\u0646 \u0627\u0644\u0634\u0647\u0631",
|
|
1596
|
+
day_of_year: "\u064A\u0648\u0645 \u0645\u0646 \u0627\u0644\u0633\u0646\u0629",
|
|
1597
|
+
in_week: "\u0641\u064A \u0627\u0644\u0623\u0633\u0628\u0648\u0639",
|
|
1598
|
+
at: "\u0639\u0646\u062F",
|
|
1599
|
+
at_minute: "\u0641\u064A \u0627\u0644\u062F\u0642\u064A\u0642\u0629",
|
|
1600
|
+
at_second: "\u0641\u064A \u0627\u0644\u062B\u0627\u0646\u064A\u0629",
|
|
1601
|
+
until: "\u062D\u062A\u0649",
|
|
1602
|
+
for: "\u0644\u0645\u062F\u0629",
|
|
1603
|
+
time: "\u0645\u0631\u0629",
|
|
1604
|
+
times: "\u0645\u0631\u0627\u062A",
|
|
1605
|
+
instance: "\u0645\u0631\u0629",
|
|
1606
|
+
week_starts_on: "\u064A\u0628\u062F\u0623 \u0627\u0644\u0623\u0633\u0628\u0648\u0639 \u064A\u0648\u0645",
|
|
1607
|
+
with: "\u0645\u0639",
|
|
1608
|
+
additional_date: "\u062A\u0627\u0631\u064A\u062E \u0625\u0636\u0627\u0641\u064A",
|
|
1609
|
+
additional_dates: "\u062A\u0648\u0627\u0631\u064A\u062E \u0625\u0636\u0627\u0641\u064A\u0629",
|
|
1610
|
+
excluding: "\u0628\u0627\u0633\u062A\u062B\u0646\u0627\u0621",
|
|
1611
|
+
date: "\u062A\u0627\u0631\u064A\u062E",
|
|
1612
|
+
dates: "\u062A\u0648\u0627\u0631\u064A\u062E",
|
|
1613
|
+
and: "\u0648",
|
|
1614
|
+
last: "\u0627\u0644\u0623\u062E\u064A\u0631"
|
|
1615
|
+
},
|
|
1616
|
+
ordinal: (n) => {
|
|
1617
|
+
if (n < 0) return "\u0627\u0644\u0623\u062E\u064A\u0631";
|
|
1618
|
+
const abs = Math.abs(n);
|
|
1619
|
+
const map = {
|
|
1620
|
+
1: "\u0627\u0644\u0623\u0648\u0644",
|
|
1621
|
+
2: "\u0627\u0644\u062B\u0627\u0646\u064A",
|
|
1622
|
+
3: "\u0627\u0644\u062B\u0627\u0644\u062B",
|
|
1623
|
+
4: "\u0627\u0644\u0631\u0627\u0628\u0639",
|
|
1624
|
+
5: "\u0627\u0644\u062E\u0627\u0645\u0633",
|
|
1625
|
+
6: "\u0627\u0644\u0633\u0627\u062F\u0633",
|
|
1626
|
+
7: "\u0627\u0644\u0633\u0627\u0628\u0639",
|
|
1627
|
+
8: "\u0627\u0644\u062B\u0627\u0645\u0646",
|
|
1628
|
+
9: "\u0627\u0644\u062A\u0627\u0633\u0639",
|
|
1629
|
+
10: "\u0627\u0644\u0639\u0627\u0634\u0631",
|
|
1630
|
+
11: "\u0627\u0644\u062D\u0627\u062F\u064A \u0639\u0634\u0631",
|
|
1631
|
+
12: "\u0627\u0644\u062B\u0627\u0646\u064A \u0639\u0634\u0631",
|
|
1632
|
+
13: "\u0627\u0644\u062B\u0627\u0644\u062B \u0639\u0634\u0631"
|
|
1633
|
+
};
|
|
1634
|
+
return map[abs] || abs.toString();
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
var he = {
|
|
1638
|
+
weekdayNames: ["\u05D9\u05D5\u05DD \u05E9\u05E0\u05D9", "\u05D9\u05D5\u05DD \u05E9\u05DC\u05D9\u05E9\u05D9", "\u05D9\u05D5\u05DD \u05E8\u05D1\u05D9\u05E2\u05D9", "\u05D9\u05D5\u05DD \u05D7\u05DE\u05D9\u05E9\u05D9", "\u05D9\u05D5\u05DD \u05E9\u05D9\u05E9\u05D9", "\u05D9\u05D5\u05DD \u05E9\u05D1\u05EA", "\u05D9\u05D5\u05DD \u05E8\u05D0\u05E9\u05D5\u05DF"],
|
|
1639
|
+
monthNames: [
|
|
1640
|
+
"\u05D9\u05E0\u05D5\u05D0\u05E8",
|
|
1641
|
+
"\u05E4\u05D1\u05E8\u05D5\u05D0\u05E8",
|
|
1642
|
+
"\u05DE\u05E8\u05E5",
|
|
1643
|
+
"\u05D0\u05E4\u05E8\u05D9\u05DC",
|
|
1644
|
+
"\u05DE\u05D0\u05D9",
|
|
1645
|
+
"\u05D9\u05D5\u05E0\u05D9",
|
|
1646
|
+
"\u05D9\u05D5\u05DC\u05D9",
|
|
1647
|
+
"\u05D0\u05D5\u05D2\u05D5\u05E1\u05D8",
|
|
1648
|
+
"\u05E1\u05E4\u05D8\u05DE\u05D1\u05E8",
|
|
1649
|
+
"\u05D0\u05D5\u05E7\u05D8\u05D5\u05D1\u05E8",
|
|
1650
|
+
"\u05E0\u05D5\u05D1\u05DE\u05D1\u05E8",
|
|
1651
|
+
"\u05D3\u05E6\u05DE\u05D1\u05E8"
|
|
1652
|
+
],
|
|
1653
|
+
units: {
|
|
1654
|
+
year: { singular: "\u05E9\u05E0\u05D4", plural: "\u05E9\u05E0\u05D9\u05DD" },
|
|
1655
|
+
month: { singular: "\u05D7\u05D5\u05D3\u05E9", plural: "\u05D7\u05D5\u05D3\u05E9\u05D9\u05DD" },
|
|
1656
|
+
week: { singular: "\u05E9\u05D1\u05D5\u05E2", plural: "\u05E9\u05D1\u05D5\u05E2\u05D5\u05EA" },
|
|
1657
|
+
day: { singular: "\u05D9\u05D5\u05DD", plural: "\u05D9\u05DE\u05D9\u05DD" },
|
|
1658
|
+
hour: { singular: "\u05E9\u05E2\u05D4", plural: "\u05E9\u05E2\u05D5\u05EA" },
|
|
1659
|
+
minute: { singular: "\u05D3\u05E7\u05D4", plural: "\u05D3\u05E7\u05D5\u05EA" },
|
|
1660
|
+
second: { singular: "\u05E9\u05E0\u05D9\u05D4", plural: "\u05E9\u05E0\u05D9\u05D5\u05EA" }
|
|
1661
|
+
},
|
|
1662
|
+
words: {
|
|
1663
|
+
every: "\u05DB\u05DC",
|
|
1664
|
+
weekday: "\u05D9\u05D5\u05DD \u05D7\u05D5\u05DC",
|
|
1665
|
+
on: "\u05D1",
|
|
1666
|
+
in: "\u05D1",
|
|
1667
|
+
on_the: "\u05D1",
|
|
1668
|
+
day_of_month: "\u05D9\u05D5\u05DD \u05D1\u05D7\u05D5\u05D3\u05E9",
|
|
1669
|
+
day_of_year: "\u05D9\u05D5\u05DD \u05D1\u05E9\u05E0\u05D4",
|
|
1670
|
+
in_week: "\u05D1\u05E9\u05D1\u05D5\u05E2",
|
|
1671
|
+
at: "\u05D1\u05E9\u05E2\u05D4",
|
|
1672
|
+
at_minute: "\u05D1\u05D3\u05E7\u05D4",
|
|
1673
|
+
at_second: "\u05D1\u05E9\u05E0\u05D9\u05D4",
|
|
1674
|
+
until: "\u05E2\u05D3",
|
|
1675
|
+
for: "\u05D1\u05DE\u05E9\u05DA",
|
|
1676
|
+
time: "\u05E4\u05E2\u05DD",
|
|
1677
|
+
times: "\u05E4\u05E2\u05DE\u05D9\u05DD",
|
|
1678
|
+
instance: "\u05E4\u05E2\u05DD",
|
|
1679
|
+
week_starts_on: "\u05E9\u05D1\u05D5\u05E2 \u05DE\u05EA\u05D7\u05D9\u05DC \u05D1",
|
|
1680
|
+
with: "\u05E2\u05DD",
|
|
1681
|
+
additional_date: "\u05EA\u05D0\u05E8\u05D9\u05DA \u05E0\u05D5\u05E1\u05E3",
|
|
1682
|
+
additional_dates: "\u05EA\u05D0\u05E8\u05D9\u05DB\u05D9\u05DD \u05E0\u05D5\u05E1\u05E4\u05D9\u05DD",
|
|
1683
|
+
excluding: "\u05DC\u05DE\u05E2\u05D8",
|
|
1684
|
+
date: "\u05EA\u05D0\u05E8\u05D9\u05DA",
|
|
1685
|
+
dates: "\u05EA\u05D0\u05E8\u05D9\u05DB\u05D9\u05DD",
|
|
1686
|
+
and: "\u05D5",
|
|
1687
|
+
last: "\u05D0\u05D7\u05E8\u05D5\u05DF"
|
|
1688
|
+
},
|
|
1689
|
+
ordinal: (n) => {
|
|
1690
|
+
if (n < 0) return "\u05D0\u05D7\u05E8\u05D5\u05DF";
|
|
1691
|
+
const abs = Math.abs(n);
|
|
1692
|
+
const map = {
|
|
1693
|
+
1: "\u05E8\u05D0\u05E9\u05D5\u05DF",
|
|
1694
|
+
2: "\u05E9\u05E0\u05D9",
|
|
1695
|
+
3: "\u05E9\u05DC\u05D9\u05E9\u05D9",
|
|
1696
|
+
4: "\u05E8\u05D1\u05D9\u05E2\u05D9",
|
|
1697
|
+
5: "\u05D7\u05DE\u05D9\u05E9\u05D9",
|
|
1698
|
+
6: "\u05E9\u05D9\u05E9\u05D9",
|
|
1699
|
+
7: "\u05E9\u05D1\u05D9\u05E2\u05D9",
|
|
1700
|
+
8: "\u05E9\u05DE\u05D9\u05E0\u05D9",
|
|
1701
|
+
9: "\u05EA\u05E9\u05D9\u05E2\u05D9",
|
|
1702
|
+
10: "\u05E2\u05E9\u05D9\u05E8\u05D9",
|
|
1703
|
+
11: "\u05D0\u05D7\u05D3 \u05E2\u05E9\u05E8",
|
|
1704
|
+
12: "\u05E9\u05E0\u05D9\u05DD \u05E2\u05E9\u05E8",
|
|
1705
|
+
13: "\u05E9\u05DC\u05D5\u05E9\u05D4 \u05E2\u05E9\u05E8"
|
|
1706
|
+
};
|
|
1707
|
+
return map[abs] || abs.toString();
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
var zh = {
|
|
1711
|
+
weekdayNames: ["\u661F\u671F\u4E00", "\u661F\u671F\u4E8C", "\u661F\u671F\u4E09", "\u661F\u671F\u56DB", "\u661F\u671F\u4E94", "\u661F\u671F\u516D", "\u661F\u671F\u65E5"],
|
|
1712
|
+
monthNames: ["\u4E00\u6708", "\u4E8C\u6708", "\u4E09\u6708", "\u56DB\u6708", "\u4E94\u6708", "\u516D\u6708", "\u4E03\u6708", "\u516B\u6708", "\u4E5D\u6708", "\u5341\u6708", "\u5341\u4E00\u6708", "\u5341\u4E8C\u6708"],
|
|
1713
|
+
units: {
|
|
1714
|
+
year: { singular: "\u5E74", plural: "\u5E74" },
|
|
1715
|
+
month: { singular: "\u6708", plural: "\u6708" },
|
|
1716
|
+
week: { singular: "\u5468", plural: "\u5468" },
|
|
1717
|
+
day: { singular: "\u65E5", plural: "\u65E5" },
|
|
1718
|
+
hour: { singular: "\u5C0F\u65F6", plural: "\u5C0F\u65F6" },
|
|
1719
|
+
minute: { singular: "\u5206\u949F", plural: "\u5206\u949F" },
|
|
1720
|
+
second: { singular: "\u79D2", plural: "\u79D2" }
|
|
1721
|
+
},
|
|
1722
|
+
words: {
|
|
1723
|
+
every: "\u6BCF",
|
|
1724
|
+
weekday: "\u5DE5\u4F5C\u65E5",
|
|
1725
|
+
on: "\u5728",
|
|
1726
|
+
in: "\u5728",
|
|
1727
|
+
on_the: "\u5728",
|
|
1728
|
+
day_of_month: "\u6708\u7684\u65E5\u5B50",
|
|
1729
|
+
day_of_year: "\u5E74\u7684\u65E5\u5B50",
|
|
1730
|
+
in_week: "\u7B2C",
|
|
1731
|
+
at: "\u5728",
|
|
1732
|
+
at_minute: "\u5728\u7B2C",
|
|
1733
|
+
at_second: "\u5728\u7B2C",
|
|
1734
|
+
until: "\u76F4\u5230",
|
|
1735
|
+
for: "\u5171",
|
|
1736
|
+
time: "\u6B21",
|
|
1737
|
+
times: "\u6B21",
|
|
1738
|
+
instance: "\u6B21",
|
|
1739
|
+
week_starts_on: "\u661F\u671F\u5F00\u59CB\u4E8E",
|
|
1740
|
+
with: "\u5E26\u6709",
|
|
1741
|
+
additional_date: "\u989D\u5916\u65E5\u671F",
|
|
1742
|
+
additional_dates: "\u989D\u5916\u65E5\u671F",
|
|
1743
|
+
excluding: "\u6392\u9664",
|
|
1744
|
+
date: "\u65E5\u671F",
|
|
1745
|
+
dates: "\u65E5\u671F",
|
|
1746
|
+
and: "\u548C",
|
|
1747
|
+
last: "\u6700\u540E"
|
|
1748
|
+
},
|
|
1749
|
+
ordinal: (n) => n < 0 ? "\u6700\u540E" : `\u7B2C${Math.abs(n)}`
|
|
1750
|
+
};
|
|
1751
|
+
var ALL_LOCALES = { en, es, hi, yue, ar, he, zh };
|
|
1263
1752
|
var env = process.env.TOTEXT_LANGS;
|
|
1264
1753
|
var active = env ? env.split(",").map((s) => s.trim()).filter(Boolean) : Object.keys(ALL_LOCALES);
|
|
1265
1754
|
var LOCALES = {};
|
|
1266
1755
|
for (const l of active) {
|
|
1267
1756
|
if (ALL_LOCALES[l]) LOCALES[l] = ALL_LOCALES[l];
|
|
1268
1757
|
}
|
|
1269
|
-
function
|
|
1758
|
+
function defaultOrdinal(n) {
|
|
1270
1759
|
const abs = Math.abs(n);
|
|
1271
1760
|
const suffix = abs % 10 === 1 && abs % 100 !== 11 ? "st" : abs % 10 === 2 && abs % 100 !== 12 ? "nd" : abs % 10 === 3 && abs % 100 !== 13 ? "rd" : "th";
|
|
1272
1761
|
return n < 0 ? `last` : `${abs}${suffix}`;
|
|
1273
1762
|
}
|
|
1274
|
-
function
|
|
1763
|
+
function ordinal(n, locale) {
|
|
1764
|
+
return locale.ordinal ? locale.ordinal(n) : defaultOrdinal(n);
|
|
1765
|
+
}
|
|
1766
|
+
function list(arr, mapFn = (x) => `${x}`, final) {
|
|
1275
1767
|
const mapped = arr.map(mapFn);
|
|
1276
1768
|
if (mapped.length === 1) return mapped[0];
|
|
1277
1769
|
return mapped.slice(0, -1).join(", ") + ` ${final} ` + mapped[mapped.length - 1];
|
|
@@ -1293,8 +1785,8 @@ function formatByDayToken(tok, locale) {
|
|
|
1293
1785
|
const idx = weekdayMap[m[2]];
|
|
1294
1786
|
const name = locale.weekdayNames[idx];
|
|
1295
1787
|
if (ord === 0) return name;
|
|
1296
|
-
if (ord === -1) return
|
|
1297
|
-
return `${ordinal(ord)} ${name}`;
|
|
1788
|
+
if (ord === -1) return `${locale.words.last} ${name}`;
|
|
1789
|
+
return `${ordinal(ord, locale)} ${name}`;
|
|
1298
1790
|
}
|
|
1299
1791
|
function formatTime(hour, minute = 0, second = 0) {
|
|
1300
1792
|
const hr12 = (hour + 11) % 12 + 1;
|
|
@@ -1316,12 +1808,12 @@ function tzAbbreviation(zdt) {
|
|
|
1316
1808
|
hour: "numeric"
|
|
1317
1809
|
}).formatToParts(new Date(zdt.epochMilliseconds));
|
|
1318
1810
|
const tzPart = parts.find((p) => p.type === "timeZoneName");
|
|
1319
|
-
return tzPart
|
|
1811
|
+
return (tzPart == null ? void 0 : tzPart.value) || zdt.timeZoneId;
|
|
1320
1812
|
}
|
|
1321
1813
|
function toText(input, locale) {
|
|
1322
1814
|
const rule = typeof input === "string" ? new RRuleTemporal({ rruleString: input }) : input;
|
|
1323
1815
|
const opts = rule.options();
|
|
1324
|
-
const lang = (locale
|
|
1816
|
+
const lang = (locale != null ? locale : Intl.DateTimeFormat().resolvedOptions().locale).split("-")[0];
|
|
1325
1817
|
const data = LOCALES[lang] || en;
|
|
1326
1818
|
const {
|
|
1327
1819
|
freq,
|
|
@@ -1341,8 +1833,8 @@ function toText(input, locale) {
|
|
|
1341
1833
|
rDate,
|
|
1342
1834
|
exDate
|
|
1343
1835
|
} = opts;
|
|
1344
|
-
const parts = [
|
|
1345
|
-
const
|
|
1836
|
+
const parts = [data.words.every];
|
|
1837
|
+
const baseKey = {
|
|
1346
1838
|
YEARLY: "year",
|
|
1347
1839
|
MONTHLY: "month",
|
|
1348
1840
|
WEEKLY: "week",
|
|
@@ -1351,70 +1843,97 @@ function toText(input, locale) {
|
|
|
1351
1843
|
MINUTELY: "minute",
|
|
1352
1844
|
SECONDLY: "second"
|
|
1353
1845
|
}[freq];
|
|
1354
|
-
const
|
|
1846
|
+
const base = data.units[baseKey];
|
|
1847
|
+
const daysNormalized = byDay == null ? void 0 : byDay.map((d) => d.toUpperCase());
|
|
1355
1848
|
const isWeekdays = daysNormalized && daysNormalized.length === 5 && ["MO", "TU", "WE", "TH", "FR"].every((d) => daysNormalized.includes(d));
|
|
1356
1849
|
const isEveryday = daysNormalized && daysNormalized.length === 7 && ["MO", "TU", "WE", "TH", "FR", "SA", "SU"].every((d) => daysNormalized.includes(d));
|
|
1357
1850
|
if (freq === "WEEKLY" && interval === 1 && isWeekdays) {
|
|
1358
|
-
parts.push(
|
|
1851
|
+
parts.push(data.words.weekday);
|
|
1359
1852
|
} else if (freq === "WEEKLY" && interval === 1 && isEveryday) {
|
|
1360
|
-
parts.push(
|
|
1853
|
+
parts.push(data.units.day.singular);
|
|
1361
1854
|
} else {
|
|
1362
1855
|
if (interval !== 1) {
|
|
1363
|
-
parts.push(interval.toString(), base
|
|
1856
|
+
parts.push(interval.toString(), base.plural);
|
|
1364
1857
|
} else {
|
|
1365
|
-
parts.push(base);
|
|
1858
|
+
parts.push(base.singular);
|
|
1366
1859
|
}
|
|
1367
1860
|
}
|
|
1368
1861
|
if (freq === "WEEKLY" && byDay && !isWeekdays && !isEveryday) {
|
|
1369
|
-
parts.push(
|
|
1862
|
+
parts.push(
|
|
1863
|
+
data.words.on,
|
|
1864
|
+
list(byDay, (t) => formatByDayToken(t, data), data.words.and)
|
|
1865
|
+
);
|
|
1370
1866
|
} else if (byDay && freq !== "WEEKLY") {
|
|
1371
|
-
parts.push(
|
|
1867
|
+
parts.push(
|
|
1868
|
+
data.words.on,
|
|
1869
|
+
list(byDay, (t) => formatByDayToken(t, data), data.words.and)
|
|
1870
|
+
);
|
|
1372
1871
|
}
|
|
1373
1872
|
if (byMonth) {
|
|
1374
|
-
parts.push(
|
|
1873
|
+
parts.push(
|
|
1874
|
+
data.words.in,
|
|
1875
|
+
list(byMonth, (m) => data.monthNames[m - 1], data.words.and)
|
|
1876
|
+
);
|
|
1375
1877
|
}
|
|
1376
1878
|
if (byMonthDay) {
|
|
1377
|
-
parts.push(
|
|
1879
|
+
parts.push(
|
|
1880
|
+
data.words.on_the,
|
|
1881
|
+
list(byMonthDay, (d) => ordinal(d, data), data.words.and),
|
|
1882
|
+
data.words.day_of_month
|
|
1883
|
+
);
|
|
1378
1884
|
}
|
|
1379
1885
|
if (byYearDay) {
|
|
1380
|
-
parts.push(
|
|
1886
|
+
parts.push(
|
|
1887
|
+
data.words.on_the,
|
|
1888
|
+
list(byYearDay, (d) => ordinal(d, data), data.words.and),
|
|
1889
|
+
data.words.day_of_year
|
|
1890
|
+
);
|
|
1381
1891
|
}
|
|
1382
1892
|
if (byWeekNo) {
|
|
1383
|
-
parts.push(
|
|
1893
|
+
parts.push(
|
|
1894
|
+
data.words.in_week,
|
|
1895
|
+
list(byWeekNo, (n) => n.toString(), data.words.and)
|
|
1896
|
+
);
|
|
1384
1897
|
}
|
|
1385
1898
|
if (byHour) {
|
|
1386
|
-
const minutes = byMinute
|
|
1387
|
-
const seconds = bySecond
|
|
1388
|
-
const times = byHour.flatMap(
|
|
1389
|
-
|
|
1390
|
-
);
|
|
1391
|
-
parts.push("at", list(times));
|
|
1899
|
+
const minutes = byMinute != null ? byMinute : [0];
|
|
1900
|
+
const seconds = bySecond != null ? bySecond : [0];
|
|
1901
|
+
const times = byHour.flatMap((h) => minutes.flatMap((m) => seconds.map((s) => formatTime(h, m, s))));
|
|
1902
|
+
parts.push(data.words.at, list(times, void 0, data.words.and));
|
|
1392
1903
|
parts.push(tzAbbreviation(opts.dtstart));
|
|
1393
1904
|
}
|
|
1394
1905
|
if (!byHour && byMinute) {
|
|
1395
|
-
parts.push(
|
|
1906
|
+
parts.push(data.words.at_minute, list(byMinute, void 0, data.words.and));
|
|
1396
1907
|
}
|
|
1397
1908
|
if (!byHour && !byMinute && bySecond) {
|
|
1398
|
-
parts.push(
|
|
1909
|
+
parts.push(data.words.at_second, list(bySecond, void 0, data.words.and));
|
|
1399
1910
|
}
|
|
1400
1911
|
if (until) {
|
|
1401
1912
|
const monthName = data.monthNames[until.month - 1];
|
|
1402
|
-
parts.push(
|
|
1913
|
+
parts.push(data.words.until, `${monthName} ${until.day}, ${until.year}`);
|
|
1403
1914
|
} else if (count !== void 0) {
|
|
1404
|
-
parts.push(
|
|
1915
|
+
parts.push(data.words.for, count.toString(), count === 1 ? data.words.time : data.words.times);
|
|
1405
1916
|
}
|
|
1406
1917
|
if (bySetPos) {
|
|
1407
|
-
parts.push(
|
|
1918
|
+
parts.push(
|
|
1919
|
+
data.words.on_the,
|
|
1920
|
+
list(bySetPos, (n) => ordinal(n, data), data.words.and),
|
|
1921
|
+
data.words.instance
|
|
1922
|
+
);
|
|
1408
1923
|
}
|
|
1409
1924
|
if (wkst) {
|
|
1410
1925
|
const wkName = formatByDayToken(wkst, data);
|
|
1411
|
-
parts.push(
|
|
1926
|
+
parts.push(data.words.week_starts_on, wkName);
|
|
1412
1927
|
}
|
|
1413
1928
|
if (rDate && rDate.length) {
|
|
1414
|
-
parts.push(
|
|
1929
|
+
parts.push(
|
|
1930
|
+
data.words.with,
|
|
1931
|
+
`${rDate.length}`,
|
|
1932
|
+
rDate.length === 1 ? data.words.additional_date : data.words.additional_dates
|
|
1933
|
+
);
|
|
1415
1934
|
}
|
|
1416
1935
|
if (exDate && exDate.length) {
|
|
1417
|
-
parts.push(
|
|
1936
|
+
parts.push(data.words.excluding, `${exDate.length}`, exDate.length === 1 ? data.words.date : data.words.dates);
|
|
1418
1937
|
}
|
|
1419
1938
|
return parts.join(" ");
|
|
1420
1939
|
}
|