Skip to content

Commit

Permalink
Fixes strict and non-strict threshold recurrence. (#613)
Browse files Browse the repository at this point in the history
* Fixes the threshold recurrence and the corresponding tests.

* Removes console.log statements.
  • Loading branch information
stephprobst authored Dec 11, 2023
1 parent 5880ba9 commit 0a8044a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/main/CreateRecurringTodo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ describe('Create recurring todos', () => {
test('Should add a new todo adding a non-strict recurrence of one week to due date and threshold date', async () => {
const recurringTodo = await createRecurringTodo(`x ${dateTodayString} ${dateTodayString} Water plants @home +quick due:2021-07-19 t:2021-07-09 rec:1w`, '1w');
const fileContent = await fs.readFile('./src/__tests__/__mock__/recurrence.txt', 'utf8');
expect(fileContent.split('\n').pop()).toEqual(`${dateTodayString} Water plants @home +quick due:${dateInOneWeekString} t:${dateInOneWeekMinus10String} rec:1w`);
expect(fileContent.split('\n').pop()).toEqual(`${dateTodayString} Water plants @home +quick due:${dateInOneWeekString} t:${dateInOneWeekString} rec:1w`);
});

test('Should add a new todo adding a strict recurrence of one day to threshold date. No due date should be created.', async () => {
const recurringTodo = await createRecurringTodo(`x ${dateTodayString} ${dateTodayString} Line 1 rec:+1d t:2023-09-19`, '1+d');
const recurringTodo = await createRecurringTodo(`x ${dateTodayString} ${dateTodayString} Line 1 rec:+1d t:2023-09-19`, '+1d');
const fileContent = await fs.readFile('./src/__tests__/__mock__/recurrence.txt', 'utf8');
expect(fileContent.split('\n').pop()).toEqual(`${dateTodayString} Line 1 rec:+1d t:2023-09-20`);
});
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/TodoObject/CreateRecurringTodo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const createRecurringTodo = async (string: string, recurrence: string): Promise<
: addRecurrenceToDate(dayjs(completedDate).toDate(), recurrenceInterval);
const newThresholdDate = strictRecurrence
? addRecurrenceToDate(dayjs(oldThresholdDate).toDate(), recurrenceInterval)
: dayjs(newDueDate).subtract(daysBetween, 'day').toDate();
: addRecurrenceToDate(dayjs(completedDate).toDate(), recurrenceInterval);

// If the user only uses threshold date and no due date, the recurrence should not create a due date:
const recurrenceOnlyForThresholdDate = oldThresholdDate && !oldDueDate;
Expand Down

0 comments on commit 0a8044a

Please sign in to comment.