Skip to content

Instantly share code, notes, and snippets.

@ersatzavian
Created December 21, 2013 00:05
Show Gist options
  • Save ersatzavian/8063595 to your computer and use it in GitHub Desktop.
Save ersatzavian/8063595 to your computer and use it in GitHub Desktop.
Calculate seconds til the next time the clock strikes n
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