Skip to content

Commit d16709b

Browse files
committed
Avoid division by zero
1 parent 071d878 commit d16709b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/store/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default createStore({
7171
let dateMultiplier: number; //calculate the date multiplier based on the number of days until the task is due
7272
if (daysToDue < 0) {
7373
//if the task is overdue, XP and score multiplier are less than 1 that decreases over time when the task is overdue
74-
dateMultiplier = -2 / (daysToDue - 1);
74+
dateMultiplier = -2 / Math.min(-1, daysToDue - 1);
7575
} else if (daysToDue === 0) {
7676
//if the task is due today, XP and score multiplier bonus increases more than 2 based on the time the task is completed
7777
dateMultiplier =
@@ -82,7 +82,7 @@ export default createStore({
8282
(1000 * 24 * 60 * 60));
8383
} else {
8484
//else, XP and score multiplier bonus increases (more than 1) when the task gets closer to due date
85-
dateMultiplier = 1 + 1 / (daysToDue + 1);
85+
dateMultiplier = 1 + 1 / Math.max(1, daysToDue + 1);
8686
}
8787
let streakMultiplier: number; //calculate the task streak XP and score multiplier based on task streak, if the task is completed before the due date, then the streak increases else if the task is completed overdue (after the due date) reset task streak to 0
8888
let repeatMultiplier: number; //calculate the task repetition XP and score multiplier based on task repetition occurrence and task repetition interval

0 commit comments

Comments
 (0)