Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Fixing timer offset issues (#905 / #1047) (#1182)
Browse files Browse the repository at this point in the history
* Fixing timer offset issues (#905 / #1047)
  • Loading branch information
Viras- authored and simonschaufi committed May 18, 2018
1 parent a3b3a84 commit db1a430
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
3 changes: 2 additions & 1 deletion extensions/ki_timesheets/templates/scripts/timeSheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,10 @@
$('#display_total').html(ts_total);

<?php if ($this->latest_running_entry == null): ?>
updateRecordStatus(false);
updateRecordStatus(<?php echo time(); ?>, false);
<?php else: ?>
updateRecordStatus(
<?php echo time(); ?>,
<?php echo $this->latest_running_entry['timeEntryID']?>,
<?php echo $this->latest_running_entry['start']?>,
<?php echo $this->latest_running_entry['customerID']?>,
Expand Down
14 changes: 5 additions & 9 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function stopRecord() {
);
}

function updateRecordStatus(record_ID, record_startTime, customerID, customerName, projectID, projectName, activityID, activityName) { // Updated
function updateRecordStatus(serverTime, record_ID, record_startTime, customerID, customerName, projectID, projectName, activityID, activityName) {
// if awaiting updateRecordStatus from buzzer
if (typeof timeout_updateRecordStatus != 'undefined'){
clearTimeout(timeout_updateRecordStatus);
Expand All @@ -375,11 +375,9 @@ function updateRecordStatus(record_ID, record_startTime, customerID, customerNam
show_selectors();
return;
}

// Update offset accuracy
if ( typeof stopwatch_init_time != 'undefined' && (stopwatch_init_time + offset) != record_startTime ){
offset = stopwatch_init_time - record_startTime;
}

// calculate offset (note: this does not take into account network latencies - but I guess for display this should be accurate enough)
var offset = serverTime - ((new Date()).getTime() / 1000);

startsec = record_startTime + offset;

Expand All @@ -396,7 +394,6 @@ function show_stopwatch() {
$("#ticker_project").html($("#selected_project").html());
$("#ticker_activity").html($("#selected_activity").html());
$("ul#ticker").newsticker();
stopwatch_init_time = Math.floor((new Date()).getTime() / 1000);
ticktac();
}

Expand All @@ -412,7 +409,7 @@ function show_selectors() {
}

function buzzer() {
if ( currentRecording == 0 || $('#buzzer').hasClass('disabled') ) return;
if (currentRecording == 0 || $('#buzzer').hasClass('disabled')) return;

if (currentRecording > -1) {
stopRecord();
Expand Down Expand Up @@ -516,7 +513,6 @@ function ticktac() {
function ticktack_off() {
if (timeoutTicktack) {
clearTimeout(timeoutTicktack);
delete stopwatch_init_time;
timeoutTicktack = 0;
$("#h").html("00");
$("#m").html("00");
Expand Down

0 comments on commit db1a430

Please sign in to comment.