rrule-temporal 0.3.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/chunk-U2SCUIWP.js +1212 -0
- package/dist/index.cjs +119 -160
- package/dist/index.d.cts +31 -6
- package/dist/index.d.ts +31 -6
- package/dist/index.js +3 -1249
- package/dist/totext.cjs +1424 -0
- package/dist/totext.d.cts +6 -0
- package/dist/totext.d.ts +6 -0
- package/dist/totext.js +192 -0
- package/package.json +9 -3
package/dist/index.cjs
CHANGED
|
@@ -24,60 +24,6 @@ __export(index_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
var import_polyfill = require("@js-temporal/polyfill");
|
|
27
|
-
var WEEKDAY_NAMES = [
|
|
28
|
-
"Monday",
|
|
29
|
-
"Tuesday",
|
|
30
|
-
"Wednesday",
|
|
31
|
-
"Thursday",
|
|
32
|
-
"Friday",
|
|
33
|
-
"Saturday",
|
|
34
|
-
"Sunday"
|
|
35
|
-
];
|
|
36
|
-
var MONTH_NAMES = [
|
|
37
|
-
"January",
|
|
38
|
-
"February",
|
|
39
|
-
"March",
|
|
40
|
-
"April",
|
|
41
|
-
"May",
|
|
42
|
-
"June",
|
|
43
|
-
"July",
|
|
44
|
-
"August",
|
|
45
|
-
"September",
|
|
46
|
-
"October",
|
|
47
|
-
"November",
|
|
48
|
-
"December"
|
|
49
|
-
];
|
|
50
|
-
var defaultDateFormatter = (year, month, day) => `${month} ${day}, ${year}`;
|
|
51
|
-
function ordinal(n) {
|
|
52
|
-
const abs = Math.abs(n);
|
|
53
|
-
const suffix = abs % 10 === 1 && abs % 100 !== 11 ? "st" : abs % 10 === 2 && abs % 100 !== 12 ? "nd" : abs % 10 === 3 && abs % 100 !== 13 ? "rd" : "th";
|
|
54
|
-
return n < 0 ? `last` : `${abs}${suffix}`;
|
|
55
|
-
}
|
|
56
|
-
function list(arr, mapFn = (x) => `${x}`, final = "and") {
|
|
57
|
-
const mapped = arr.map(mapFn);
|
|
58
|
-
if (mapped.length === 1) return mapped[0];
|
|
59
|
-
return mapped.slice(0, -1).join(", ") + ` ${final} ` + mapped[mapped.length - 1];
|
|
60
|
-
}
|
|
61
|
-
function formatByDayToken(tok) {
|
|
62
|
-
if (typeof tok === "number") return tok.toString();
|
|
63
|
-
const m = tok.match(/^([+-]?\d+)?(MO|TU|WE|TH|FR|SA|SU)$/);
|
|
64
|
-
if (!m) return tok;
|
|
65
|
-
const ord = m[1] ? parseInt(m[1], 10) : 0;
|
|
66
|
-
const weekdayMap = {
|
|
67
|
-
MO: 0,
|
|
68
|
-
TU: 1,
|
|
69
|
-
WE: 2,
|
|
70
|
-
TH: 3,
|
|
71
|
-
FR: 4,
|
|
72
|
-
SA: 5,
|
|
73
|
-
SU: 6
|
|
74
|
-
};
|
|
75
|
-
const idx = weekdayMap[m[2]];
|
|
76
|
-
const name = WEEKDAY_NAMES[idx];
|
|
77
|
-
if (ord === 0) return name;
|
|
78
|
-
if (ord === -1) return `last ${name}`;
|
|
79
|
-
return `${ordinal(ord)} ${name}`;
|
|
80
|
-
}
|
|
81
27
|
function unfoldLine(foldedLine) {
|
|
82
28
|
return foldedLine.replace(/\r?\n[ \t]/g, "");
|
|
83
29
|
}
|
|
@@ -206,32 +152,16 @@ function parseRRuleString(input, fallbackDtstart) {
|
|
|
206
152
|
}
|
|
207
153
|
return opts;
|
|
208
154
|
}
|
|
209
|
-
function formatTime(hour, minute = 0) {
|
|
210
|
-
const hr12 = (hour + 11) % 12 + 1;
|
|
211
|
-
const ampm = hour < 12 ? "AM" : "PM";
|
|
212
|
-
if (minute) {
|
|
213
|
-
return `${hr12}:${String(minute).padStart(2, "0")} ${ampm}`;
|
|
214
|
-
}
|
|
215
|
-
return `${hr12} ${ampm}`;
|
|
216
|
-
}
|
|
217
|
-
function tzAbbreviation(zdt) {
|
|
218
|
-
const parts = new Intl.DateTimeFormat("en-US", {
|
|
219
|
-
timeZone: zdt.timeZoneId,
|
|
220
|
-
timeZoneName: "short",
|
|
221
|
-
hour: "numeric"
|
|
222
|
-
}).formatToParts(new Date(zdt.epochMilliseconds));
|
|
223
|
-
const tzPart = parts.find((p) => p.type === "timeZoneName");
|
|
224
|
-
return tzPart?.value || zdt.timeZoneId;
|
|
225
|
-
}
|
|
226
155
|
var RRuleTemporal = class {
|
|
227
156
|
tzid;
|
|
228
157
|
originalDtstart;
|
|
229
158
|
opts;
|
|
230
159
|
maxIterations;
|
|
160
|
+
includeDtstart;
|
|
231
161
|
constructor(params) {
|
|
232
162
|
let manual;
|
|
233
163
|
if ("rruleString" in params) {
|
|
234
|
-
manual = parseRRuleString(params.rruleString);
|
|
164
|
+
manual = { ...params, ...parseRRuleString(params.rruleString) };
|
|
235
165
|
this.tzid = manual.tzid || "UTC";
|
|
236
166
|
this.originalDtstart = manual.dtstart;
|
|
237
167
|
} else {
|
|
@@ -253,6 +183,7 @@ var RRuleTemporal = class {
|
|
|
253
183
|
}
|
|
254
184
|
this.opts = this.sanitizeOpts(manual);
|
|
255
185
|
this.maxIterations = manual.maxIterations ?? 1e4;
|
|
186
|
+
this.includeDtstart = manual.includeDtstart ?? false;
|
|
256
187
|
}
|
|
257
188
|
sanitizeOpts(opts) {
|
|
258
189
|
const validDay = /^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/;
|
|
@@ -546,6 +477,16 @@ var RRuleTemporal = class {
|
|
|
546
477
|
const start = this.originalDtstart;
|
|
547
478
|
let monthCursor = start.with({ day: 1 });
|
|
548
479
|
let matchCount2 = 0;
|
|
480
|
+
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
481
|
+
if (iterator && !iterator(start, matchCount2)) {
|
|
482
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
483
|
+
}
|
|
484
|
+
dates.push(start);
|
|
485
|
+
matchCount2++;
|
|
486
|
+
if (this.shouldBreakForCountLimit(matchCount2)) {
|
|
487
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
549
490
|
outer_month: while (true) {
|
|
550
491
|
if (++iterationCount > this.maxIterations) {
|
|
551
492
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
@@ -575,6 +516,15 @@ var RRuleTemporal = class {
|
|
|
575
516
|
}
|
|
576
517
|
if (this.opts.freq === "WEEKLY") {
|
|
577
518
|
const start = this.originalDtstart;
|
|
519
|
+
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
520
|
+
if (iterator && !iterator(start, 0)) {
|
|
521
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
522
|
+
}
|
|
523
|
+
dates.push(start);
|
|
524
|
+
if (this.shouldBreakForCountLimit(1)) {
|
|
525
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
578
528
|
const dayMap = {
|
|
579
529
|
MO: 1,
|
|
580
530
|
TU: 2,
|
|
@@ -624,8 +574,64 @@ var RRuleTemporal = class {
|
|
|
624
574
|
}
|
|
625
575
|
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
626
576
|
}
|
|
577
|
+
if (this.opts.freq === "MONTHLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
578
|
+
const start = this.originalDtstart;
|
|
579
|
+
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
580
|
+
if (iterator && !iterator(start, 0)) {
|
|
581
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
582
|
+
}
|
|
583
|
+
dates.push(start);
|
|
584
|
+
if (this.shouldBreakForCountLimit(1)) {
|
|
585
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
589
|
+
let monthOffset = 0;
|
|
590
|
+
let matchCount2 = dates.length;
|
|
591
|
+
let startMonthIndex = months.findIndex((m) => m >= start.month);
|
|
592
|
+
if (startMonthIndex === -1) {
|
|
593
|
+
startMonthIndex = 0;
|
|
594
|
+
monthOffset = 1;
|
|
595
|
+
}
|
|
596
|
+
while (true) {
|
|
597
|
+
if (++iterationCount > this.maxIterations) {
|
|
598
|
+
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
599
|
+
}
|
|
600
|
+
const monthIndex = startMonthIndex + monthOffset;
|
|
601
|
+
const targetMonth = months[monthIndex % months.length];
|
|
602
|
+
const yearsToAdd = Math.floor(monthIndex / months.length);
|
|
603
|
+
const candidate = start.with({
|
|
604
|
+
year: start.year + yearsToAdd,
|
|
605
|
+
month: targetMonth
|
|
606
|
+
});
|
|
607
|
+
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(candidate, this.opts.until) > 0) {
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
if (import_polyfill.Temporal.ZonedDateTime.compare(candidate, start) >= 0) {
|
|
611
|
+
if (iterator && !iterator(candidate, matchCount2)) {
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
dates.push(candidate);
|
|
615
|
+
matchCount2++;
|
|
616
|
+
if (this.shouldBreakForCountLimit(matchCount2)) {
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
monthOffset++;
|
|
621
|
+
}
|
|
622
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
623
|
+
}
|
|
627
624
|
if (this.opts.freq === "YEARLY" && this.opts.byMonth && !this.opts.byDay && !this.opts.byMonthDay) {
|
|
628
625
|
const start = this.originalDtstart;
|
|
626
|
+
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
627
|
+
if (iterator && !iterator(start, 0)) {
|
|
628
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
629
|
+
}
|
|
630
|
+
dates.push(start);
|
|
631
|
+
if (this.shouldBreakForCountLimit(1)) {
|
|
632
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
629
635
|
const months = [...this.opts.byMonth].sort((a, b) => a - b);
|
|
630
636
|
let yearOffset = 0;
|
|
631
637
|
let matchCount2 = 0;
|
|
@@ -658,6 +664,15 @@ var RRuleTemporal = class {
|
|
|
658
664
|
}
|
|
659
665
|
if (this.opts.freq === "YEARLY" && (this.opts.byDay || this.opts.byMonthDay)) {
|
|
660
666
|
const start = this.originalDtstart;
|
|
667
|
+
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
668
|
+
if (iterator && !iterator(start, 0)) {
|
|
669
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
670
|
+
}
|
|
671
|
+
dates.push(start);
|
|
672
|
+
if (this.shouldBreakForCountLimit(1)) {
|
|
673
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
661
676
|
let yearCursor = start.with({ month: 1, day: 1 });
|
|
662
677
|
let matchCount2 = 0;
|
|
663
678
|
outer_year: while (true) {
|
|
@@ -685,6 +700,15 @@ var RRuleTemporal = class {
|
|
|
685
700
|
}
|
|
686
701
|
if (this.opts.freq === "YEARLY" && (this.opts.byYearDay || this.opts.byWeekNo)) {
|
|
687
702
|
const start = this.originalDtstart;
|
|
703
|
+
if (this.includeDtstart && !this.matchesAll(start)) {
|
|
704
|
+
if (iterator && !iterator(start, 0)) {
|
|
705
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
706
|
+
}
|
|
707
|
+
dates.push(start);
|
|
708
|
+
if (this.shouldBreakForCountLimit(1)) {
|
|
709
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
688
712
|
let yearCursor = start.with({ month: 1, day: 1 });
|
|
689
713
|
let matchCount2 = 0;
|
|
690
714
|
outer_year2: while (true) {
|
|
@@ -712,6 +736,16 @@ var RRuleTemporal = class {
|
|
|
712
736
|
}
|
|
713
737
|
let current = this.computeFirst();
|
|
714
738
|
let matchCount = 0;
|
|
739
|
+
if (this.includeDtstart && import_polyfill.Temporal.ZonedDateTime.compare(current, this.originalDtstart) > 0) {
|
|
740
|
+
if (iterator && !iterator(this.originalDtstart, matchCount)) {
|
|
741
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
742
|
+
}
|
|
743
|
+
dates.push(this.originalDtstart);
|
|
744
|
+
matchCount++;
|
|
745
|
+
if (this.shouldBreakForCountLimit(matchCount)) {
|
|
746
|
+
return this.applyCountLimitAndMergeRDates(dates, iterator);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
715
749
|
while (true) {
|
|
716
750
|
if (++iterationCount > this.maxIterations) {
|
|
717
751
|
throw new Error(`Maximum iterations (${this.maxIterations}) exceeded in all()`);
|
|
@@ -1012,81 +1046,6 @@ var RRuleTemporal = class {
|
|
|
1012
1046
|
if (byMonthDay) parts.push(`BYMONTHDAY=${byMonthDay.join(",")}`);
|
|
1013
1047
|
return [dtLine, `RRULE:${parts.join(";")}`].join("\n");
|
|
1014
1048
|
}
|
|
1015
|
-
/**
|
|
1016
|
-
* Convert this rule to a human readable English description.
|
|
1017
|
-
*/
|
|
1018
|
-
toText(formatter = defaultDateFormatter) {
|
|
1019
|
-
const {
|
|
1020
|
-
freq,
|
|
1021
|
-
interval = 1,
|
|
1022
|
-
count,
|
|
1023
|
-
until,
|
|
1024
|
-
byDay,
|
|
1025
|
-
byHour,
|
|
1026
|
-
byMinute,
|
|
1027
|
-
byMonth,
|
|
1028
|
-
byMonthDay
|
|
1029
|
-
} = this.opts;
|
|
1030
|
-
const parts = ["every"];
|
|
1031
|
-
const base = {
|
|
1032
|
-
YEARLY: "year",
|
|
1033
|
-
MONTHLY: "month",
|
|
1034
|
-
WEEKLY: "week",
|
|
1035
|
-
DAILY: "day",
|
|
1036
|
-
HOURLY: "hour",
|
|
1037
|
-
MINUTELY: "minute",
|
|
1038
|
-
SECONDLY: "second"
|
|
1039
|
-
}[freq];
|
|
1040
|
-
const daysNormalized = byDay?.map((d) => d.toUpperCase());
|
|
1041
|
-
const isWeekdays = daysNormalized && daysNormalized.length === 5 && ["MO", "TU", "WE", "TH", "FR"].every((d) => daysNormalized.includes(d));
|
|
1042
|
-
const isEveryday = daysNormalized && daysNormalized.length === 7 && ["MO", "TU", "WE", "TH", "FR", "SA", "SU"].every(
|
|
1043
|
-
(d) => daysNormalized.includes(d)
|
|
1044
|
-
);
|
|
1045
|
-
if (freq === "WEEKLY" && interval === 1 && isWeekdays) {
|
|
1046
|
-
parts.push("weekday");
|
|
1047
|
-
} else if (freq === "WEEKLY" && interval === 1 && isEveryday) {
|
|
1048
|
-
parts.push("day");
|
|
1049
|
-
} else {
|
|
1050
|
-
if (interval !== 1) {
|
|
1051
|
-
parts.push(interval.toString(), base + "s");
|
|
1052
|
-
} else {
|
|
1053
|
-
parts.push(base);
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
if (freq === "WEEKLY" && byDay && !isWeekdays && !isEveryday) {
|
|
1057
|
-
parts.push("on", list(byDay, formatByDayToken));
|
|
1058
|
-
} else if (byDay && freq !== "WEEKLY") {
|
|
1059
|
-
parts.push("on", list(byDay, formatByDayToken));
|
|
1060
|
-
}
|
|
1061
|
-
if (byMonth) {
|
|
1062
|
-
parts.push(
|
|
1063
|
-
"in",
|
|
1064
|
-
list(byMonth, (m) => MONTH_NAMES[m - 1])
|
|
1065
|
-
);
|
|
1066
|
-
}
|
|
1067
|
-
if (byMonthDay) {
|
|
1068
|
-
parts.push(
|
|
1069
|
-
"on the",
|
|
1070
|
-
list(byMonthDay, (d) => ordinal(d)),
|
|
1071
|
-
"day of the month"
|
|
1072
|
-
);
|
|
1073
|
-
}
|
|
1074
|
-
if (byHour) {
|
|
1075
|
-
const minutes = byMinute ?? [0];
|
|
1076
|
-
const times = byHour.flatMap((h) => minutes.map((m) => formatTime(h, m)));
|
|
1077
|
-
parts.push("at", list(times));
|
|
1078
|
-
parts.push(tzAbbreviation(this.originalDtstart));
|
|
1079
|
-
}
|
|
1080
|
-
if (until) {
|
|
1081
|
-
parts.push(
|
|
1082
|
-
"until",
|
|
1083
|
-
formatter(until.year, MONTH_NAMES[until.month - 1], until.day)
|
|
1084
|
-
);
|
|
1085
|
-
} else if (count !== void 0) {
|
|
1086
|
-
parts.push("for", count.toString(), count === 1 ? "time" : "times");
|
|
1087
|
-
}
|
|
1088
|
-
return parts.join(" ");
|
|
1089
|
-
}
|
|
1090
1049
|
/**
|
|
1091
1050
|
* Given any date in a month, return all the ZonedDateTimes in that month
|
|
1092
1051
|
* matching your opts.byDay and opts.byMonth (or the single "same day" if no BYDAY).
|
|
@@ -1132,13 +1091,13 @@ var RRuleTemporal = class {
|
|
|
1132
1091
|
}
|
|
1133
1092
|
const byDayHits = [];
|
|
1134
1093
|
for (const { ord, wd } of tokens) {
|
|
1135
|
-
const
|
|
1136
|
-
if (!
|
|
1094
|
+
const list = buckets[wd] ?? [];
|
|
1095
|
+
if (!list.length) continue;
|
|
1137
1096
|
if (ord === 0) {
|
|
1138
|
-
for (const d of
|
|
1097
|
+
for (const d of list) byDayHits.push(d);
|
|
1139
1098
|
} else {
|
|
1140
|
-
const idx = ord > 0 ? ord - 1 :
|
|
1141
|
-
const dayN =
|
|
1099
|
+
const idx = ord > 0 ? ord - 1 : list.length + ord;
|
|
1100
|
+
const dayN = list[idx];
|
|
1142
1101
|
if (dayN) byDayHits.push(dayN);
|
|
1143
1102
|
}
|
|
1144
1103
|
}
|
|
@@ -1241,10 +1200,10 @@ var RRuleTemporal = class {
|
|
|
1241
1200
|
occs = this.applyBySetPos(occs);
|
|
1242
1201
|
return occs;
|
|
1243
1202
|
}
|
|
1244
|
-
applyBySetPos(
|
|
1203
|
+
applyBySetPos(list) {
|
|
1245
1204
|
const { bySetPos } = this.opts;
|
|
1246
|
-
if (!bySetPos || !bySetPos.length) return
|
|
1247
|
-
const sorted = [...
|
|
1205
|
+
if (!bySetPos || !bySetPos.length) return list;
|
|
1206
|
+
const sorted = [...list].sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1248
1207
|
const out = [];
|
|
1249
1208
|
const len = sorted.length;
|
|
1250
1209
|
for (const pos of bySetPos) {
|
|
@@ -1253,17 +1212,17 @@ var RRuleTemporal = class {
|
|
|
1253
1212
|
}
|
|
1254
1213
|
return out.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1255
1214
|
}
|
|
1256
|
-
mergeRDates(
|
|
1257
|
-
if (!this.opts.rDate) return this.excludeExDates(
|
|
1215
|
+
mergeRDates(list, startInst, endInst, inc) {
|
|
1216
|
+
if (!this.opts.rDate) return this.excludeExDates(list);
|
|
1258
1217
|
for (const z of this.opts.rDate) {
|
|
1259
1218
|
const inst = z.toInstant();
|
|
1260
1219
|
const startOk = inc ? import_polyfill.Temporal.Instant.compare(inst, startInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, startInst) > 0;
|
|
1261
1220
|
const endOk = inc ? import_polyfill.Temporal.Instant.compare(inst, endInst) <= 0 : import_polyfill.Temporal.Instant.compare(inst, endInst) < 0;
|
|
1262
|
-
if (startOk && endOk)
|
|
1221
|
+
if (startOk && endOk) list.push(z);
|
|
1263
1222
|
}
|
|
1264
|
-
|
|
1223
|
+
list.sort((a, b) => import_polyfill.Temporal.ZonedDateTime.compare(a, b));
|
|
1265
1224
|
const dedup = [];
|
|
1266
|
-
for (const d of
|
|
1225
|
+
for (const d of list) {
|
|
1267
1226
|
if (dedup.length === 0 || import_polyfill.Temporal.ZonedDateTime.compare(d, dedup[dedup.length - 1]) !== 0) {
|
|
1268
1227
|
dedup.push(d);
|
|
1269
1228
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,28 +1,56 @@
|
|
|
1
1
|
import { Temporal } from '@js-temporal/polyfill';
|
|
2
2
|
|
|
3
|
-
type DateFormatter = (year: number, month: string, day: number) => string;
|
|
4
3
|
type Freq = "YEARLY" | "MONTHLY" | "WEEKLY" | "DAILY" | "HOURLY" | "MINUTELY" | "SECONDLY";
|
|
4
|
+
/**
|
|
5
|
+
* Shared options for all rule constructors.
|
|
6
|
+
*
|
|
7
|
+
* @property tzid - Time zone identifier as defined in RFC 5545 §3.2.19.
|
|
8
|
+
* @property maxIterations - Safety cap when generating occurrences.
|
|
9
|
+
* @property includeDtstart - Include DTSTART even if it does not match the rule.
|
|
10
|
+
*/
|
|
5
11
|
interface BaseOpts {
|
|
6
12
|
tzid?: string;
|
|
7
13
|
maxIterations?: number;
|
|
14
|
+
includeDtstart?: boolean;
|
|
8
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Manual rule definition following the recurrence rule parts defined in
|
|
18
|
+
* RFC 5545 §3.3.10.
|
|
19
|
+
*/
|
|
9
20
|
interface ManualOpts extends BaseOpts {
|
|
21
|
+
/** FREQ: recurrence frequency */
|
|
10
22
|
freq: Freq;
|
|
23
|
+
/** INTERVAL between each occurrence of {@link freq} */
|
|
11
24
|
interval?: number;
|
|
25
|
+
/** COUNT: total number of occurrences */
|
|
12
26
|
count?: number;
|
|
27
|
+
/** UNTIL: last possible occurrence */
|
|
13
28
|
until?: Temporal.ZonedDateTime;
|
|
29
|
+
/** BYHOUR: hours to include (0-23) */
|
|
14
30
|
byHour?: number[];
|
|
31
|
+
/** BYMINUTE: minutes to include (0-59) */
|
|
15
32
|
byMinute?: number[];
|
|
33
|
+
/** BYSECOND: seconds to include (0-59) */
|
|
16
34
|
bySecond?: number[];
|
|
35
|
+
/** BYDAY: list of weekdays e.g. ["MO","WE","FR"] */
|
|
17
36
|
byDay?: string[];
|
|
37
|
+
/** BYMONTH: months of the year (1-12) */
|
|
18
38
|
byMonth?: number[];
|
|
39
|
+
/** BYMONTHDAY: days of the month (1..31 or negative from end) */
|
|
19
40
|
byMonthDay?: number[];
|
|
41
|
+
/** BYYEARDAY: days of the year (1..366 or negative from end) */
|
|
20
42
|
byYearDay?: number[];
|
|
43
|
+
/** BYWEEKNO: ISO week numbers (1..53 or negative from end) */
|
|
21
44
|
byWeekNo?: number[];
|
|
45
|
+
/** BYSETPOS: select n-th occurrence(s) after other filters */
|
|
22
46
|
bySetPos?: number[];
|
|
47
|
+
/** WKST: weekday on which the week starts ("MO".."SU") */
|
|
23
48
|
wkst?: string;
|
|
49
|
+
/** RDATE: additional dates to include */
|
|
24
50
|
rDate?: Temporal.ZonedDateTime[];
|
|
51
|
+
/** EXDATE: exception dates to exclude */
|
|
25
52
|
exDate?: Temporal.ZonedDateTime[];
|
|
53
|
+
/** DTSTART: first occurrence */
|
|
26
54
|
dtstart: Temporal.ZonedDateTime;
|
|
27
55
|
}
|
|
28
56
|
interface IcsOpts extends BaseOpts {
|
|
@@ -34,6 +62,7 @@ declare class RRuleTemporal {
|
|
|
34
62
|
private originalDtstart;
|
|
35
63
|
private opts;
|
|
36
64
|
private maxIterations;
|
|
65
|
+
private includeDtstart;
|
|
37
66
|
constructor(params: {
|
|
38
67
|
rruleString: string;
|
|
39
68
|
} | ManualOpts);
|
|
@@ -109,10 +138,6 @@ declare class RRuleTemporal {
|
|
|
109
138
|
*/
|
|
110
139
|
previous(before?: Date | Temporal.ZonedDateTime, inc?: boolean): Temporal.ZonedDateTime | null;
|
|
111
140
|
toString(): string;
|
|
112
|
-
/**
|
|
113
|
-
* Convert this rule to a human readable English description.
|
|
114
|
-
*/
|
|
115
|
-
toText(formatter?: DateFormatter): string;
|
|
116
141
|
/**
|
|
117
142
|
* Given any date in a month, return all the ZonedDateTimes in that month
|
|
118
143
|
* matching your opts.byDay and opts.byMonth (or the single "same day" if no BYDAY).
|
|
@@ -128,4 +153,4 @@ declare class RRuleTemporal {
|
|
|
128
153
|
private mergeRDates;
|
|
129
154
|
}
|
|
130
155
|
|
|
131
|
-
export { type
|
|
156
|
+
export { type RRuleOptions, RRuleTemporal };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,56 @@
|
|
|
1
1
|
import { Temporal } from '@js-temporal/polyfill';
|
|
2
2
|
|
|
3
|
-
type DateFormatter = (year: number, month: string, day: number) => string;
|
|
4
3
|
type Freq = "YEARLY" | "MONTHLY" | "WEEKLY" | "DAILY" | "HOURLY" | "MINUTELY" | "SECONDLY";
|
|
4
|
+
/**
|
|
5
|
+
* Shared options for all rule constructors.
|
|
6
|
+
*
|
|
7
|
+
* @property tzid - Time zone identifier as defined in RFC 5545 §3.2.19.
|
|
8
|
+
* @property maxIterations - Safety cap when generating occurrences.
|
|
9
|
+
* @property includeDtstart - Include DTSTART even if it does not match the rule.
|
|
10
|
+
*/
|
|
5
11
|
interface BaseOpts {
|
|
6
12
|
tzid?: string;
|
|
7
13
|
maxIterations?: number;
|
|
14
|
+
includeDtstart?: boolean;
|
|
8
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Manual rule definition following the recurrence rule parts defined in
|
|
18
|
+
* RFC 5545 §3.3.10.
|
|
19
|
+
*/
|
|
9
20
|
interface ManualOpts extends BaseOpts {
|
|
21
|
+
/** FREQ: recurrence frequency */
|
|
10
22
|
freq: Freq;
|
|
23
|
+
/** INTERVAL between each occurrence of {@link freq} */
|
|
11
24
|
interval?: number;
|
|
25
|
+
/** COUNT: total number of occurrences */
|
|
12
26
|
count?: number;
|
|
27
|
+
/** UNTIL: last possible occurrence */
|
|
13
28
|
until?: Temporal.ZonedDateTime;
|
|
29
|
+
/** BYHOUR: hours to include (0-23) */
|
|
14
30
|
byHour?: number[];
|
|
31
|
+
/** BYMINUTE: minutes to include (0-59) */
|
|
15
32
|
byMinute?: number[];
|
|
33
|
+
/** BYSECOND: seconds to include (0-59) */
|
|
16
34
|
bySecond?: number[];
|
|
35
|
+
/** BYDAY: list of weekdays e.g. ["MO","WE","FR"] */
|
|
17
36
|
byDay?: string[];
|
|
37
|
+
/** BYMONTH: months of the year (1-12) */
|
|
18
38
|
byMonth?: number[];
|
|
39
|
+
/** BYMONTHDAY: days of the month (1..31 or negative from end) */
|
|
19
40
|
byMonthDay?: number[];
|
|
41
|
+
/** BYYEARDAY: days of the year (1..366 or negative from end) */
|
|
20
42
|
byYearDay?: number[];
|
|
43
|
+
/** BYWEEKNO: ISO week numbers (1..53 or negative from end) */
|
|
21
44
|
byWeekNo?: number[];
|
|
45
|
+
/** BYSETPOS: select n-th occurrence(s) after other filters */
|
|
22
46
|
bySetPos?: number[];
|
|
47
|
+
/** WKST: weekday on which the week starts ("MO".."SU") */
|
|
23
48
|
wkst?: string;
|
|
49
|
+
/** RDATE: additional dates to include */
|
|
24
50
|
rDate?: Temporal.ZonedDateTime[];
|
|
51
|
+
/** EXDATE: exception dates to exclude */
|
|
25
52
|
exDate?: Temporal.ZonedDateTime[];
|
|
53
|
+
/** DTSTART: first occurrence */
|
|
26
54
|
dtstart: Temporal.ZonedDateTime;
|
|
27
55
|
}
|
|
28
56
|
interface IcsOpts extends BaseOpts {
|
|
@@ -34,6 +62,7 @@ declare class RRuleTemporal {
|
|
|
34
62
|
private originalDtstart;
|
|
35
63
|
private opts;
|
|
36
64
|
private maxIterations;
|
|
65
|
+
private includeDtstart;
|
|
37
66
|
constructor(params: {
|
|
38
67
|
rruleString: string;
|
|
39
68
|
} | ManualOpts);
|
|
@@ -109,10 +138,6 @@ declare class RRuleTemporal {
|
|
|
109
138
|
*/
|
|
110
139
|
previous(before?: Date | Temporal.ZonedDateTime, inc?: boolean): Temporal.ZonedDateTime | null;
|
|
111
140
|
toString(): string;
|
|
112
|
-
/**
|
|
113
|
-
* Convert this rule to a human readable English description.
|
|
114
|
-
*/
|
|
115
|
-
toText(formatter?: DateFormatter): string;
|
|
116
141
|
/**
|
|
117
142
|
* Given any date in a month, return all the ZonedDateTimes in that month
|
|
118
143
|
* matching your opts.byDay and opts.byMonth (or the single "same day" if no BYDAY).
|
|
@@ -128,4 +153,4 @@ declare class RRuleTemporal {
|
|
|
128
153
|
private mergeRDates;
|
|
129
154
|
}
|
|
130
155
|
|
|
131
|
-
export { type
|
|
156
|
+
export { type RRuleOptions, RRuleTemporal };
|