Hi. I am tryinmg to put the finishing touches on a web-based race clock. It is not working for me. The problem appears to be the value I am placing into the JS script.
Here is the classic asp:
[code]
dRaceTime = Date & " " & ConvertToMinutes(Round(lngRaceStart + sngStartTime, 0)) 'remove tenths
dRaceTime = Left(dRaceTime, Len(dRaceTime) - 2) 'truncate to remove ".0"
dRaceStart = DateDiff("s","1/1/1970 00:00:00", dRaceTime) * 1000 'convert to milliseconds
[/code]
js...pretty sure it is correct...not my code
[code]
<script>
var TTimer = {
startedTime: <%=dRaceStart%>,
restoredFromSession: false,
started: false,
minutes: 0,
seconds: 0,
tick: function tick() {
// Since setInterval is not reliable in inactive windows/tabs we are using date diff.
var diffInSeconds = Math.floor((new Date() - this.startedTime) / 1000);
this.minutes = Math.floor(diffInSeconds / 60);
this.seconds = diffInSeconds - this.minutes * 60;
this.render();
this.updateSession();
},
utilities: {
pad: function pad(number) {
return number < 10 ? '0' + number : number;
}
},
container: function container() {
return $(document);
},
render: function render() {
this.container().find('#timer-minutes').text(this.utilities.pad(this.minutes));
this.container().find('#timer-seconds').text(this.utilities.pad(this.seconds));
},
updateSession: function updateSession() {
sessionStorage.setItem('timerStartedTime', this.startedTime);
},
clearSession: function clearSession() {
sessionStorage.removeItem('timerStartedTime');
},
restoreFromSession: function restoreFromSession() {
// Using sessionsStorage to make the timer persistent
if (typeof Storage == "undefined") {
console.log('No sessionStorage Support');
return;
}
if (sessionStorage.getItem('timerStartedTime') !== null) {
this.restoredFromSession = true;
this.startedTime = new Date(sessionStorage.getItem('timerStartedTime'));
}
},
start: function start() {
this.restoreFromSession();
this.stop();
this.started = true;
this.tick();
this.timerId = setInterval(this.tick.bind(this), 1000);
},
stop: function stop() {
this.started = false;
clearInterval(this.timerId);
this.render();
}
};
TTimer.start();
</script>
[/code]
What is not working for you? what is the input and expected output? you can't just paste code here and expect us to review it and know the problem without understanding your requirements.