Skip to content
Snippets Groups Projects
Commit a161acab authored by Adam Spiers's avatar Adam Spiers
Browse files

extract time display code into new _displayTime() function

This will allow us to reuse the display code for displaying
an additional pacing timer.
parent eb23e581
No related branches found
No related tags found
No related merge requests found
......@@ -463,22 +463,26 @@
minutesEl = timeEl.querySelector( '.minutes-value' ),
secondsEl = timeEl.querySelector( '.seconds-value' );
function _displayTime( hrEl, minEl, secEl, time) {
var hours = Math.floor( time / ( 1000 * 60 * 60 ) );
var minutes = Math.floor( ( time / ( 1000 * 60 ) ) % 60 );
var seconds = Math.floor( ( time / 1000 ) % 60 );
hrEl.innerHTML = zeroPadInteger( hours );
hrEl.className = hours > 0 ? '' : 'mute';
minEl.innerHTML = ':' + zeroPadInteger( minutes );
minEl.className = minutes > 0 ? '' : 'mute';
secEl.innerHTML = ':' + zeroPadInteger( seconds );
}
function _updateTimer() {
var diff, hours, minutes, seconds,
now = new Date();
diff = now.getTime() - start.getTime();
hours = Math.floor( diff / ( 1000 * 60 * 60 ) );
minutes = Math.floor( ( diff / ( 1000 * 60 ) ) % 60 );
seconds = Math.floor( ( diff / 1000 ) % 60 );
clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } );
hoursEl.innerHTML = zeroPadInteger( hours );
hoursEl.className = hours > 0 ? '' : 'mute';
minutesEl.innerHTML = ':' + zeroPadInteger( minutes );
minutesEl.className = minutes > 0 ? '' : 'mute';
secondsEl.innerHTML = ':' + zeroPadInteger( seconds );
_displayTime( hoursEl, minutesEl, secondsEl, diff );
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment