Skip to content

Commit 413ad50

Browse files
committed
Add validation for deadline date format in daysLeft function
1 parent 4ec3342 commit 413ad50

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ export function deleteCompleted(todos) {
4444
export function daysLeft(deadline, today = new Date()) {
4545
const [year, month, day] = deadline.split("-").map(Number);
4646
const deadlineDate = new Date(year, month - 1, day);
47+
48+
if (
49+
deadlineDate.getFullYear() !== year ||
50+
deadlineDate.getMonth() !== month ||
51+
deadlineDate.getDate() !== day
52+
) {
53+
return NaN;
54+
}
55+
4756
const todaysDate = new Date(
4857
today.getFullYear(),
4958
today.getMonth(),

0 commit comments

Comments
 (0)