rrule-temporal 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +25 -33
- package/dist/index.js +25 -33
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -252,9 +252,14 @@ var RRuleTemporal = class {
|
|
|
252
252
|
SA: 6,
|
|
253
253
|
SU: 7
|
|
254
254
|
};
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
255
|
+
const deltas = this.opts.byDay.map((tok) => {
|
|
256
|
+
const wdTok = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)?.[1];
|
|
257
|
+
return wdTok ? (dayMap[wdTok] - zdt.dayOfWeek + 7) % 7 : null;
|
|
258
|
+
}).filter((d) => d !== null);
|
|
259
|
+
if (deltas.length) {
|
|
260
|
+
const delta = Math.min(...deltas);
|
|
261
|
+
zdt = zdt.add({ days: delta });
|
|
262
|
+
}
|
|
258
263
|
}
|
|
259
264
|
const { byHour, byMinute } = this.opts;
|
|
260
265
|
if (byHour || byMinute) {
|
|
@@ -608,23 +613,17 @@ var RRuleTemporal = class {
|
|
|
608
613
|
*/
|
|
609
614
|
next(after = /* @__PURE__ */ new Date(), inc = false) {
|
|
610
615
|
const afterInst = after instanceof Date ? import_polyfill.Temporal.Instant.from(after.toISOString()) : after.toInstant();
|
|
611
|
-
let
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
const
|
|
615
|
-
if (
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
matchCount++;
|
|
619
|
-
if (this.opts.count !== void 0 && matchCount >= this.opts.count) {
|
|
620
|
-
return null;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(current, this.opts.until) >= 0) {
|
|
624
|
-
return null;
|
|
616
|
+
let result = null;
|
|
617
|
+
this.all((occ) => {
|
|
618
|
+
const inst = occ.toInstant();
|
|
619
|
+
const ok = inc ? import_polyfill.Temporal.Instant.compare(inst, afterInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, afterInst) > 0;
|
|
620
|
+
if (ok) {
|
|
621
|
+
result = occ;
|
|
622
|
+
return false;
|
|
625
623
|
}
|
|
626
|
-
|
|
627
|
-
}
|
|
624
|
+
return true;
|
|
625
|
+
});
|
|
626
|
+
return result;
|
|
628
627
|
}
|
|
629
628
|
/**
|
|
630
629
|
* Returns the previous occurrence of the rule before a specified date.
|
|
@@ -634,21 +633,14 @@ var RRuleTemporal = class {
|
|
|
634
633
|
*/
|
|
635
634
|
previous(before = /* @__PURE__ */ new Date(), inc = false) {
|
|
636
635
|
const beforeInst = before instanceof Date ? import_polyfill.Temporal.Instant.from(before.toISOString()) : before.toInstant();
|
|
637
|
-
let current = this.computeFirst();
|
|
638
636
|
let prev = null;
|
|
639
|
-
|
|
640
|
-
const inst =
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
}
|
|
647
|
-
if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(current, this.opts.until) >= 0) {
|
|
648
|
-
break;
|
|
649
|
-
}
|
|
650
|
-
current = this.nextCandidateSameDate(current);
|
|
651
|
-
}
|
|
637
|
+
this.all((occ) => {
|
|
638
|
+
const inst = occ.toInstant();
|
|
639
|
+
const beyond = inc ? import_polyfill.Temporal.Instant.compare(inst, beforeInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, beforeInst) >= 0;
|
|
640
|
+
if (beyond) return false;
|
|
641
|
+
prev = occ;
|
|
642
|
+
return true;
|
|
643
|
+
});
|
|
652
644
|
return prev;
|
|
653
645
|
}
|
|
654
646
|
toString() {
|
package/dist/index.js
CHANGED
|
@@ -228,9 +228,14 @@ var RRuleTemporal = class {
|
|
|
228
228
|
SA: 6,
|
|
229
229
|
SU: 7
|
|
230
230
|
};
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
const deltas = this.opts.byDay.map((tok) => {
|
|
232
|
+
const wdTok = tok.match(/(MO|TU|WE|TH|FR|SA|SU)$/)?.[1];
|
|
233
|
+
return wdTok ? (dayMap[wdTok] - zdt.dayOfWeek + 7) % 7 : null;
|
|
234
|
+
}).filter((d) => d !== null);
|
|
235
|
+
if (deltas.length) {
|
|
236
|
+
const delta = Math.min(...deltas);
|
|
237
|
+
zdt = zdt.add({ days: delta });
|
|
238
|
+
}
|
|
234
239
|
}
|
|
235
240
|
const { byHour, byMinute } = this.opts;
|
|
236
241
|
if (byHour || byMinute) {
|
|
@@ -584,23 +589,17 @@ var RRuleTemporal = class {
|
|
|
584
589
|
*/
|
|
585
590
|
next(after = /* @__PURE__ */ new Date(), inc = false) {
|
|
586
591
|
const afterInst = after instanceof Date ? Temporal.Instant.from(after.toISOString()) : after.toInstant();
|
|
587
|
-
let
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
const
|
|
591
|
-
if (
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
matchCount++;
|
|
595
|
-
if (this.opts.count !== void 0 && matchCount >= this.opts.count) {
|
|
596
|
-
return null;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
if (this.opts.until && Temporal.ZonedDateTime.compare(current, this.opts.until) >= 0) {
|
|
600
|
-
return null;
|
|
592
|
+
let result = null;
|
|
593
|
+
this.all((occ) => {
|
|
594
|
+
const inst = occ.toInstant();
|
|
595
|
+
const ok = inc ? Temporal.Instant.compare(inst, afterInst) >= 0 : Temporal.Instant.compare(inst, afterInst) > 0;
|
|
596
|
+
if (ok) {
|
|
597
|
+
result = occ;
|
|
598
|
+
return false;
|
|
601
599
|
}
|
|
602
|
-
|
|
603
|
-
}
|
|
600
|
+
return true;
|
|
601
|
+
});
|
|
602
|
+
return result;
|
|
604
603
|
}
|
|
605
604
|
/**
|
|
606
605
|
* Returns the previous occurrence of the rule before a specified date.
|
|
@@ -610,21 +609,14 @@ var RRuleTemporal = class {
|
|
|
610
609
|
*/
|
|
611
610
|
previous(before = /* @__PURE__ */ new Date(), inc = false) {
|
|
612
611
|
const beforeInst = before instanceof Date ? Temporal.Instant.from(before.toISOString()) : before.toInstant();
|
|
613
|
-
let current = this.computeFirst();
|
|
614
612
|
let prev = null;
|
|
615
|
-
|
|
616
|
-
const inst =
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}
|
|
623
|
-
if (this.opts.until && Temporal.ZonedDateTime.compare(current, this.opts.until) >= 0) {
|
|
624
|
-
break;
|
|
625
|
-
}
|
|
626
|
-
current = this.nextCandidateSameDate(current);
|
|
627
|
-
}
|
|
613
|
+
this.all((occ) => {
|
|
614
|
+
const inst = occ.toInstant();
|
|
615
|
+
const beyond = inc ? Temporal.Instant.compare(inst, beforeInst) > 0 : Temporal.Instant.compare(inst, beforeInst) >= 0;
|
|
616
|
+
if (beyond) return false;
|
|
617
|
+
prev = occ;
|
|
618
|
+
return true;
|
|
619
|
+
});
|
|
628
620
|
return prev;
|
|
629
621
|
}
|
|
630
622
|
toString() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrule-temporal",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Recurrence rule processing using Temporal PlainDate/PlainDateTime",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tsup",
|
|
16
|
-
"test": "jest"
|
|
16
|
+
"test": "jest",
|
|
17
|
+
"prepare": "npm run build"
|
|
17
18
|
},
|
|
18
19
|
"repository": {
|
|
19
20
|
"type": "git",
|