Skip to content

Instantly share code, notes, and snippets.

@pauladam
Created October 20, 2011 00:32
Show Gist options
  • Select an option

  • Save pauladam/1300092 to your computer and use it in GitHub Desktop.

Select an option

Save pauladam/1300092 to your computer and use it in GitHub Desktop.
Seconds till next tuesday (coffeescript)
# returns seconds till next tuesday @ noon - 5 minutes
exports.reckonTimeoutValue = ()->
# num days till next tuesday
tuesOffset =
2 : 7
3 : 6
4 : 5
5 : 4
6 : 3
0 : 2
1 : 1
now = new Date()
curTime = now.getTime()
oneDay = 1000 * 60 * 60 * 24
daysTillNextTues = tuesOffset[now.getDay()] * oneDay
nextTuesday = new Date(curTime + daysTillNextTues)
nextTuesday.setHours(11)
nextTuesday.setMinutes(55)
return nextTuesday.getTime() - curTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment