Skip to content

Commit e7ef918

Browse files
committed
Add daysLeft function to calculate remaining days until deadline
1 parent cfa258e commit e7ef918

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎Sprint-3/todo-list/todos.mjs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,16 @@ export function deleteCompleted(todos) {
4040
}
4141
}
4242
}
43+
44+
export function daysLeft(deadline, today = new Date()) {
45+
const [year, month, day] = deadline.split("-").map(Number);
46+
const deadlineDate = new Date(year, month - 1, day);
47+
const todaysDate = new Date(
48+
today.getFullYear(),
49+
today.getMonth,
50+
today.getDate()
51+
);
52+
const MS_PER_DAY = 24 * 60 * 60 * 1000;
53+
54+
return Math.round((deadlineDate - todaysDate) / MS_PER_DAY);
55+
}

0 commit comments

Comments
 (0)