Fix bi-weekly+ recurring tasks reverting to weekly (#844) (#890)

This commit is contained in:
Chris 2026-03-02 23:36:47 +02:00 committed by GitHub
parent b81abd9bfe
commit c656c2aa67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 108 additions and 39 deletions

View file

@ -68,16 +68,22 @@ const calculateWeeklyRecurrence = (fromDate, interval, weekday, weekdays) => {
: null;
if (parsedWeekdays && parsedWeekdays.length > 0) {
// Find the next matching weekday from tomorrow onward
for (let daysAhead = 1; daysAhead <= 7; daysAhead++) {
const testDate = new Date(nextDate);
testDate.setUTCDate(testDate.getUTCDate() + daysAhead);
if (parsedWeekdays.includes(testDate.getUTCDay())) {
return testDate;
}
const sorted = [...parsedWeekdays].sort((a, b) => a - b);
const currentDay = nextDate.getUTCDay();
// Find next weekday later in the current week
const laterInWeek = sorted.filter((d) => d > currentDay);
if (laterInWeek.length > 0) {
nextDate.setUTCDate(
nextDate.getUTCDate() + (laterInWeek[0] - currentDay)
);
} else {
// Wrap to first weekday of next cycle (interval weeks ahead)
const daysToNextFirst = (7 - currentDay + sorted[0]) % 7 || 7;
nextDate.setUTCDate(
nextDate.getUTCDate() + daysToNextFirst + (interval - 1) * 7
);
}
// Fallback: advance by interval weeks
nextDate.setUTCDate(nextDate.getUTCDate() + interval * 7);
} else if (weekday !== null && weekday !== undefined) {
const currentWeekday = nextDate.getUTCDay();
const daysUntilTarget = (weekday - currentWeekday + 7) % 7;