Skip to content

Commit f369596

Browse files
committed
Complete recurring tasks by setting their start date to the next recurrence date
Signed-off-by: Sunik Kupfer <[email protected]> Signed-off-by: Sunik <[email protected]>
1 parent a11429d commit f369596

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/models/task.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ export default class Task {
9595
this._completed = !!comp
9696
this._completedDate = comp ? comp.toJSDate() : null
9797
this._completedDateMoment = moment(this._completedDate, 'YYYYMMDDTHHmmss')
98-
const recur = this.vtodo.getFirstPropertyValue('rrule')
99-
this._recurring = !!recur
98+
this._recurrence = this.vtodo.getFirstPropertyValue('rrule')
10099
this._status = this.vtodo.getFirstPropertyValue('status')
101100
this._note = this.vtodo.getFirstPropertyValue('description') || ''
102101
this._related = this.getParent()?.getFirstValue() || null
@@ -331,8 +330,17 @@ export default class Task {
331330
return this._completedDateMoment.clone()
332331
}
333332

333+
get recurrence() {
334+
return this._recurrence
335+
}
336+
334337
get recurring() {
335-
return this._recurring
338+
if (this._start === null || this._recurrence === null) {
339+
return false
340+
}
341+
const iter = this._recurrence.iterator(this.start)
342+
iter.next()
343+
return iter.next() !== null
336344
}
337345

338346
get status() {
@@ -682,6 +690,27 @@ export default class Task {
682690
).toSeconds()
683691
}
684692

693+
/**
694+
* For completing a recurring task, tries to set the task start date to the next recurrence date.
695+
*
696+
* Does nothing if we are at the end of the recurrence (RRULE:UNTIL was reached).
697+
*/
698+
completeRecurring() {
699+
// Get recurrence iterator, starting at start date
700+
const iter = this.recurrence.iterator(this.start)
701+
// Skip the start date itself
702+
iter.next()
703+
// If there is a next recurrence, update the start date to next recurrence date
704+
const nextRecurrence = iter.next()
705+
if (nextRecurrence !== null) {
706+
this.start = nextRecurrence
707+
// If the due date now lies before start date, clear it
708+
if (this.due !== null && this.due.compare(this.start) < 0) {
709+
this.due = null
710+
}
711+
}
712+
}
713+
685714
/**
686715
* Checks if the task matches the search query
687716
*

src/store/tasks.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,12 @@ const actions = {
10191019
if (task.calendar.isSharedWithMe && task.class !== 'PUBLIC') {
10201020
return
10211021
}
1022+
// Don't complete a task if it is still recurring, but update its start date instead
1023+
if (task.recurring) {
1024+
task.completeRecurring()
1025+
await context.dispatch('updateTask', task)
1026+
return
1027+
}
10221028
if (task.completed) {
10231029
await context.dispatch('setPercentComplete', { task, complete: 0 })
10241030
} else {

0 commit comments

Comments
 (0)