Skip to content

Commit 6eb4fbe

Browse files
[scheduler] Build the last counted day of a daily series only when it counts one
With an interval of millennia, the day before the first one fell before the supported years, which the constructor of the plain dates rejects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent cd2ac98 commit 6eb4fbe

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎packages/x-scheduler-internals-premium/src/internals/utils/recurring-events/RecurringSeries.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ describe('recurring-events/RecurringSeries', () => {
205205
).to.equal(100);
206206
});
207207

208+
it('should return count when target is before start with an interval of millennia', () => {
209+
expect(
210+
countRemaining(
211+
createRule(1_000_000),
212+
adapter.date('2025-03-10', 'UTC'),
213+
adapter.date('2025-03-09T23:59:59', 'UTC'),
214+
100,
215+
),
216+
).to.equal(100);
217+
});
218+
208219
it('should return the remaining occurrences after an inclusive day span (interval=1)', () => {
209220
expect(
210221
countRemaining(

‎packages/x-scheduler-internals-premium/src/internals/utils/recurring-events/RecurringSeries.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,9 @@ export class RecurringSeries {
480480
const startDayNumber = getDayNumber(startDay);
481481
const days = getDayNumber(date) - startDayNumber;
482482
count = days > 0 ? Math.min(this.count, Math.ceil(days / ruleDays.interval)) : 0;
483-
lastDay = plainDateFromDayNumber(startDayNumber + (count - 1) * ruleDays.interval);
483+
if (count > 0) {
484+
lastDay = plainDateFromDayNumber(startDayNumber + (count - 1) * ruleDays.interval);
485+
}
484486
} else {
485487
count = countDays(() => false);
486488
}

0 commit comments

Comments
 (0)