From 1c2f67f93e01a4b0f9f2bb690c77821fb6dd9326 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 22 Jun 2016 18:35:00 +0200 Subject: fix date/time offset, add button for 'today' 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 = $(''); addWeekClass(row, week); - + if(isThisWeek(date)) { + row.append($('').addClass('currentweek').text('*')); + } else { + row.append($('').addClass('currentweek').text('')); + } row.append($('').addClass('week').text(week)); - row.append($('').addClass('month').text(monthname_short[date.getMonth()])); + row.append($('').addClass('month').text(monthname_short[date.getUTCMonth()] + ' ' + date.getUTCFullYear())); for(var d = 0; d < 7; d++) { - var col = $('').text(date.getDate()); + var col = $('').text(date.getUTCDate()); row.append(col); if(d < 6) { date = addDeltaDays(date, 1); } } - row.append($('').addClass('month').text(monthname_short[date.getMonth()])); + row.append($('').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()] + ', '; diff --git a/www/styles/week.css b/www/styles/week.css index 211f1ad..5536059 100644 --- a/www/styles/week.css +++ b/www/styles/week.css @@ -35,6 +35,7 @@ font-size: 1.3em; font-weight: bold; padding: 0.3em 3em; + margin: 0.2em; } #rightcol { @@ -57,7 +58,13 @@ font-weight: bold; text-align: center; padding: 0.3em; - border-bottom: 1px solid white; + border-bottom: 1px solid #eee; +} + +#calendar td.currentweek { + font-size: 1.2em; + font-weight: bold; + background-color: #eee; } #calendar td.week { @@ -66,9 +73,9 @@ } #calendar td.month { - width: 3em; + width: 6em; font-size: 1.2em; font-weight: bold; - border-left: 2px solid white; - border-right: 2px solid white; + border-left: 2px solid #eee; + border-right: 2px solid #eee; } diff --git a/www/weeks.html b/www/weeks.html index 42c8e29..832e032 100644 --- a/www/weeks.html +++ b/www/weeks.html @@ -28,6 +28,9 @@
+
+ +
@@ -38,6 +41,7 @@ + Mo Di Mi -- cgit v0.10.2