diff options
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/calendar.js | 35 | ||||
-rw-r--r-- | www/js/clock.js | 6 |
2 files changed, 30 insertions, 11 deletions
diff --git a/www/js/calendar.js b/www/js/calendar.js index c6b4f61..48ba5ef 100644 --- a/www/js/calendar.js +++ b/www/js/calendar.js @@ -21,12 +21,12 @@ 'use strict'; -var current_week_offset = -4; +var current_week_offset = 0; function getLastMonday() { - var d = new Date(); - d.setHours(0, 0, 0, 0); - var dow = d.getDay() + var d = new Date(clock.getRDTimeMS()); + d.setUTCHours(0, 0, 0, 0); + var dow = d.getUTCDay() if(dow == 0) { return new Date(d - (6*24*3600000)); } else { @@ -35,7 +35,12 @@ function getLastMonday() { } function addDeltaDays(d, days) { - return new Date(d.valueOf() + (days*24*3600000)) + return new Date(d.valueOf() + (days*24*3600000)) +} + +function isThisWeek(d) { + var lastmon = getLastMonday() + return ((d - lastmon) == 0) } function addWeekClass(row, week) { @@ -64,28 +69,38 @@ function calendar_redraw(weekstart) { var date = getLastMonday(); date = addDeltaDays(date, weekstart * 7); for(var w = 0; w < 20; w++) { - var week = get_rd_week(date.valueOf()); + var week = get_rd_week(date.valueOf() + 7199999); var row = $('<tr>'); addWeekClass(row, week); - + if(isThisWeek(date)) { + row.append($('<td>').addClass('currentweek').text('*')); + } else { + row.append($('<td>').addClass('currentweek').text('')); + } row.append($('<td>').addClass('week').text(week)); - row.append($('<td>').addClass('month').text(monthname_short[date.getMonth()])); + row.append($('<td>').addClass('month').text(monthname_short[date.getUTCMonth()] + ' ' + date.getUTCFullYear())); for(var d = 0; d < 7; d++) { - var col = $('<td>').text(date.getDate()); + var col = $('<td>').text(date.getUTCDate()); row.append(col); if(d < 6) { date = addDeltaDays(date, 1); } } - row.append($('<td>').addClass('month').text(monthname_short[date.getMonth()])); + row.append($('<td>').addClass('month').text(monthname_short[date.getUTCMonth()] + ' ' + date.getUTCFullYear())); date = addDeltaDays(date, 1); $('#calendar').append(row); } } function calendar_init() { + $('#btn-today').click(calendar_today); $('#btn-earlier').click(calendar_prev); $('#btn-later').click(calendar_next); + calendar_today() +} + +function calendar_today() { + current_week_offset = -4; calendar_redraw(current_week_offset) } diff --git a/www/js/clock.js b/www/js/clock.js index d62acff..3fa5c24 100644 --- a/www/js/clock.js +++ b/www/js/clock.js @@ -29,8 +29,12 @@ function Clock() { this.clock_rtt = 0; this.state = 'NEW'; + this.getRDTimeMS = function() { + return (+new Date()) + (this.last_message.tz_offset * 1000) + this.clock_offset; + } + this.redraw = function() { - var rdtime_ms = (+new Date()) + (this.last_message.tz_offset * 1000) + this.clock_offset; + var rdtime_ms = this.getRDTimeMS() var rdtime = new Date(rdtime_ms); var date_str = weekday_short[rdtime.getUTCDay()] + ', '; |