rrule-temporal 0.2.1 → 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 CHANGED
@@ -613,23 +613,17 @@ var RRuleTemporal = class {
613
613
  */
614
614
  next(after = /* @__PURE__ */ new Date(), inc = false) {
615
615
  const afterInst = after instanceof Date ? import_polyfill.Temporal.Instant.from(after.toISOString()) : after.toInstant();
616
- let current = this.computeFirst();
617
- let matchCount = 0;
618
- while (true) {
619
- const inst = current.toInstant();
620
- if (this.matchesAll(current)) {
621
- const ok = inc ? import_polyfill.Temporal.Instant.compare(inst, afterInst) >= 0 : import_polyfill.Temporal.Instant.compare(inst, afterInst) > 0;
622
- if (ok) return current;
623
- matchCount++;
624
- if (this.opts.count !== void 0 && matchCount >= this.opts.count) {
625
- return null;
626
- }
627
- }
628
- if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(current, this.opts.until) >= 0) {
629
- 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;
630
623
  }
631
- current = this.nextCandidateSameDate(current);
632
- }
624
+ return true;
625
+ });
626
+ return result;
633
627
  }
634
628
  /**
635
629
  * Returns the previous occurrence of the rule before a specified date.
@@ -639,21 +633,14 @@ var RRuleTemporal = class {
639
633
  */
640
634
  previous(before = /* @__PURE__ */ new Date(), inc = false) {
641
635
  const beforeInst = before instanceof Date ? import_polyfill.Temporal.Instant.from(before.toISOString()) : before.toInstant();
642
- let current = this.computeFirst();
643
636
  let prev = null;
644
- while (true) {
645
- const inst = current.toInstant();
646
- if (inc ? import_polyfill.Temporal.Instant.compare(inst, beforeInst) > 0 : import_polyfill.Temporal.Instant.compare(inst, beforeInst) >= 0) {
647
- break;
648
- }
649
- if (this.matchesAll(current)) {
650
- prev = current;
651
- }
652
- if (this.opts.until && import_polyfill.Temporal.ZonedDateTime.compare(current, this.opts.until) >= 0) {
653
- break;
654
- }
655
- current = this.nextCandidateSameDate(current);
656
- }
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
+ });
657
644
  return prev;
658
645
  }
659
646
  toString() {
package/dist/index.js CHANGED
@@ -589,23 +589,17 @@ var RRuleTemporal = class {
589
589
  */
590
590
  next(after = /* @__PURE__ */ new Date(), inc = false) {
591
591
  const afterInst = after instanceof Date ? Temporal.Instant.from(after.toISOString()) : after.toInstant();
592
- let current = this.computeFirst();
593
- let matchCount = 0;
594
- while (true) {
595
- const inst = current.toInstant();
596
- if (this.matchesAll(current)) {
597
- const ok = inc ? Temporal.Instant.compare(inst, afterInst) >= 0 : Temporal.Instant.compare(inst, afterInst) > 0;
598
- if (ok) return current;
599
- matchCount++;
600
- if (this.opts.count !== void 0 && matchCount >= this.opts.count) {
601
- return null;
602
- }
603
- }
604
- if (this.opts.until && Temporal.ZonedDateTime.compare(current, this.opts.until) >= 0) {
605
- 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;
606
599
  }
607
- current = this.nextCandidateSameDate(current);
608
- }
600
+ return true;
601
+ });
602
+ return result;
609
603
  }
610
604
  /**
611
605
  * Returns the previous occurrence of the rule before a specified date.
@@ -615,21 +609,14 @@ var RRuleTemporal = class {
615
609
  */
616
610
  previous(before = /* @__PURE__ */ new Date(), inc = false) {
617
611
  const beforeInst = before instanceof Date ? Temporal.Instant.from(before.toISOString()) : before.toInstant();
618
- let current = this.computeFirst();
619
612
  let prev = null;
620
- while (true) {
621
- const inst = current.toInstant();
622
- if (inc ? Temporal.Instant.compare(inst, beforeInst) > 0 : Temporal.Instant.compare(inst, beforeInst) >= 0) {
623
- break;
624
- }
625
- if (this.matchesAll(current)) {
626
- prev = current;
627
- }
628
- if (this.opts.until && Temporal.ZonedDateTime.compare(current, this.opts.until) >= 0) {
629
- break;
630
- }
631
- current = this.nextCandidateSameDate(current);
632
- }
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
+ });
633
620
  return prev;
634
621
  }
635
622
  toString() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrule-temporal",
3
- "version": "0.2.1",
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",