From aa6f2e31660f0e5cea5228ac77e618962bdb7e48 Mon Sep 17 00:00:00 2001 From: lifeadventurer Date: Sun, 31 Mar 2024 00:07:17 +0800 Subject: [PATCH] Fix: Function daysDiff handling date bug --- fortune_generator/js/fortune.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fortune_generator/js/fortune.js b/fortune_generator/js/fortune.js index 9517e4a..29d8f52 100644 --- a/fortune_generator/js/fortune.js +++ b/fortune_generator/js/fortune.js @@ -62,8 +62,8 @@ const year = d.getFullYear(); function daysDiff(eventIndex) { // define the date right now and the special event date - const startDate = new Date(year, month, date); - const endDate = new Date(special_events[eventIndex].year, special_events[eventIndex].month, special_events[eventIndex].date); + const startDate = new Date(year, month - 1, date); + const endDate = new Date(special_events[eventIndex].year, special_events[eventIndex].month - 1, special_events[eventIndex].date); // calculate the difference in milliseconds and convert it to days const timeDiff = Math.ceil((endDate - startDate) / (1000 * 60 * 60 * 24));