Fix first occurrence deletion
This commit is contained in:
@@ -103,24 +103,24 @@ function getWeeklyOccurrenceIndex(event, dateStr) {
|
||||
if (d.getTime() === baseStart.getTime()) {
|
||||
return 0 // Base occurrence is always index 0
|
||||
}
|
||||
|
||||
|
||||
if (d < baseStart) {
|
||||
return null // Dates before base start in same week are not valid occurrences
|
||||
}
|
||||
|
||||
|
||||
let occurrenceIndex = 0
|
||||
const cursor = new Date(baseStart)
|
||||
|
||||
|
||||
// Count the base occurrence first
|
||||
if (pattern[cursor.getDay()]) occurrenceIndex++
|
||||
|
||||
|
||||
// Move to the next day and count until we reach the target
|
||||
cursor.setDate(cursor.getDate() + 1)
|
||||
while (cursor <= d) {
|
||||
if (pattern[cursor.getDay()]) occurrenceIndex++
|
||||
cursor.setDate(cursor.getDate() + 1)
|
||||
}
|
||||
|
||||
|
||||
// Subtract 1 because we want the index, not the count
|
||||
occurrenceIndex--
|
||||
|
||||
@@ -139,16 +139,16 @@ function getWeeklyOccurrenceIndex(event, dateStr) {
|
||||
const firstWeekCursor = new Date(baseStart)
|
||||
const firstWeekEnd = new Date(baseBlockStart)
|
||||
firstWeekEnd.setDate(firstWeekEnd.getDate() + 6) // End of first week (Sunday)
|
||||
|
||||
|
||||
while (firstWeekCursor <= firstWeekEnd) {
|
||||
if (pattern[firstWeekCursor.getDay()]) firstWeekPatternDays++
|
||||
firstWeekCursor.setDate(firstWeekCursor.getDate() + 1)
|
||||
}
|
||||
|
||||
|
||||
// For subsequent complete intervals, use the full pattern count
|
||||
const fullWeekdaysPerInterval = pattern.filter(Boolean).length
|
||||
const completeIntervals = blocksDiff / interval
|
||||
|
||||
|
||||
// First interval uses actual first week count, remaining intervals use full count
|
||||
let occurrenceIndex = firstWeekPatternDays + (completeIntervals - 1) * fullWeekdaysPerInterval
|
||||
|
||||
|
||||
Reference in New Issue
Block a user