From: Michael Prager Date: Mon, 1 Mar 2010 17:13:20 +0000 (+0100) Subject: refactoring isToday() and isTomorrow() methods X-Git-Url: https://code.delx.au/comingnext/commitdiff_plain/e9768ba1344752c5225e20ba834efec89229f24a?hp=7b49858cd1fcb737295bcba3d1bff3ee59c7b78b refactoring isToday() and isTomorrow() methods --- 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()