]> code.delx.au - comingnext/commitdiff
refactoring isToday() and isTomorrow() methods
authorMichael Prager <michael@pragers.de>
Mon, 1 Mar 2010 17:13:20 +0000 (18:13 +0100)
committerMichael Prager <michael@pragers.de>
Mon, 1 Mar 2010 17:13:20 +0000 (18:13 +0100)
comingNext/index.html

index b722479b1a2df497c520553d599e9dbb3595dec0..7077a4eaf15802ad5c720590845f46383fbdcad8 100644 (file)
@@ -150,20 +150,23 @@ function error(message)
        document.getElementById("calendarList").innerHTML = 'Error: ' + message;\r
 }\r
 \r
-function isToday(date)\r
+function areDatesEqual(date1, date2)\r
 {\r
-       if (date.getFullYear() == now.getFullYear() && date.getMonth() == now.getMonth() && date.getDate() == now.getDate())\r
-               return true;\r
-       return false;\r
+       return (date1.getFullYear() == date2.getFullYear() && \r
+                       date1.getMonth() == date2.getMonth() && \r
+                       date1.getDate() == date2.getDate());\r
 }\r
 \r
 function isTomorrow(date)\r
 {\r
-       var tomorrow = new Date (now.getTime() + 24 * 60 * 60 * 1000);\r
-       if (date.getFullYear() == tomorrow.getFullYear() && date.getMonth() == tomorrow.getMonth() && date.getDate() == tomorrow.getDate())\r
-               return true;\r
-       else\r
-               return false; \r
+       // tommorow = now + 1 day\r
+       // ToDo: some days can be shorter as 24 hours(daylight saving change day)\r
+       return areDatesEqual(date, new Date (now.getTime() + 24*60*60*1000));\r
+}\r
+\r
+function isToday(date)\r
+{\r
+       return areDatesEqual(date, now);\r
 }\r
 \r
 function collectLocales()\r