Merge pull request #960 from ostcar/time_format

Time format
This commit is contained in:
Oskar Hahn 2013-10-28 13:05:53 -07:00
commit 76c0a98ab8
5 changed files with 55 additions and 5 deletions

View File

@ -13,3 +13,4 @@ Authors of OpenSlides in chronological order of first contribution:
Pavel Fric <pavelfric@seznam.cz> (Czech translation) Pavel Fric <pavelfric@seznam.cz> (Czech translation)
Max Brauer <max@max-brauer.de> Max Brauer <max@max-brauer.de>
Marco A.G.Pinto <marcoagpinto@mail.telepac.pt> (Portuguese translation) Marco A.G.Pinto <marcoagpinto@mail.telepac.pt> (Portuguese translation)
Dominik Breu <dominikbreu@yahoo.de>

View File

@ -9,6 +9,8 @@
:copyright: 20112013 by OpenSlides team, see AUTHORS. :copyright: 20112013 by OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details. :license: GNU GPL, see LICENSE for more details.
""" """
from time import time
from django.contrib.staticfiles.templatetags.staticfiles import static from django.contrib.staticfiles.templatetags.staticfiles import static
from django.core.context_processors import csrf from django.core.context_processors import csrf
from django.dispatch import receiver, Signal from django.dispatch import receiver, Signal
@ -167,7 +169,8 @@ def projector_clock(sender, **kwargs):
""" """
Returns JavaScript for the projector Returns JavaScript for the projector
""" """
return {'load_file': static('javascript/clock.js')} return {'load_file': static('javascript/clock.js'),
'server_time': int(time())}
return Overlay(name, None, get_projector_html, get_projector_js, return Overlay(name, None, get_projector_html, get_projector_js,
allways_active=True) allways_active=True)

View File

@ -1,8 +1,18 @@
function update_clock() { function update_clock() {
var currentTime = new Date(); var currentTime = projector.get_server_time()
var currentHours = currentTime.getHours(); var currentHours = currentTime.getHours();
var currentMinutes = currentTime.getMinutes(); var currentMinutes = currentTime.getMinutes();
currentHours = normalise(currentHours);
currentMinutes = normalise(currentMinutes);
$('#currentTime').html(currentHours + ':' + currentMinutes); $('#currentTime').html(currentHours + ':' + currentMinutes);
setTimeout('update_clock()', 200); setTimeout('update_clock()', 200);
} }
update_clock(); update_clock();
function normalise(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}

View File

@ -1,6 +1,9 @@
function update_countdown() { function update_countdown() {
var time = new Date().getTime() / 1000; var time = projector.get_server_time().getTime() / 1000;
var seconds; var seconds;
var minutes_digit;
var seconds_digit;
var hours_digit;
var start = projector.projector_countdown_start; var start = projector.projector_countdown_start;
var duration = projector.projector_countdown_duration; var duration = projector.projector_countdown_duration;
var pause = projector.projector_countdown_pause; var pause = projector.projector_countdown_pause;
@ -16,10 +19,34 @@ function update_countdown() {
seconds = duration; seconds = duration;
break; break;
} }
if (seconds !== undefined) { if (seconds > 60) {
hours_digit = Math.floor(seconds / 3600);
minutes_digit = Math.floor((seconds - (hours_digit * 3600)) / 60);
seconds_digit = Math.floor(seconds - (hours_digit * 3600) - (minutes_digit * 60));
minutes_digit = normalise(minutes_digit);
seconds_digit = normalise(seconds_digit);
if (hours_digit > 0) {
hours_digit = normalise(hours_digit);
seconds = hours_digit + ":" + minutes_digit + ":" + seconds_digit;
} else {
seconds = minutes_digit + ":" + seconds_digit;
}
} else {
seconds = Math.max(0, Math.floor(seconds)); seconds = Math.max(0, Math.floor(seconds));
}
if(seconds !== undefined) {
$('#overlay_countdown_inner').html(seconds); $('#overlay_countdown_inner').html(seconds);
} }
setTimeout('update_countdown()', 200); setTimeout('update_countdown()', 200);
} }
update_countdown(); update_countdown();
function normalise(i) {
if(i < 10) {
i = "0" + i;
}
return i;
}

View File

@ -31,11 +31,20 @@ var projector = {
$('#content').css('font-size', 100 + 20 * value + '%'); $('#content').css('font-size', 100 + 20 * value + '%');
}, },
get_server_time: function () {
var date = new Date();
date.setTime(date.getTime() + projector.server_time_offset);
return date;
},
update_data: function(data) { update_data: function(data) {
$.each(data, function (key, value) { $.each(data, function (key, value) {
if (key === 'load_file') if (key === 'load_file')
projector.load_file(value); projector.load_file(value);
else else if (key === 'server_time') {
var local_time = Date.parse(new Date().toUTCString());
projector.server_time_offset = local_time - value * 1000;
} else
projector[key] = value; projector[key] = value;
}); });
} }