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
...@@ -463,22 +463,26 @@ ...@@ -463,22 +463,26 @@
minutesEl = timeEl.querySelector( '.minutes-value' ), minutesEl = timeEl.querySelector( '.minutes-value' ),
secondsEl = timeEl.querySelector( '.seconds-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() { function _updateTimer() {
var diff, hours, minutes, seconds, var diff, hours, minutes, seconds,
now = new Date(); now = new Date();
diff = now.getTime() - start.getTime(); 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' } ); clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } );
hoursEl.innerHTML = zeroPadInteger( hours ); _displayTime( hoursEl, minutesEl, secondsEl, diff );
hoursEl.className = hours > 0 ? '' : 'mute';
minutesEl.innerHTML = ':' + zeroPadInteger( minutes );
minutesEl.className = minutes > 0 ? '' : 'mute';
secondsEl.innerHTML = ':' + zeroPadInteger( seconds );
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment