Skip to content

Commit 7b33e13

Browse files
committed
Don't drop scheduled when it's the only date.
1 parent e6dcf70 commit 7b33e13

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Task/Occurrence.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,15 @@ export class Occurrence {
9999
});
100100
}
101101

102+
const hasStartDate = this.startDate !== null;
103+
const hasDueDate = this.dueDate !== null;
104+
const canDropScheduledDate = hasStartDate || hasDueDate;
105+
const shouldDropScheduledDate = dropScheduledDate && canDropScheduledDate;
106+
102107
const startDate = this.nextOccurrenceDate(this.startDate, nextReferenceDate);
103-
const scheduledDate = dropScheduledDate ? null : this.nextOccurrenceDate(this.scheduledDate, nextReferenceDate);
108+
const scheduledDate = shouldDropScheduledDate
109+
? null
110+
: this.nextOccurrenceDate(this.scheduledDate, nextReferenceDate);
104111
const dueDate = this.nextOccurrenceDate(this.dueDate, nextReferenceDate);
105112

106113
return new Occurrence({

tests/Task/Recurrence.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,20 @@ describe('Recurrence - with dropScheduledDateOnRecurrence', () => {
247247
// Assert
248248
expect(next!.scheduledDate).toBeNull();
249249
});
250+
251+
it('does not drop the scheduledDate when it is the only date', () => {
252+
// Arrange
253+
const recurrence = Recurrence.fromText({
254+
recurrenceRuleText: 'every month',
255+
occurrence: new Occurrence({
256+
scheduledDate: moment('2022-01-04').startOf('day'),
257+
}),
258+
});
259+
260+
// Act
261+
const next = recurrence!.next(undefined, true);
262+
263+
// Assert
264+
expect(next!.scheduledDate).not.toBeNull();
265+
});
250266
});

0 commit comments

Comments
 (0)