Skip to content

Commit 44c6d29

Browse files
authored
Merge pull request #2600 from obsidian-tasks-group/urgency-ignores-invalid-dates
fix: Make the Urgency calculation ignore invalid dates
2 parents ff8cd81 + 8e208ba commit 44c6d29

File tree

5 files changed

+56
-53
lines changed

5 files changed

+56
-53
lines changed

docs/Advanced/Urgency.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Tasks simply sums up urgency scores of different aspects of a task:
2727

2828
As you can tell from the table below, **due dates have the strongest influence on urgency.**
2929

30+
Note that any invalid date values, referring to non-existent dates, are ignored.
31+
3032
The scores are as follows:
3133

3234
<!-- placeholder to force blank line before included text --><!-- include: DocsSamplesForUrgency.test.UrgencyTable_urgency-html-table.approved.md -->

docs/Support and Help/Breaking Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ These are all bug-fixes, improving the default behaviour, and recorded here for
4343
- [[Filters#Happens|happens]] date now ignores any invalid dates.
4444
- `sort by [date]` now puts invalid dates before valid dates, as action is required. See [[Sorting#How dates are sorted]].
4545
- `group by [date]` now puts `Invalid [date] date` as the first heading.
46+
- The [[urgency]] calculation now ignores any invalid dates.
4647
- `task.due.category` and `task.due.fromNow` now handle invalid dates as different from future dates. See [[Task Properties#Values in TasksDate Properties|Values in TasksDate Properties]].
4748
- Code snippets used to change the look of the Edit and Postpone buttons must be changed, as explained in [[How to style buttons]], which gives several examples.

src/Urgency.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class Urgency {
1111
public static calculate(task: Task): number {
1212
let urgency = 0.0;
1313

14-
if (task.dueDate !== null) {
14+
if (task.dueDate !== null && task.dueDate.isValid()) {
1515
// Map a range of 21 days to the value 0.2 - 1.0
1616
const startOfToday = window.moment().startOf('day');
1717
const daysOverdue = Math.round(startOfToday.diff(task.dueDate) / Urgency.milliSecondsPerDay);
@@ -29,13 +29,13 @@ export class Urgency {
2929
urgency += dueMultiplier * Urgency.dueCoefficient;
3030
}
3131

32-
if (task.scheduledDate !== null) {
32+
if (task.scheduledDate !== null && task.scheduledDate.isValid()) {
3333
if (window.moment().isSameOrAfter(task.scheduledDate)) {
3434
urgency += 1 * Urgency.scheduledCoefficient;
3535
}
3636
}
3737

38-
if (task.startDate !== null) {
38+
if (task.startDate !== null && task.startDate.isValid()) {
3939
if (window.moment().isBefore(task.startDate)) {
4040
urgency += 1 * Urgency.startedCoefficient;
4141
}

0 commit comments

Comments
 (0)