@@ -95,8 +95,7 @@ export default class Task {
95
95
this . _completed = ! ! comp
96
96
this . _completedDate = comp ? comp . toJSDate ( ) : null
97
97
this . _completedDateMoment = moment ( this . _completedDate , 'YYYYMMDDTHHmmss' )
98
- const recur = this . vtodo . getFirstPropertyValue ( 'rrule' )
99
- this . _recurring = ! ! recur
98
+ this . _recurrence = this . vtodo . getFirstPropertyValue ( 'rrule' )
100
99
this . _status = this . vtodo . getFirstPropertyValue ( 'status' )
101
100
this . _note = this . vtodo . getFirstPropertyValue ( 'description' ) || ''
102
101
this . _related = this . getParent ( ) ?. getFirstValue ( ) || null
@@ -331,8 +330,17 @@ export default class Task {
331
330
return this . _completedDateMoment . clone ( )
332
331
}
333
332
333
+ get recurrence ( ) {
334
+ return this . _recurrence
335
+ }
336
+
334
337
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
336
344
}
337
345
338
346
get status ( ) {
@@ -680,6 +688,27 @@ export default class Task {
680
688
) . toSeconds ( )
681
689
}
682
690
691
+ /**
692
+ * For completing a recurring task, tries to set the task start date to the next recurrence date.
693
+ *
694
+ * Does nothing if we are at the end of the recurrence (RRULE:UNTIL was reached).
695
+ */
696
+ completeRecurring ( ) {
697
+ // Get recurrence iterator, starting at start date
698
+ const iter = this . recurrence . iterator ( this . start )
699
+ // Skip the start date itself
700
+ iter . next ( )
701
+ // If there is a next recurrence, update the start date to next recurrence date
702
+ const nextRecurrence = iter . next ( )
703
+ if ( nextRecurrence !== null ) {
704
+ this . start = nextRecurrence
705
+ // If the due date now lies before start date, clear it
706
+ if ( this . due !== null && this . due . compare ( this . start ) < 0 ) {
707
+ this . due = null
708
+ }
709
+ }
710
+ }
711
+
683
712
/**
684
713
* Checks if the task matches the search query
685
714
*
0 commit comments