Created
December 21, 2013 00:05
-
-
Save ersatzavian/8063595 to your computer and use it in GitHub Desktop.
Calculate seconds til the next time the clock strikes n
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 secondsTil(now,targetTime) { | |
local data = split(targetTime,":"); | |
local target = { hour = data[0].tointeger(), min = data[1].tointeger() }; | |
if ((target.hour < now.hour) || (target.hour == now.hour && target.min < now.min)) { | |
target.hour += 24; | |
} | |
local secondsTill = 0; | |
secondsTill += (target.hour - now.hour) * 3600; | |
secondsTill += (target.min - now.min) * 60; | |
return secondsTill; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment