Skip to content

Commit e6dcf70

Browse files
committed
Drop scheduled dates as an option. #2751
1 parent 8cd7a87 commit e6dcf70

File tree

7 files changed

+51
-7
lines changed

7 files changed

+51
-7
lines changed

src/Config/Settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export interface Settings {
7676
filenameAsScheduledDateFormat: string;
7777
filenameAsDateFolders: string[];
7878
recurrenceOnNextLine: boolean;
79+
dropScheduledDateOnRecurrence: boolean;
7980

8081
// The custom status states.
8182
statusSettings: StatusSettings;
@@ -110,6 +111,7 @@ const defaultSettings: Settings = {
110111
filenameAsScheduledDateFormat: '',
111112
filenameAsDateFolders: [],
112113
recurrenceOnNextLine: false,
114+
dropScheduledDateOnRecurrence: false,
113115
statusSettings: new StatusSettings(),
114116
features: Feature.settingsFlags,
115117
generalSettings: {

src/Config/SettingsTab.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,19 @@ export class SettingsTab extends PluginSettingTab {
376376
});
377377
});
378378

379+
new Setting(containerEl)
380+
.setName(i18n.t('settings.recurringTasks.dropScheduledDate.name'))
381+
.setDesc(
382+
SettingsTab.createFragmentWithHTML(i18n.t('settings.recurringTasks.dropScheduledDate.description')),
383+
)
384+
.addToggle((toggle) => {
385+
const { dropScheduledDateOnRecurrence } = getSettings();
386+
toggle.setValue(dropScheduledDateOnRecurrence).onChange(async (value) => {
387+
updateSettings({ dropScheduledDateOnRecurrence: value });
388+
await this.plugin.saveSettings();
389+
});
390+
});
391+
379392
// ---------------------------------------------------------------------------
380393
new Setting(containerEl).setName(i18n.t('settings.autoSuggest.heading')).setHeading();
381394
// ---------------------------------------------------------------------------

src/Task/Occurrence.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class Occurrence {
8888
*
8989
* @param nextReferenceDate
9090
*/
91-
public next(nextReferenceDate: Date): Occurrence {
91+
public next(nextReferenceDate: Date, dropScheduledDate: boolean = false): Occurrence {
9292
// Only if a reference date is given. A reference date will exist if at
9393
// least one of the other dates is set.
9494
if (this.referenceDate === null) {
@@ -99,10 +99,14 @@ export class Occurrence {
9999
});
100100
}
101101

102+
const startDate = this.nextOccurrenceDate(this.startDate, nextReferenceDate);
103+
const scheduledDate = dropScheduledDate ? null : this.nextOccurrenceDate(this.scheduledDate, nextReferenceDate);
104+
const dueDate = this.nextOccurrenceDate(this.dueDate, nextReferenceDate);
105+
102106
return new Occurrence({
103-
startDate: this.nextOccurrenceDate(this.startDate, nextReferenceDate),
104-
scheduledDate: this.nextOccurrenceDate(this.scheduledDate, nextReferenceDate),
105-
dueDate: this.nextOccurrenceDate(this.dueDate, nextReferenceDate),
107+
startDate,
108+
scheduledDate,
109+
dueDate,
106110
});
107111
}
108112

src/Task/Recurrence.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ export class Recurrence {
7373
*
7474
* @param today - Optional date representing the completion date. Defaults to today.
7575
*/
76-
public next(today = window.moment()): Occurrence | null {
76+
public next(today = window.moment(), dropScheduledDate: boolean = false): Occurrence | null {
7777
const nextReferenceDate = this.nextReferenceDate(today);
7878

7979
if (nextReferenceDate === null) {
8080
return null;
8181
}
8282

83-
return this.occurrence.next(nextReferenceDate);
83+
return this.occurrence.next(nextReferenceDate, dropScheduledDate);
8484
}
8585

8686
public identicalTo(other: Recurrence) {

src/Task/Task.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ export class Task extends ListItem {
377377
return [toggledTask];
378378
}
379379

380-
const nextOccurrence = this.recurrence.next(today);
380+
const { dropScheduledDateOnRecurrence } = getSettings();
381+
const nextOccurrence = this.recurrence.next(today, dropScheduledDateOnRecurrence);
381382
if (nextOccurrence === null) {
382383
return [toggledTask];
383384
}

src/i18n/locales/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@
180180
"nextLine": {
181181
"description": "Enabling this will make the next recurrence of a task appear on the line below the completed task. Otherwise the next recurrence will appear before the completed one.",
182182
"name": "Next recurrence appears on the line below"
183+
},
184+
"dropScheduledDate": {
185+
"description": "Enabling this will make the next recurrence of a task have no scheduled date.",
186+
"name": "Drop scheduled date on recurrence"
183187
}
184188
},
185189
"seeTheDocumentation": "See the documentation",

tests/Task/Recurrence.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,23 @@ describe('identicalTo', () => {
228228
expect(date1Recurrence?.identicalTo(date2Recurrence)).toBe(false);
229229
});
230230
});
231+
232+
describe('Recurrence - with dropScheduledDateOnRecurrence', () => {
233+
it('drops the scheduledDate when dropScheduledDate is true', () => {
234+
// Arrange
235+
const recurrence = Recurrence.fromText({
236+
recurrenceRuleText: 'every month',
237+
occurrence: new Occurrence({
238+
startDate: moment('2022-01-01').startOf('day'),
239+
scheduledDate: moment('2022-01-04').startOf('day'),
240+
dueDate: moment('2022-01-10').startOf('day'),
241+
}),
242+
});
243+
244+
// Act
245+
const next = recurrence!.next(undefined, true);
246+
247+
// Assert
248+
expect(next!.scheduledDate).toBeNull();
249+
});
250+
});

0 commit comments

Comments
 (0)