Created
January 10, 2014 21:26
-
-
Save ajhekman/8362952 to your computer and use it in GitHub Desktop.
perform action at specific time
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
| setSpecific = (callback, hours=0, minutes=0, seconds=0, options={tickRate:10000, repeat:true}) -> | |
| start = new Date() | |
| target = new Date() | |
| #add a day to target if we're already past the time | |
| target.setDate start.getDate() + 1 if start.getHours() > hours or (start.getHours() is hours and start.getMinutes() > minutes) or start.getHours() is hours and start.getMinutes() is minutes and start.getSeconds() >= seconds | |
| target.setHours hours | |
| target.setMinutes minutes | |
| target.setSeconds seconds | |
| console.log "set refresh for #{target}" | |
| intervalID = setInterval -> | |
| unless options.repeat then clearInterval intervalID | |
| if new Date() > target | |
| callback() | |
| , options.tickRate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment