From e9768ba1344752c5225e20ba834efec89229f24a Mon Sep 17 00:00:00 2001 From: Michael Prager Date: Mon, 1 Mar 2010 18:13:20 +0100 Subject: [PATCH] refactoring isToday() and isTomorrow() methods --- comingNext/index.html | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/comingNext/index.html b/comingNext/index.html index b722479..7077a4e 100644 --- a/comingNext/index.html +++ b/comingNext/index.html @@ -150,20 +150,23 @@ function error(message) document.getElementById("calendarList").innerHTML = 'Error: ' + message; } -function isToday(date) +function areDatesEqual(date1, date2) { - if (date.getFullYear() == now.getFullYear() && date.getMonth() == now.getMonth() && date.getDate() == now.getDate()) - return true; - return false; + return (date1.getFullYear() == date2.getFullYear() && + date1.getMonth() == date2.getMonth() && + date1.getDate() == date2.getDate()); } function isTomorrow(date) { - var tomorrow = new Date (now.getTime() + 24 * 60 * 60 * 1000); - if (date.getFullYear() == tomorrow.getFullYear() && date.getMonth() == tomorrow.getMonth() && date.getDate() == tomorrow.getDate()) - return true; - else - return false; + // tommorow = now + 1 day + // ToDo: some days can be shorter as 24 hours(daylight saving change day) + return areDatesEqual(date, new Date (now.getTime() + 24*60*60*1000)); +} + +function isToday(date) +{ + return areDatesEqual(date, now); } function collectLocales() -- 2.39.2