Skip to content

Commit 438dbff

Browse files
committed
Fix date validation in daysLeft function and add test for invalid date handling
1 parent 413ad50 commit 438dbff

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function daysLeft(deadline, today = new Date()) {
4747

4848
if (
4949
deadlineDate.getFullYear() !== year ||
50-
deadlineDate.getMonth() !== month ||
50+
deadlineDate.getMonth() !== month - 1 ||
5151
deadlineDate.getDate() !== day
5252
) {
5353
return NaN;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ describe("daysLeft()", () => {
174174
test("Past date is negative", () => {
175175
expect(Todos.daysLeft("2026-11-10", today)).toBe(-2);
176176
});
177+
test("Returns NaN for a date that does not exist", () => {
178+
const today = new Date(2026, 10, 16);
179+
expect(Number.isNaN(Todos.daysLeft("2026-02-31", today))).toBe(true);
180+
});
177181
});
178182

179183
describe("addTask() with deadline", () => {

0 commit comments

Comments
 (0)