Skip to content

Instantly share code, notes, and snippets.

@oreillyross
Created February 14, 2016 20:41
Show Gist options
  • Save oreillyross/7b2c75ad6b31e365c203 to your computer and use it in GitHub Desktop.
Save oreillyross/7b2c75ad6b31e365c203 to your computer and use it in GitHub Desktop.
timingfunctions.js
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