rrule-temporal 1.4.5 → 1.4.7
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 +20 -1
- package/dist/{chunk-5IREWES7.js → chunk-Y57KCW63.js} +118 -91
- package/dist/index.cjs +123 -93
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +9 -3
- package/dist/totext.cjs +173 -133
- package/dist/totext.d.cts +5 -2
- package/dist/totext.d.ts +5 -2
- package/dist/totext.js +61 -44
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -49,10 +49,42 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
49
49
|
// src/index.ts
|
|
50
50
|
var index_exports = {};
|
|
51
51
|
__export(index_exports, {
|
|
52
|
-
RRuleTemporal: () => RRuleTemporal
|
|
52
|
+
RRuleTemporal: () => RRuleTemporal,
|
|
53
|
+
allowedFreq: () => allowedFreq,
|
|
54
|
+
allowedWeekdays: () => allowedWeekdays,
|
|
55
|
+
weekdayToIsoDay: () => weekdayToIsoDay
|
|
53
56
|
});
|
|
54
57
|
module.exports = __toCommonJS(index_exports);
|
|
55
58
|
var import_polyfill = require("@js-temporal/polyfill");
|
|
59
|
+
var allowedFreq = ["YEARLY", "MONTHLY", "WEEKLY", "DAILY", "HOURLY", "MINUTELY", "SECONDLY"];
|
|
60
|
+
var allowedWeekdays = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
|
|
61
|
+
var weekdayToIsoDay = {
|
|
62
|
+
MO: 1,
|
|
63
|
+
TU: 2,
|
|
64
|
+
WE: 3,
|
|
65
|
+
TH: 4,
|
|
66
|
+
FR: 5,
|
|
67
|
+
SA: 6,
|
|
68
|
+
SU: 7
|
|
69
|
+
};
|
|
70
|
+
var allowedFreqSet = new Set(allowedFreq);
|
|
71
|
+
var allowedWeekdaysSet = new Set(allowedWeekdays);
|
|
72
|
+
var byDayTokenRegex = new RegExp(`^([+-]?\\d{1,2})?(${allowedWeekdays.join("|")})$`);
|
|
73
|
+
var byDayWeekdaySuffixRegex = new RegExp(`(${allowedWeekdays.join("|")})$`);
|
|
74
|
+
function extractWeekdayToken(token) {
|
|
75
|
+
const m = token.toUpperCase().match(byDayWeekdaySuffixRegex);
|
|
76
|
+
const weekday = m == null ? void 0 : m[1];
|
|
77
|
+
if (!weekday || !allowedWeekdaysSet.has(weekday)) return null;
|
|
78
|
+
return weekday;
|
|
79
|
+
}
|
|
80
|
+
function parseByDayToken(token) {
|
|
81
|
+
const m = token.toUpperCase().match(byDayTokenRegex);
|
|
82
|
+
if (!m) return null;
|
|
83
|
+
const ord = m[1] ? parseInt(m[1], 10) : 0;
|
|
84
|
+
const weekday = m[2];
|
|
85
|
+
if (!weekday || !allowedWeekdaysSet.has(weekday)) return null;
|
|
86
|
+
return { ord, weekday };
|
|
87
|
+
}
|
|
56
88
|
function isIcsOpts(opts) {
|
|
57
89
|
return typeof opts.rruleString === "string";
|
|
58
90
|
}
|
|
@@ -102,7 +134,7 @@ function parseByMonthArray(val) {
|
|
|
102
134
|
return Number.isFinite(n) ? n : t;
|
|
103
135
|
});
|
|
104
136
|
}
|
|
105
|
-
function parseRRuleString(input, targetTimezone, dtstart) {
|
|
137
|
+
function parseRRuleString(input, targetTimezone, dtstart, strict = false) {
|
|
106
138
|
var _a, _b, _c, _d, _e;
|
|
107
139
|
const unfoldedInput = unfoldLine(input).trim();
|
|
108
140
|
let parsedDtstart;
|
|
@@ -194,7 +226,20 @@ function parseRRuleString(input, targetTimezone, dtstart) {
|
|
|
194
226
|
break;
|
|
195
227
|
}
|
|
196
228
|
if (!untilHasTime) {
|
|
197
|
-
|
|
229
|
+
if (strict) {
|
|
230
|
+
throw new Error("UNTIL rule part MUST have the same value type as DTSTART");
|
|
231
|
+
}
|
|
232
|
+
const localEndOfDay = parseIcsDateTime(val, tzid || "UTC", "DATE").with({
|
|
233
|
+
hour: 23,
|
|
234
|
+
minute: 59,
|
|
235
|
+
second: 59,
|
|
236
|
+
millisecond: 0,
|
|
237
|
+
microsecond: 0,
|
|
238
|
+
nanosecond: 0
|
|
239
|
+
});
|
|
240
|
+
const requiresUtc2 = dtstartHasTzid || dtstartIsUtc;
|
|
241
|
+
opts.until = requiresUtc2 ? localEndOfDay.withTimeZone("UTC") : localEndOfDay;
|
|
242
|
+
break;
|
|
198
243
|
}
|
|
199
244
|
const requiresUtc = dtstartHasTzid || dtstartIsUtc;
|
|
200
245
|
if (requiresUtc && !val.endsWith("Z")) {
|
|
@@ -213,7 +258,7 @@ function parseRRuleString(input, targetTimezone, dtstart) {
|
|
|
213
258
|
opts.bySecond = parseNumberArray(val, true);
|
|
214
259
|
break;
|
|
215
260
|
case "BYDAY":
|
|
216
|
-
opts.byDay = val.split(",");
|
|
261
|
+
opts.byDay = val.split(",").map((token) => token.toUpperCase());
|
|
217
262
|
break;
|
|
218
263
|
case "BYMONTH":
|
|
219
264
|
opts.byMonth = parseByMonthArray(val);
|
|
@@ -231,7 +276,7 @@ function parseRRuleString(input, targetTimezone, dtstart) {
|
|
|
231
276
|
opts.bySetPos = parseNumberArray(val);
|
|
232
277
|
break;
|
|
233
278
|
case "WKST":
|
|
234
|
-
opts.wkst = val;
|
|
279
|
+
opts.wkst = val == null ? void 0 : val.toUpperCase();
|
|
235
280
|
break;
|
|
236
281
|
}
|
|
237
282
|
}
|
|
@@ -252,19 +297,19 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
252
297
|
return import_polyfill.Temporal.ZonedDateTime.from(zdt.toString());
|
|
253
298
|
}
|
|
254
299
|
constructor(params) {
|
|
255
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
300
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
256
301
|
let manual;
|
|
257
302
|
if (isIcsOpts(params)) {
|
|
258
|
-
const parsed = parseRRuleString(params.rruleString, params.tzid, params.dtstart);
|
|
303
|
+
const parsed = parseRRuleString(params.rruleString, params.tzid, params.dtstart, (_a = params.strict) != null ? _a : false);
|
|
259
304
|
if (!parsed.dtstart) {
|
|
260
305
|
throw new Error("dtstart is required - provide it either in rruleString or as a separate parameter");
|
|
261
306
|
}
|
|
262
|
-
this.tzid = (
|
|
307
|
+
this.tzid = (_c = (_b = parsed.tzid) != null ? _b : params.tzid) != null ? _c : "UTC";
|
|
263
308
|
this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(parsed.dtstart);
|
|
264
309
|
manual = __spreadProps(__spreadValues({}, parsed), {
|
|
265
310
|
// Allow explicit COUNT/UNTIL overrides when omitted from the RRULE string
|
|
266
|
-
count: (
|
|
267
|
-
until: (
|
|
311
|
+
count: (_d = params.count) != null ? _d : parsed.count,
|
|
312
|
+
until: (_e = params.until) != null ? _e : parsed.until,
|
|
268
313
|
strict: params.strict,
|
|
269
314
|
maxIterations: params.maxIterations,
|
|
270
315
|
includeDtstart: params.includeDtstart,
|
|
@@ -280,7 +325,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
280
325
|
this.originalDtstart = _RRuleTemporal.normalizeToPolyfill(manual.dtstart);
|
|
281
326
|
}
|
|
282
327
|
if (!manual.freq) throw new Error("RRULE must include FREQ");
|
|
283
|
-
manual.interval = (
|
|
328
|
+
manual.interval = (_f = manual.interval) != null ? _f : 1;
|
|
284
329
|
if (manual.interval <= 0) {
|
|
285
330
|
throw new Error("Cannot create RRule: interval must be greater than 0");
|
|
286
331
|
}
|
|
@@ -291,8 +336,8 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
291
336
|
manual.until = _RRuleTemporal.normalizeToPolyfill(manual.until);
|
|
292
337
|
}
|
|
293
338
|
this.opts = this.sanitizeOpts(manual);
|
|
294
|
-
this.maxIterations = (
|
|
295
|
-
this.includeDtstart = (
|
|
339
|
+
this.maxIterations = (_g = manual.maxIterations) != null ? _g : 1e4;
|
|
340
|
+
this.includeDtstart = (_h = manual.includeDtstart) != null ? _h : false;
|
|
296
341
|
}
|
|
297
342
|
sanitizeNumericArray(arr, min, max, allowZero = false, sort = false) {
|
|
298
343
|
if (!arr) return void 0;
|
|
@@ -301,22 +346,20 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
301
346
|
return sort ? sanitized.sort((a, b) => a - b) : sanitized;
|
|
302
347
|
}
|
|
303
348
|
sanitizeByDay(byDay) {
|
|
304
|
-
const
|
|
305
|
-
const
|
|
349
|
+
const days = (byDay != null ? byDay : []).filter((day) => Boolean(day) && typeof day === "string");
|
|
350
|
+
const normalized = [];
|
|
306
351
|
for (const day of days) {
|
|
307
|
-
const
|
|
308
|
-
|
|
352
|
+
const token = day.toUpperCase();
|
|
353
|
+
const parsed = parseByDayToken(token);
|
|
354
|
+
if (!parsed) {
|
|
309
355
|
throw new Error(`Invalid BYDAY value: ${day}`);
|
|
310
356
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const ordInt = parseInt(ord, 10);
|
|
314
|
-
if (ordInt === 0) {
|
|
315
|
-
throw new Error(`Invalid BYDAY value: ${day}`);
|
|
316
|
-
}
|
|
357
|
+
if (parsed.ord === 0 && /^[+-]?\d/.test(token)) {
|
|
358
|
+
throw new Error(`Invalid BYDAY value: ${day}`);
|
|
317
359
|
}
|
|
360
|
+
normalized.push(token);
|
|
318
361
|
}
|
|
319
|
-
return
|
|
362
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
320
363
|
}
|
|
321
364
|
enforceStrictRfc(opts) {
|
|
322
365
|
var _a;
|
|
@@ -347,7 +390,17 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
347
390
|
}
|
|
348
391
|
sanitizeOpts(opts) {
|
|
349
392
|
var _a;
|
|
393
|
+
if (!allowedFreqSet.has(opts.freq)) {
|
|
394
|
+
throw new Error(`Invalid FREQ value: ${opts.freq}`);
|
|
395
|
+
}
|
|
350
396
|
opts.byDay = this.sanitizeByDay(opts.byDay);
|
|
397
|
+
if (opts.wkst) {
|
|
398
|
+
const wkst = opts.wkst.toUpperCase();
|
|
399
|
+
if (!allowedWeekdaysSet.has(wkst)) {
|
|
400
|
+
throw new Error(`Invalid WKST value: ${opts.wkst}`);
|
|
401
|
+
}
|
|
402
|
+
opts.wkst = wkst;
|
|
403
|
+
}
|
|
351
404
|
if (opts.byMonth) {
|
|
352
405
|
const numeric = opts.byMonth.filter((v) => typeof v === "number");
|
|
353
406
|
const stringy = opts.byMonth.filter((v) => typeof v === "string");
|
|
@@ -562,11 +615,8 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
562
615
|
weekStart = firstThursday.subtract({ days: 3 }).add({ weeks: lastWeek + targetWeek });
|
|
563
616
|
}
|
|
564
617
|
if ((_b = this.opts.byDay) == null ? void 0 : _b.length) {
|
|
565
|
-
const dayMap =
|
|
566
|
-
const targetDays = this.opts.byDay.map((tok) =>
|
|
567
|
-
var _a2;
|
|
568
|
-
return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
|
|
569
|
-
}).filter(Boolean).map((day) => dayMap[day]).filter(Boolean);
|
|
618
|
+
const dayMap = weekdayToIsoDay;
|
|
619
|
+
const targetDays = this.opts.byDay.map((tok) => extractWeekdayToken(tok)).filter((day) => day !== null).map((day) => dayMap[day]).filter(Boolean);
|
|
570
620
|
if (targetDays.length) {
|
|
571
621
|
const candidates = targetDays.map((dayOfWeek) => {
|
|
572
622
|
const delta = (dayOfWeek - weekStart.dayOfWeek + 7) % 7;
|
|
@@ -589,7 +639,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
589
639
|
}
|
|
590
640
|
}
|
|
591
641
|
if (((_c = this.opts.byDay) == null ? void 0 : _c.length) && !this.opts.byWeekNo) {
|
|
592
|
-
const dayMap =
|
|
642
|
+
const dayMap = weekdayToIsoDay;
|
|
593
643
|
const hasOrdinalTokens = this.opts.byDay.some((tok) => /^[+-]?\d/.test(tok));
|
|
594
644
|
if (hasOrdinalTokens && this.opts.byMonth && (this.opts.freq === "MINUTELY" || this.opts.freq === "SECONDLY")) {
|
|
595
645
|
const months = this.opts.byMonth.filter((v) => typeof v === "number").sort((a, b) => a - b);
|
|
@@ -615,14 +665,11 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
615
665
|
}
|
|
616
666
|
} else {
|
|
617
667
|
let deltas;
|
|
618
|
-
|
|
619
|
-
|
|
668
|
+
const weekdayTokens = this.opts.byDay.map((tok) => extractWeekdayToken(tok)).filter((tok) => tok !== null);
|
|
669
|
+
if (["DAILY", "HOURLY", "MINUTELY", "SECONDLY"].includes(this.opts.freq) && weekdayTokens.length === this.opts.byDay.length) {
|
|
670
|
+
deltas = weekdayTokens.map((tok) => (dayMap[tok] - zdt.dayOfWeek + 7) % 7);
|
|
620
671
|
} else {
|
|
621
|
-
deltas =
|
|
622
|
-
var _a2;
|
|
623
|
-
const wdTok = (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
|
|
624
|
-
return wdTok ? (dayMap[wdTok] - zdt.dayOfWeek + 7) % 7 : null;
|
|
625
|
-
}).filter((d) => d !== null);
|
|
672
|
+
deltas = weekdayTokens.map((wdTok) => (dayMap[wdTok] - zdt.dayOfWeek + 7) % 7);
|
|
626
673
|
}
|
|
627
674
|
if (deltas.length) {
|
|
628
675
|
zdt = zdt.add({ days: Math.min(...deltas) });
|
|
@@ -664,14 +711,12 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
664
711
|
matchesByDay(zdt) {
|
|
665
712
|
const { byDay, freq } = this.opts;
|
|
666
713
|
if (!byDay) return true;
|
|
667
|
-
const dayMap =
|
|
714
|
+
const dayMap = weekdayToIsoDay;
|
|
668
715
|
for (const token of byDay) {
|
|
669
|
-
const
|
|
670
|
-
if (!
|
|
671
|
-
const ord =
|
|
672
|
-
const
|
|
673
|
-
if (!weekday) continue;
|
|
674
|
-
const wd = dayMap[weekday];
|
|
716
|
+
const parsed = parseByDayToken(token);
|
|
717
|
+
if (!parsed) continue;
|
|
718
|
+
const ord = parsed.ord;
|
|
719
|
+
const wd = dayMap[parsed.weekday];
|
|
675
720
|
if (freq === "DAILY") {
|
|
676
721
|
if (zdt.dayOfWeek === wd) return true;
|
|
677
722
|
continue;
|
|
@@ -925,10 +970,6 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
925
970
|
}
|
|
926
971
|
let occs = this.generateMonthlyOccurrences(monthCursor);
|
|
927
972
|
occs = this.applyBySetPos(occs);
|
|
928
|
-
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)) {
|
|
929
|
-
monthCursor = monthCursor.add({ months: this.opts.interval });
|
|
930
|
-
continue;
|
|
931
|
-
}
|
|
932
973
|
const { shouldBreak } = this.processOccurrences(occs, dates, start, iterator);
|
|
933
974
|
if (shouldBreak) {
|
|
934
975
|
break;
|
|
@@ -938,14 +979,14 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
938
979
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
939
980
|
}
|
|
940
981
|
_allWeekly(iterator) {
|
|
941
|
-
var _a;
|
|
982
|
+
var _a, _b;
|
|
942
983
|
const dates = [];
|
|
943
984
|
let iterationCount = 0;
|
|
944
985
|
const start = this.originalDtstart;
|
|
945
986
|
if (!this.addDtstartIfNeeded(dates, iterator)) {
|
|
946
987
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
947
988
|
}
|
|
948
|
-
const dayMap =
|
|
989
|
+
const dayMap = weekdayToIsoDay;
|
|
949
990
|
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]];
|
|
950
991
|
const dows = tokens.map((tok) => dayMap[tok.slice(-2)]).filter((d) => d !== void 0).sort((a, b) => a - b);
|
|
951
992
|
const firstWeekDates = dows.map((dw) => {
|
|
@@ -953,7 +994,8 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
953
994
|
return start.add({ days: delta });
|
|
954
995
|
});
|
|
955
996
|
const firstOccurrence = firstWeekDates.reduce((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b) <= 0 ? a : b);
|
|
956
|
-
const
|
|
997
|
+
const wkstToken = (_a = extractWeekdayToken(this.opts.wkst || "MO")) != null ? _a : "MO";
|
|
998
|
+
const wkstDay = (_b = dayMap[wkstToken]) != null ? _b : 1;
|
|
957
999
|
const firstOccWeekOffset = (firstOccurrence.dayOfWeek - wkstDay + 7) % 7;
|
|
958
1000
|
let weekCursor = firstOccurrence.subtract({ days: firstOccWeekOffset });
|
|
959
1001
|
while (true) {
|
|
@@ -1773,11 +1815,11 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
1773
1815
|
if (!byDay) {
|
|
1774
1816
|
return this.expandByTime(sample);
|
|
1775
1817
|
}
|
|
1776
|
-
const dayMap =
|
|
1818
|
+
const dayMap = weekdayToIsoDay;
|
|
1777
1819
|
const tokens = byDay.map((tok) => {
|
|
1778
|
-
const
|
|
1779
|
-
if (!
|
|
1780
|
-
return { ord:
|
|
1820
|
+
const parsed = parseByDayToken(tok);
|
|
1821
|
+
if (!parsed) return null;
|
|
1822
|
+
return { ord: parsed.ord, wd: dayMap[parsed.weekday] };
|
|
1781
1823
|
}).filter((x) => x !== null);
|
|
1782
1824
|
const buckets = {};
|
|
1783
1825
|
let cursor = sample.with({ day: 1 });
|
|
@@ -1818,12 +1860,12 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
1818
1860
|
let occs = [];
|
|
1819
1861
|
const hasOrdinalByDay = this.opts.byDay && this.opts.byDay.some((t) => /^[+-]?\d/.test(t));
|
|
1820
1862
|
if (hasOrdinalByDay && !this.opts.byMonth) {
|
|
1821
|
-
const dayMap =
|
|
1863
|
+
const dayMap = weekdayToIsoDay;
|
|
1822
1864
|
for (const tok of this.opts.byDay) {
|
|
1823
|
-
const
|
|
1824
|
-
if (!
|
|
1825
|
-
const ord =
|
|
1826
|
-
const wd = dayMap[
|
|
1865
|
+
const parsed = parseByDayToken(tok);
|
|
1866
|
+
if (!parsed || parsed.ord === 0) continue;
|
|
1867
|
+
const ord = parsed.ord;
|
|
1868
|
+
const wd = dayMap[parsed.weekday];
|
|
1827
1869
|
let dt;
|
|
1828
1870
|
if (ord > 0) {
|
|
1829
1871
|
const jan1 = sample.with({ month: 1, day: 1 });
|
|
@@ -1887,7 +1929,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
1887
1929
|
return occs;
|
|
1888
1930
|
}
|
|
1889
1931
|
addByDay(tokens, weekStart) {
|
|
1890
|
-
const dayMap =
|
|
1932
|
+
const dayMap = weekdayToIsoDay;
|
|
1891
1933
|
const wkst = dayMap[this.opts.wkst || "MO"];
|
|
1892
1934
|
const entries = [];
|
|
1893
1935
|
for (const tok of tokens) {
|
|
@@ -2002,11 +2044,8 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
2002
2044
|
return current;
|
|
2003
2045
|
}
|
|
2004
2046
|
if (this.opts.byDay && !this.matchesByDay(current)) {
|
|
2005
|
-
const dayMap =
|
|
2006
|
-
const targetDays = this.opts.byDay.map((tok) =>
|
|
2007
|
-
var _a;
|
|
2008
|
-
return (_a = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a[1];
|
|
2009
|
-
}).filter(Boolean).map((day) => dayMap[day]).filter(Boolean);
|
|
2047
|
+
const dayMap = weekdayToIsoDay;
|
|
2048
|
+
const targetDays = this.opts.byDay.map((tok) => extractWeekdayToken(tok)).filter((day) => day !== null).map((day) => dayMap[day]).filter(Boolean);
|
|
2010
2049
|
const nextDayOfWeek = this.findNextValidValue(current.dayOfWeek, targetDays.sort(), (a, b) => a - b);
|
|
2011
2050
|
if (nextDayOfWeek) {
|
|
2012
2051
|
const delta = (nextDayOfWeek - current.dayOfWeek + 7) % 7;
|
|
@@ -2051,7 +2090,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
2051
2090
|
}
|
|
2052
2091
|
isoWeekByDay(sample) {
|
|
2053
2092
|
var _a;
|
|
2054
|
-
const dayMap =
|
|
2093
|
+
const dayMap = weekdayToIsoDay;
|
|
2055
2094
|
const wkst = dayMap[this.opts.wkst || "MO"];
|
|
2056
2095
|
const jan1 = sample.with({ month: 1, day: 1 });
|
|
2057
2096
|
const jan4 = sample.with({ month: 1, day: 4 });
|
|
@@ -2059,10 +2098,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
2059
2098
|
const firstWeekStart = jan4.subtract({ days: delta });
|
|
2060
2099
|
const isLeapYear = jan1.inLeapYear;
|
|
2061
2100
|
const lastWeek = jan1.dayOfWeek === 4 || isLeapYear && jan1.dayOfWeek === 3 ? 53 : 52;
|
|
2062
|
-
const tokens = ((_a = this.opts.byDay) == null ? void 0 : _a.length) ? this.opts.byDay.map((tok) =>
|
|
2063
|
-
var _a2;
|
|
2064
|
-
return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
|
|
2065
|
-
}) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
|
|
2101
|
+
const tokens = ((_a = this.opts.byDay) == null ? void 0 : _a.length) ? this.opts.byDay.map((tok) => extractWeekdayToken(tok)).filter((day) => day !== null) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
|
|
2066
2102
|
return { lastWeek, firstWeekStart, tokens };
|
|
2067
2103
|
}
|
|
2068
2104
|
/**
|
|
@@ -2180,7 +2216,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
2180
2216
|
rscaleMatchesByWeekNo(calId, pd) {
|
|
2181
2217
|
const list = this.opts.byWeekNo;
|
|
2182
2218
|
if (!list || list.length === 0) return true;
|
|
2183
|
-
const dayMap =
|
|
2219
|
+
const dayMap = weekdayToIsoDay;
|
|
2184
2220
|
const wkst = dayMap[this.opts.wkst || "MO"];
|
|
2185
2221
|
const weekStart = pd.subtract({ days: (pd.dayOfWeek - wkst + 7) % 7 });
|
|
2186
2222
|
const thursday = weekStart.add({ days: (4 - wkst + 7) % 7 });
|
|
@@ -2205,11 +2241,8 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
2205
2241
|
rscaleMatchesByDayBasic(pd) {
|
|
2206
2242
|
const byDay = this.opts.byDay;
|
|
2207
2243
|
if (!byDay || byDay.length === 0) return true;
|
|
2208
|
-
const dayMap =
|
|
2209
|
-
const tokens = byDay.map((tok) =>
|
|
2210
|
-
var _a;
|
|
2211
|
-
return (_a = tok.match(/^(?:[+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a[1];
|
|
2212
|
-
}).filter((x) => !!x);
|
|
2244
|
+
const dayMap = weekdayToIsoDay;
|
|
2245
|
+
const tokens = byDay.map((tok) => extractWeekdayToken(tok)).filter((x) => x !== null);
|
|
2213
2246
|
if (tokens.length === 0) return true;
|
|
2214
2247
|
return tokens.some((wd) => dayMap[wd] === pd.dayOfWeek);
|
|
2215
2248
|
}
|
|
@@ -2254,7 +2287,7 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
2254
2287
|
}
|
|
2255
2288
|
}
|
|
2256
2289
|
if (byDay && byDay.length > 0) {
|
|
2257
|
-
const dayMap =
|
|
2290
|
+
const dayMap = weekdayToIsoDay;
|
|
2258
2291
|
const buckets = {};
|
|
2259
2292
|
let cur = monthStart;
|
|
2260
2293
|
while (cur.month === monthStart.month && cur.year === monthStart.year) {
|
|
@@ -2263,10 +2296,10 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
2263
2296
|
cur = cur.add({ days: 1 });
|
|
2264
2297
|
}
|
|
2265
2298
|
for (const tok of byDay) {
|
|
2266
|
-
const
|
|
2267
|
-
if (!
|
|
2268
|
-
const ord =
|
|
2269
|
-
const wd = dayMap[
|
|
2299
|
+
const parsed = parseByDayToken(tok);
|
|
2300
|
+
if (!parsed) continue;
|
|
2301
|
+
const ord = parsed.ord;
|
|
2302
|
+
const wd = dayMap[parsed.weekday];
|
|
2270
2303
|
const list = buckets[wd] || [];
|
|
2271
2304
|
if (list.length === 0) continue;
|
|
2272
2305
|
if (ord === 0) {
|
|
@@ -2303,15 +2336,12 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
2303
2336
|
let occs = [];
|
|
2304
2337
|
const monthsTokens = this.opts.byMonth;
|
|
2305
2338
|
const months = this.monthsOfYear(calId, tgtYear);
|
|
2306
|
-
const dayMap =
|
|
2339
|
+
const dayMap = weekdayToIsoDay;
|
|
2307
2340
|
const wkst = dayMap[this.opts.wkst || "MO"];
|
|
2308
2341
|
if (this.opts.byWeekNo && this.opts.byWeekNo.length > 0) {
|
|
2309
2342
|
const firstStart = this.rscaleFirstWeekStart(calId, tgtYear, wkst);
|
|
2310
2343
|
const lastWeek = this.rscaleLastWeekCount(calId, tgtYear, wkst);
|
|
2311
|
-
const tokens = ((_b = this.opts.byDay) == null ? void 0 : _b.length) ? this.opts.byDay.map((tok) =>
|
|
2312
|
-
var _a2;
|
|
2313
|
-
return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
|
|
2314
|
-
}) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
|
|
2344
|
+
const tokens = ((_b = this.opts.byDay) == null ? void 0 : _b.length) ? this.opts.byDay.map((tok) => extractWeekdayToken(tok)).filter((day) => day !== null) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
|
|
2315
2345
|
for (const wn of this.opts.byWeekNo) {
|
|
2316
2346
|
let idx = wn > 0 ? wn - 1 : lastWeek + wn;
|
|
2317
2347
|
if (idx < 0 || idx >= lastWeek) continue;
|
|
@@ -2380,12 +2410,9 @@ var _RRuleTemporal = class _RRuleTemporal {
|
|
|
2380
2410
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
2381
2411
|
}
|
|
2382
2412
|
if (this.opts.freq === "WEEKLY") {
|
|
2383
|
-
const dayMap =
|
|
2413
|
+
const dayMap = weekdayToIsoDay;
|
|
2384
2414
|
const wkst = dayMap[this.opts.wkst || "MO"];
|
|
2385
|
-
const tokens = ((_c = this.opts.byDay) == null ? void 0 : _c.length) ? this.opts.byDay.map((tok) =>
|
|
2386
|
-
var _a2;
|
|
2387
|
-
return (_a2 = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)) == null ? void 0 : _a2[1];
|
|
2388
|
-
}) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
|
|
2415
|
+
const tokens = ((_c = this.opts.byDay) == null ? void 0 : _c.length) ? this.opts.byDay.map((tok) => extractWeekdayToken(tok)).filter((day) => day !== null) : [Object.entries(dayMap).find(([, d]) => d === this.originalDtstart.dayOfWeek)[0]];
|
|
2389
2416
|
let weekStart = seed.toPlainDate().subtract({ days: (seed.dayOfWeek - wkst + 7) % 7 });
|
|
2390
2417
|
while (true) {
|
|
2391
2418
|
if (++iterationCount > this.maxIterations) {
|
|
@@ -2517,5 +2544,8 @@ _RRuleTemporal.rscaleCalendarSupport = {};
|
|
|
2517
2544
|
var RRuleTemporal = _RRuleTemporal;
|
|
2518
2545
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2519
2546
|
0 && (module.exports = {
|
|
2520
|
-
RRuleTemporal
|
|
2547
|
+
RRuleTemporal,
|
|
2548
|
+
allowedFreq,
|
|
2549
|
+
allowedWeekdays,
|
|
2550
|
+
weekdayToIsoDay
|
|
2521
2551
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Temporal } from '@js-temporal/polyfill';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
declare const allowedFreq: readonly ["YEARLY", "MONTHLY", "WEEKLY", "DAILY", "HOURLY", "MINUTELY", "SECONDLY"];
|
|
4
|
+
type Freq = (typeof allowedFreq)[number];
|
|
5
|
+
declare const allowedWeekdays: readonly ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
|
|
6
|
+
type Weekday = (typeof allowedWeekdays)[number];
|
|
7
|
+
declare const weekdayToIsoDay: Record<Weekday, number>;
|
|
4
8
|
/**
|
|
5
9
|
* Shared options for all rule constructors.
|
|
6
10
|
*/
|
|
@@ -263,4 +267,4 @@ declare class RRuleTemporal {
|
|
|
263
267
|
private _allRscaleNonGregorian;
|
|
264
268
|
}
|
|
265
269
|
|
|
266
|
-
export { type RRuleOptions, RRuleTemporal };
|
|
270
|
+
export { type Freq, type RRuleOptions, RRuleTemporal, type Weekday, allowedFreq, allowedWeekdays, weekdayToIsoDay };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Temporal } from '@js-temporal/polyfill';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
declare const allowedFreq: readonly ["YEARLY", "MONTHLY", "WEEKLY", "DAILY", "HOURLY", "MINUTELY", "SECONDLY"];
|
|
4
|
+
type Freq = (typeof allowedFreq)[number];
|
|
5
|
+
declare const allowedWeekdays: readonly ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
|
|
6
|
+
type Weekday = (typeof allowedWeekdays)[number];
|
|
7
|
+
declare const weekdayToIsoDay: Record<Weekday, number>;
|
|
4
8
|
/**
|
|
5
9
|
* Shared options for all rule constructors.
|
|
6
10
|
*/
|
|
@@ -263,4 +267,4 @@ declare class RRuleTemporal {
|
|
|
263
267
|
private _allRscaleNonGregorian;
|
|
264
268
|
}
|
|
265
269
|
|
|
266
|
-
export { type RRuleOptions, RRuleTemporal };
|
|
270
|
+
export { type Freq, type RRuleOptions, RRuleTemporal, type Weekday, allowedFreq, allowedWeekdays, weekdayToIsoDay };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
RRuleTemporal
|
|
3
|
-
|
|
2
|
+
RRuleTemporal,
|
|
3
|
+
allowedFreq,
|
|
4
|
+
allowedWeekdays,
|
|
5
|
+
weekdayToIsoDay
|
|
6
|
+
} from "./chunk-Y57KCW63.js";
|
|
4
7
|
export {
|
|
5
|
-
RRuleTemporal
|
|
8
|
+
RRuleTemporal,
|
|
9
|
+
allowedFreq,
|
|
10
|
+
allowedWeekdays,
|
|
11
|
+
weekdayToIsoDay
|
|
6
12
|
};
|