@@ -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 ( ) {
@@ -682,6 +690,27 @@ export default class Task {
682
690
) . toSeconds ( )
683
691
}
684
692
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
+
685
714
/**
686
715
* Checks if the task matches the search query
687
716
*
0 commit comments