From fc721969528078fe6c623cc998c11f94a66fdbb0 Mon Sep 17 00:00:00 2001 From: Michael Prager Date: Sun, 11 Oct 2009 13:46:48 +0200 Subject: [PATCH] added support for daylight saving time (DST) --- comingNext/index.html | 78 +++++++++ comingNextB/index.html | 350 ++++++++++++++++++++++++++--------------- 2 files changed, 301 insertions(+), 127 deletions(-) diff --git a/comingNext/index.html b/comingNext/index.html index 35d1632..9ec9f99 100644 --- a/comingNext/index.html +++ b/comingNext/index.html @@ -42,6 +42,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 var showNothingText = true; // if set to "true", show a text if no events are in the list var nothingText = 'No further events within ' + monthRange + ' months'; // text to show when no events are in the list +var enableDaylightSaving = true;// enable this if you are in a timezone that has daylight saving time (+1h) //------------------------------------------------------- // Nothing of interest from here on... @@ -53,10 +54,77 @@ var months_translated = []; var orientation = ''; var now = new Date(); +// vars for daylight saving time +var daylightsavingWinter = 0; +var daylightsavingSummer = 0; +var summertime = false; + window.onload = init; window.onresize = updateScreen; window.onshow = updateScreen; +function isLeapYear( year ) { + if (( year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0 ) + return true; + else + return false; +} + +function calcLeapYear(year, days) +{ + if (isLeapYear(year)) + return ++days; + else + return days; +} + +function subToSunday(myDate, year, days, prevMonthDays) +{ + for (i = myDate.getDay(); i > 0 ;i--) + days--; + days -= prevMonthDays; + days = isLeapYear(year) ? --days : days; + return days; +} + +function calcDaylightSaving() +{ + var thisYearS = new Date(now.getFullYear(), 3, 0, 0, 0, 0 ); + var thisYearW = new Date(now.getFullYear(), 10, 0, 0, 0, 0 ); + var nextYearS = new Date(now.getFullYear() + 1, 3, 0, 0, 0, 0 ); + var nextYearW = new Date(now.getFullYear() + 1, 10, 0, 0, 0, 0 ); + var summer = false; + var winter = false; + + thisYearSDays = nextYearSDays = 90; + thisYearWDays = nextYearWDays = 304; + + thisYearSDays = calcLeapYear(now.getFullYear(), thisYearSDays); + thisYearWDays = calcLeapYear(now.getFullYear(), thisYearWDays); + nextYearSDays = calcLeapYear(now.getFullYear() + 1, nextYearSDays); + nextYearWDays = calcLeapYear(now.getFullYear() + 1, nextYearWDays); + + thisYearSDays = subToSunday(thisYearS, now.getFullYear(), thisYearSDays, 59); + thisYearWDays = subToSunday(thisYearW, now.getFullYear(), thisYearWDays, 273); + nextYearSDays = subToSunday(nextYearS, now.getFullYear() + 1, nextYearSDays, 59); + nextYearWDays = subToSunday(nextYearW, now.getFullYear() + 1, nextYearWDays, 273); + + daylightsavingSummer = new Date (now.getFullYear(), 03-1, thisYearSDays, 2, 0, 0); + daylightsavingWinter = new Date (now.getFullYear(), 10-1, thisYearWDays, 2, 0, 0); + if (daylightsavingSummer < now) { + daylightsavingSummer = new Date (now.getFullYear()+1, 03-1, nextYearSDays, 2, 0, 0); + var summer = true; + } + if (daylightsavingWinter < now) { + daylightsavingWinter = new Date (now.getFullYear()+1, 10-1, nextYearWDays, 2, 0, 0); + var winter = true; + } + if (summer && !winter) + summertime = true; + else + summertime = false; +} + function error(message) { console.info('Error: ' + message); @@ -242,6 +310,15 @@ function parseDate(dateString) console.info('year=' + year + ' month=' + month + ' day=' + day + ' hours=' + hours + ' minutes=' + minutes+ ' seconds=' + seconds); + // take care of daylight saving time + if (enableDaylightSaving) { + var date = new Date(year, month - 1, day, hours, minutes, seconds); + if (summertime && date > daylightsavingWinter && date < daylightsavingSummer) + hours -= 1; + else if (!summertime && date > daylightsavingSummer && date < daylightsavingWinter) + hours += 1; + } + return new Date(year, month - 1, day, hours, minutes, seconds); } @@ -313,6 +390,7 @@ function formatTime(date) function updateData() { + calcDaylightSaving(); try { // meetings have time // 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 diff --git a/comingNextB/index.html b/comingNextB/index.html index 5a53715..b5631d3 100644 --- a/comingNextB/index.html +++ b/comingNextB/index.html @@ -2,7 +2,9 @@ + Coming Next + + + + +
- \ No newline at end of file + + -- 2.39.2