Created
February 14, 2016 20:41
-
-
Save oreillyross/7b2c75ad6b31e365c203 to your computer and use it in GitHub Desktop.
timingfunctions.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addMinutes(date, minutes) { | |
return new Date(date.getTime() + minutes * 60000); | |
} | |
function getTimeRemaining(deadline) { | |
const t = Date.parse(deadline) - Date.parse(new Date()) | |
const seconds = Math.floor((t / 1000) % 60); | |
const minutes = Math.floor((t / 1000 / 60) % 60) | |
return { | |
'total': t, | |
'seconds': seconds, | |
'minutes': minutes | |
} | |
} | |
function updateClock(timeRemaining) { | |
const t = timeRemaining | |
minutes.innerHTML = ('0' + t.minutes).slice(-2) | |
seconds.innerHTML = ('0' + t.seconds).slice(-2) | |
if (t.total <= 0) { | |
clearInterval(timeInterval) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment