Skip to content

Instantly share code, notes, and snippets.

@johnjelinek
Created June 23, 2012 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnjelinek/2977199 to your computer and use it in GitHub Desktop.
Save johnjelinek/2977199 to your computer and use it in GitHub Desktop.
countdown in coffeescript
counter = (futureDate) ->
today = new Date
count = Math.floor (futureDate - today) / 1000
countdown = setInterval ->
$("#d").html Math.floor count / ( 60 * 60 * 24 )
temp = count % ( 60 * 60 * 24 )
$("#h").html Math.floor temp / ( 60 * 60 )
temp = count % ( 60 * 60 )
$("#m").html Math.floor temp / 60
temp = count % 60
$("#s").html temp
counter new Date today.getFullYear(), today.getMonth(), today.getDate() + 1 if count isnt 0
count--
, 1000
today = new Date today
counter new Date today.getFullYear(), today.getMonth(), today.getDate() + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment