Created
September 18, 2011 19:37
-
-
Save MatrixFrog/1225459 to your computer and use it in GitHub Desktop.
Countdown clock for psychogate.com
This file contains 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() { | |
function getCurrentTime() { | |
var now = new Date(); | |
var nowInUTC = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds()); | |
var nowInPacific = new Date(nowInUTC - 7*60*60*1000); | |
return nowInPacific; | |
} | |
function getNextStartTimeAfter(time) { | |
var startTimes = [ | |
new Date(2011, 9, 1, 6, 0, 0, 0), | |
new Date(2011, 9, 29, 6, 0, 0, 0), | |
new Date(2011, 9, 1, 6, 0, 0, 0), | |
new Date(2011, 10, 12, 6, 0, 0, 0), | |
new Date(2011, 10, 26, 6, 0, 0, 0) | |
]; | |
for (var i in startTimes) { | |
startTime = startTimes[i]; | |
if (startTime > time) { | |
return startTime; | |
} | |
} | |
} | |
function startCountdown() { | |
var now = getCurrentTime(); | |
var timeUntilNextPsychogate = getNextStartTimeAfter(now) - now; | |
setInterval(function() { | |
displayTime(timeUntilNextPsychogate); | |
timeUntilNextPsychogate -= 1000; | |
}, 1000); | |
} | |
var countdownDiv = $('#countdown'); | |
var secondInMillis = 1000; | |
var minuteInMillis = 60*secondInMillis; | |
var hourInMillis = 60*minuteInMillis; | |
var dayInMillis = 24*hourInMillis; | |
function displayTime(time) { | |
var days = Math.floor(time / dayInMillis); | |
time -= days*dayInMillis; | |
var hours = Math.floor(time / hourInMillis); | |
time -= hours*hourInMillis; | |
var minutes = Math.floor(time / minuteInMillis); | |
time -= minutes*minuteInMillis; | |
var seconds = Math.floor(time / secondInMillis); | |
countdownDiv.text( | |
days + ':' + | |
zeroPad(hours) + ':' + | |
zeroPad(minutes) + ':' + | |
zeroPad(seconds)); | |
} | |
function zeroPad(x) { | |
return (x.toString().length < 2) ? '0'+x : x | |
} | |
startCountdown(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment