Skip to content

Commit

Permalink
Fix: No longer crash when toggling a recurring task without any date (o…
Browse files Browse the repository at this point in the history
…bsidian-tasks-group#597)

* Added a default case to handle when no due, scheduled, or start date is supplied.

* added test for default recurrence case

* Removed null check

* referenceDate is no longer nullable
  • Loading branch information
pistolpeter authored Apr 18, 2022
1 parent 1d38d07 commit 0fd369f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Recurrence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Recurrence {
* same relative distance to the due date as the original task. For example
* "starts one week before it is due".
*/
private readonly referenceDate: Moment | null;
private readonly referenceDate: Moment;

constructor({
rrule,
Expand All @@ -33,7 +33,7 @@ export class Recurrence {
}: {
rrule: RRule;
baseOnToday: boolean;
referenceDate: Moment | null;
referenceDate: Moment;
startDate: Moment | null;
scheduledDate: Moment | null;
dueDate: Moment | null;
Expand Down Expand Up @@ -80,9 +80,11 @@ export class Recurrence {
referenceDate = window.moment(scheduledDate);
} else if (startDate) {
referenceDate = window.moment(startDate);
} else {
referenceDate = window.moment();
}

if (!baseOnToday && referenceDate !== null) {
if (!baseOnToday) {
options.dtstart = window
.moment(referenceDate)
.startOf('day')
Expand Down
3 changes: 3 additions & 0 deletions tests/Task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ describe('toggle done', () => {
nextScheduled: '2021-10-18',
nextDue: '2021-10-20',
},
{
interval: 'every week',
},
];

test.concurrent.each<RecurrenceCase>(recurrenceCases)(
Expand Down

0 comments on commit 0fd369f

Please sign in to comment.