I have an object which contains some data about progression of a bar but it keeps stopping at 99% and won't continue, i believe its because client time is not going to be the same as server time accurately enough to do it. So i don't know how to solve it.
These 2 timers are created server side and sent to the client.
myOjb[i].end: 1374805587 //seconds since epoch for when 100% is made
myObj[i].strt: 1374805527 //seconds since epoch when it started
The function that is calculating the percentage :
function clocker() {
var now = new Date().getTime() / 1000;
for (var i in myObj) {
if (myObj[i].end > now) {
var remain = myObj[i].end - now;
var per = (now - myObj[i].strt) / (myObj[i].end - myBuildings[i].strt) * 100;
var per = fix_percentage(per); // stops > 100 and < 0 returns int if true
myObj[i].percentage = Math.ceil(per);
console.log(myObj[i].percentage); //reaches 99 max
if (myObj[i].percentage > 99) {
console.log('test'); //never occurs
return false;
}
break;
} else {
continue;
}
}
setTimeout(clocker, 1000);
}
function fix_percentage(per){
if(per>100)per=100;
if(per<0)per = 0;
return Math.round(per);
}
How could i sync the two together so the timing is more accurate ?