Skip to content

Commit 8f955b3

Browse files
committed
Add count of overdue tasks
1 parent cdc0a8c commit 8f955b3

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/store/index.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ export default createStore({
6161
const task: Todo = state.todos.find(
6262
(todo: { newId: number }) => todo.newId === payload,
6363
) as Todo;
64-
const daysToDue: number =
64+
const daysToDue: number = Math.round(
6565
(Number(new Date(task.dueDate + " 23:59:59.999")) -
6666
Number(new Date().setHours(23, 59, 59, 999))) /
67-
(1000 * 60 * 60 * 24); //calculate the number of days until the task is due
67+
(1000 * 60 * 60 * 24),
68+
); //calculate the number of days until the task is due
6869
let dateMultiplier: number;
6970
if (daysToDue < 0) {
7071
//if the task is overdue, XP and score multiplier is less than 1 that decreases over time when the task is overdue
@@ -90,7 +91,19 @@ export default createStore({
9091
let rankMultiplier: number; //calculate rank multiplier based on current user rating score
9192
const activeTasks: number = state.todos.filter(
9293
(taskList) => !taskList.isCompleted,
93-
).length; //calculate the number of active tasks (tasks that are not completed) using array.filter
94+
).length; //calculate the number of active tasks (tasks that are not completed) using Array.filter
95+
const overdueTasks: number = state.todos.filter(
96+
(taskList) =>
97+
new Date(
98+
new Date(
99+
new Date().setMinutes(
100+
new Date().getMinutes() - new Date().getTimezoneOffset(),
101+
),
102+
)
103+
.toISOString()
104+
.split("T")[0] + " 23:59:59.999",
105+
) >= new Date(taskList.dueDate + " 23:59:59.999"),
106+
).length; //calculate the number of overdue tasks (tasks after the due date)
94107
let activeTasksMultiplier: number; //calculate score multiplier for number of active tasks (tasks that are not completed)
95108
//calculate task repetition XP multiplier
96109
if (Number(task.repeatInterval) === 1) {
@@ -228,7 +241,8 @@ export default createStore({
228241
state.user.rating = Math.max(
229242
state.user.rating -
230243
Math.sqrt(Math.max(state.user.rating, 0)) *
231-
(1 + Math.log(Math.max(i + 1, 1))),
244+
(1 + Math.log(Math.max(i + 1, 1))) *
245+
(1 + Math.log(Math.max(overdueTasks + 1, 1))),
232246
0,
233247
); //decrease user rating for each day of inactivity
234248
}

0 commit comments

Comments
 (0)