( input: TaskEditChangeInput, changes: Partial<TaskInfo> )
| 254 | } |
| 255 | |
| 256 | function applyRecurringInstanceChanges( |
| 257 | input: TaskEditChangeInput, |
| 258 | changes: Partial<TaskInfo> |
| 259 | ): void { |
| 260 | if ( |
| 261 | input.completedInstancesChanges.length === 0 && |
| 262 | input.skippedInstancesChanges.length === 0 |
| 263 | ) { |
| 264 | return; |
| 265 | } |
| 266 | |
| 267 | const originalCompleted = new Set(input.task.complete_instances || []); |
| 268 | const originalSkipped = new Set(input.task.skipped_instances || []); |
| 269 | const currentCompleted = new Set(originalCompleted); |
| 270 | const currentSkipped = new Set(originalSkipped); |
| 271 | |
| 272 | for (const dateStr of input.completedInstancesChanges) { |
| 273 | if (currentCompleted.has(dateStr)) { |
| 274 | currentCompleted.delete(dateStr); |
| 275 | } else { |
| 276 | currentCompleted.add(dateStr); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | for (const dateStr of input.skippedInstancesChanges) { |
| 281 | if (currentSkipped.has(dateStr)) { |
| 282 | currentSkipped.delete(dateStr); |
| 283 | } else { |
| 284 | currentSkipped.add(dateStr); |
| 285 | currentCompleted.delete(dateStr); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | for (const dateStr of currentCompleted) { |
| 290 | currentSkipped.delete(dateStr); |
| 291 | } |
| 292 | for (const dateStr of currentSkipped) { |
| 293 | currentCompleted.delete(dateStr); |
| 294 | } |
| 295 | |
| 296 | let latestAddedCompletion: string | null = null; |
| 297 | for (const dateStr of input.completedInstancesChanges) { |
| 298 | if (!originalCompleted.has(dateStr) && currentCompleted.has(dateStr)) { |
| 299 | if (!latestAddedCompletion || dateStr > latestAddedCompletion) { |
| 300 | latestAddedCompletion = dateStr; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | if (!setsEqual(originalCompleted, currentCompleted)) { |
| 306 | changes.complete_instances = Array.from(currentCompleted); |
| 307 | } |
| 308 | |
| 309 | if (!setsEqual(originalSkipped, currentSkipped)) { |
| 310 | changes.skipped_instances = Array.from(currentSkipped); |
| 311 | } |
| 312 | |
| 313 | if (!input.task.recurrence || typeof input.task.recurrence !== "string") { |
no test coverage detected