]> code.delx.au - comingnext/blobdiff - comingNext/index.html
fixed display of "tomorrow" text if CombinedDateTime is enabled
[comingnext] / comingNext / index.html
index 7fa1d5debdbff77cfd7f073d7a6fdccd99d9840e..27c397a74f461d1d8efbcabac5c36b52675fef92 100644 (file)
@@ -14,6 +14,7 @@ here you can customize background color, font color, font size etc...
 .weekDay { }                           /* Defines the appearance of all week day texts */\r
 .date { }                              /* Defines the appearance of all date texts */\r
 .today { color:#ff0000; }              /* Defines the appearance of "Today" text */\r
+.tomorrow { color:#0000ff; }           /* Defines the appearance of "Tomorrow" text */\r
 .time { }                              /* Defines the appearance of all time texts */\r
 .now { color:#ff00ff; }                        /* Defines the appearance of "Now" text */\r
 .description { }                       /* Defines the appearance of all event descriptions */\r
@@ -32,6 +33,7 @@ var showCombinedDateTime = false;// only show the time for events happening toda
 var showLocation = true;       // show the location for meeting events\r
 var showTodayAsText = true;    // if enabled, the current date will be shown as "Today" instead of "31.12"\r
 var todayText = 'Today';       // text to display for "Today"\r
+var tomorrowText = 'Tomorrow'; // text to display for "Tomorrow"\r
 var showNowAsText = true;      // if enabled, the appointment time will be shown as "Now" instead of "12:00"\r
 var nowText = 'Now';           // text to display for "Now"\r
 var dateSeparator = '.';       // separator for dates. e.g. "31.12" or "31/12"\r
@@ -42,6 +44,7 @@ var calendarApp = 0x10005901; // UID of the calendar app to run when clicking th
 var eventsPerWidget = 4;       // number of events to show per widget. Default is 4\r
 var showNothingText = true;    // if set to "true", show a text if no events are in the list\r
 var nothingText = 'No further events within ' + monthRange + ' months';                // text to show when no events are in the list\r
+var enableDaylightSaving = true;// enable this if you are in a timezone that has daylight saving time (+1h)\r
 \r
 //-------------------------------------------------------\r
 // Nothing of interest from here on...\r
@@ -53,10 +56,77 @@ var months_translated = [];
 var orientation = '';\r
 var now = new Date();\r
 \r
+// vars for daylight saving time\r
+var daylightsavingWinter = 0;\r
+var daylightsavingSummer = 0;\r
+var summertime = false;\r
+\r
 window.onload = init;\r
 window.onresize = updateScreen;\r
 window.onshow = updateScreen;\r
 \r
+function isLeapYear( year ) {\r
+       if (( year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0 )\r
+               return true;\r
+       else\r
+               return false;\r
+}\r
+         \r
+function calcLeapYear(year, days)\r
+{\r
+       if (isLeapYear(year))\r
+               return ++days;\r
+       else\r
+               return days;\r
+}\r
+         \r
+function subToSunday(myDate, year, days, prevMonthDays)\r
+{\r
+       for (i = myDate.getDay(); i > 0 ;i--)\r
+               days--;\r
+       days -= prevMonthDays;\r
+       days = isLeapYear(year) ? --days : days;\r
+       return days;\r
+}\r
+       \r
+function calcDaylightSaving()\r
+{\r
+       var thisYearS = new Date(now.getFullYear(),  3, 0, 0, 0, 0 );\r
+       var thisYearW = new Date(now.getFullYear(), 10, 0, 0, 0, 0 );\r
+       var nextYearS = new Date(now.getFullYear() + 1,  3, 0, 0, 0, 0 );\r
+       var nextYearW = new Date(now.getFullYear() + 1, 10, 0, 0, 0, 0 );\r
+       var summer = false;\r
+       var winter = false;\r
+       \r
+       thisYearSDays = nextYearSDays = 90;\r
+       thisYearWDays = nextYearWDays = 304;\r
+       \r
+       thisYearSDays = calcLeapYear(now.getFullYear(), thisYearSDays);\r
+       thisYearWDays = calcLeapYear(now.getFullYear(), thisYearWDays);\r
+       nextYearSDays = calcLeapYear(now.getFullYear() + 1, nextYearSDays);\r
+       nextYearWDays = calcLeapYear(now.getFullYear() + 1, nextYearWDays);\r
+       \r
+       thisYearSDays = subToSunday(thisYearS, now.getFullYear(), thisYearSDays, 59);\r
+       thisYearWDays = subToSunday(thisYearW, now.getFullYear(), thisYearWDays, 273);\r
+       nextYearSDays = subToSunday(nextYearS, now.getFullYear() + 1, nextYearSDays, 59);\r
+       nextYearWDays = subToSunday(nextYearW, now.getFullYear() + 1, nextYearWDays, 273);\r
+       \r
+       daylightsavingSummer = new Date (now.getFullYear(), 03-1, thisYearSDays, 2, 0, 0);\r
+       daylightsavingWinter = new Date (now.getFullYear(), 10-1, thisYearWDays, 2, 0, 0);\r
+       if (daylightsavingSummer < now) {\r
+               daylightsavingSummer = new Date (now.getFullYear()+1, 03-1, nextYearSDays, 2, 0, 0);\r
+               var summer = true;\r
+       }\r
+       if (daylightsavingWinter < now) {\r
+               daylightsavingWinter = new Date (now.getFullYear()+1, 10-1, nextYearWDays, 2, 0, 0);\r
+               var winter = true;\r
+       }\r
+       if (summer && !winter)\r
+               summertime = true;\r
+       else\r
+               summertime = false;\r
+}\r
+\r
 function error(message)\r
 {\r
        console.info('Error: ' + message);\r
@@ -70,6 +140,15 @@ function isToday(date)
        return false;\r
 }\r
 \r
+function isTomorrow(date)\r
+{\r
+       if ((date.getDate() == now.getDate() + 1 && date.getMonth() == now.getMonth()) ||\r
+           (date.getDate() == 0 && date.getMonth() == now.getMonth() + 1) ||\r
+           (date.getDate() == 0 && date.getMonth() == now.getMonth() + 1 && date.getYear() == now.getYear() + 1))\r
+               return true;\r
+       return false;\r
+}\r
+\r
 function collectLocales()\r
 {\r
        var tmpyear = ((panelNum == 0) ? 2000 : 2001);\r
@@ -242,6 +321,15 @@ function parseDate(dateString)
 \r
        console.info('year=' + year + ' month=' + month + ' day=' + day + ' hours=' + hours + ' minutes=' + minutes+ ' seconds=' + seconds);\r
 \r
+       // take care of daylight saving time\r
+       if (enableDaylightSaving) {\r
+               var date = new Date(year, month - 1, day, hours, minutes, seconds);\r
+               if (summertime && date > daylightsavingWinter && date < daylightsavingSummer)\r
+                       hours -= 1;\r
+               else if (!summertime && date > daylightsavingSummer && date < daylightsavingWinter)\r
+                       hours += 1;\r
+       }\r
+\r
        return new Date(year, month - 1, day, hours, minutes, seconds);\r
 }\r
 \r
@@ -255,6 +343,8 @@ function formatDate(date, format)
 \r
        if (showTodayAsText && isToday(date))\r
                return '<span class="today">' + todayText + '</span>';\r
+       if (showTodayAsText && isTomorrow(date))\r
+               return '<span class="tomorrow">' + tomorrowText + '</span>';\r
 \r
        var dateArr = format.replace(/,/g,'').replace(/\./g,':').replace(/  /g,' ').split(' ');\r
        if (dateArr.length != 5 && dateArr.length != 6) {\r
@@ -313,6 +403,7 @@ function formatTime(date)
 \r
 function updateData()\r
 {\r
+       calcDaylightSaving();\r
        try {\r
                // meetings have time\r
                // note: anniveraries have a start time of 12:00am. So since we want to include them, we have to query the whole day and check if events have passed later\r
@@ -471,25 +562,27 @@ function updateData()
                                        var time = formatTime(date);\r
                                        var dateStr = formatDate(date, entryDate);\r
                                        if (entry.Type == 'ToDo' || entry.Type == 'Anniversary' || entry.Type == 'DayEvent' || entry.Type == 'Reminder') {\r
-                                               if (isToday(date))\r
-                                                       entriesHtml += '<td colspan="2" class="date">' + dateStr + '</td><td colspan="2" class="description">';\r
+                                               if ((isToday(date) || isTomorrow(date)) && showTodayAsText) // show weekday if the date string is not text. looks odd otherwise\r
+                                                       entriesHtml += '<td colspan="4"><span class="date">' + dateStr + '</span> ';\r
                                                else\r
-                                                       entriesHtml += '<td class="weekDay">' + weekDay + '</td><td class="date">' + dateStr + '</td><td colspan="2" class="description">';\r
+                                                       entriesHtml += '<td class="weekDay">' + weekDay + '</td><td width="1px" class="date">' + dateStr + '</td><td colspan="2">';\r
                                        } else if (entry.Type == 'Meeting') {\r
                                                if (showCombinedDateTime) {\r
                                                        if (isToday(date))\r
-                                                               entriesHtml += '<td colspan="2" class="today">' + time + '</td><td colspan="2" class="description">';\r
+                                                               entriesHtml += '<td width="1px" colspan="4"><span class="today">' + time + '</span> ';\r
+                                                       else if (isTomorrow(date))\r
+                                                               entriesHtml += '<td width="1px" colspan="4"><span class="tomorrow">' + dateStr + '</span> <span class="time">' + time + '</span> ';\r
                                                        else\r
-                                                               entriesHtml += '<td class="weekDay">' + weekDay + '</td><td class="date">' + dateStr + '</td><td colspan="2" class="description">';\r
+                                                               entriesHtml += '<td width="1px" class="weekDay">' + weekDay + '</td><td width="1px" class="date">' + dateStr + '</td><td colspan="2">';\r
                                                } else {\r
-                                                       if (isToday(date))\r
-                                                               entriesHtml += '<td class="date">' + dateStr + '</td><td class="time">' + time + '</td><td colspan="2" class="description">';\r
+                                                       if ((isToday(date) || isTomorrow(date)) && showTodayAsText)\r
+                                                               entriesHtml += '<td colspan="4"><span class="today">' + dateStr + '</span> <span class="time">' + time + '</span> ';\r
                                                        else\r
-                                                               entriesHtml += '<td class="weekDay">' + weekDay + '</td><td class="date">' + dateStr + '</td>&nbsp;<span class="time">' + time + '</span></td><td colspan="2" class="description">';\r
+                                                               entriesHtml += '<td width="1px" class="weekDay">' + weekDay + '</td><td width="1px" class="date">' + dateStr + '</td><td width="1px" class="time">' + time + '</td><td>';\r
                                                }\r
                                        }\r
                                }\r
-                               entriesHtml += Summary + '</td></tr>';\r
+                               entriesHtml += '<span class="description">' + Summary + '</span></td></tr>';\r
                        }\r
                }\r
                entriesHtml += '</table>';\r