summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-07-19 12:55:41 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-07-19 12:55:41 (GMT)
commit6577bb44354778eaa19fffa4b5f60811c72e76db (patch)
tree5b1c410026e2de5bfc71052457cec7e0eaf82c33 /www/js
parentd866b6f9b603da67fee2f200e888200e43b6e74d (diff)
remove week from rd-ntp protocol and readed javascript based calculation
Diffstat (limited to 'www/js')
-rw-r--r--www/js/utils.js26
1 files changed, 24 insertions, 2 deletions
diff --git a/www/js/utils.js b/www/js/utils.js
index b8bbd76..eec81b0 100644
--- a/www/js/utils.js
+++ b/www/js/utils.js
@@ -74,10 +74,32 @@ function msToTimeString(time) {
return h + ':' + m.pad(2) + ':' + s.pad(2) + '.' + hs;
}
+function get_rd_week(msEpoch) {
+ //
+ // This computes the current Rivendell Week based on the number
+ // of weeks since epoch.
+ //
+ // Explanation:
+ // epoch was at 01.01.1970 which was a Thursday.
+ // Monday in that week is (s-from-epoch + 3*24*60*60) seconds ago.
+ // This needs to be adjusted by the timezone offset for Europe/Vienna
+ // which is of course not constant (damn you daylight savings time)
+ // Divide this by (7*24*60*60) and you get the number of
+ // weeks since the Monday in the week of epoch adjusted for timezone offsets.
+ // This week had week number 3 so add an offset of 2 and
+ // get the modulo of 4. This rounded down gives you the current week
+ // with 0 meaning Week 1. So add 1 to that number and you will get
+ // the current RD week.
+ //
+ var sEpoch = ((+msEpoch) / 1000) ;
+ var week = Math.floor((((sEpoch + 259200)/604800) + 2) % 4) + 1;
+ return week;
+}
+
function Clock(draw_callback) {
this.draw_callback = draw_callback;
- this.last_message = { t1: 0, t2: 0, t3: 0, t4: 0, tz_offset: 3600, week: 3 };
+ this.last_message = { t1: 0, t2: 0, t3: 0, t4: 0, tz_offset: 3600 };
this.clock_offset = 0;
this.clock_rtt = 0;
@@ -92,7 +114,7 @@ function Clock(draw_callback) {
time_str += (rdtime.getUTCMinutes() > 9 ? ':' : ':0') + rdtime.getUTCMinutes();
time_str += (rdtime.getUTCSeconds() > 9 ? ':' : ':0') + rdtime.getUTCSeconds();
- this.draw_callback(date_str, time_str, this.last_message.week);
+ this.draw_callback(date_str, time_str, get_rd_week(rdtime_ms));
}
this.ntp_update = function(event) {