Created
May 20, 2012 04:02
-
-
Save larzconwell/2743463 to your computer and use it in GitHub Desktop.
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
alarmTime = "13:30"; // 1:30 pm | |
set_alarm = function() { | |
// Convert alarmTime to 24 format if it's 12 format | |
var alarmCopy = (Options.timeFormat === '12') ? toggle_time_format(alarmTime) : alarmTime | |
, time = new Date() | |
, cHour = time.getHours() | |
, cMin = time.getMinutes() | |
// Extract hour and minute from alarmCopy string | |
, aHour = Number(alarmCopy.replace(/:[0-9]+/, '')) | |
, aMin = Number(alarmCopy.replace(/[0-9]+:/, '')) | |
, millHour | |
, millMin | |
, tillAlarm; | |
// This kind of works, but messes up horribly | |
// - when the alarmTime is before the current time | |
if(aHour < cHour) { | |
millHour = ((24 - cHour) + aHour) * 3600000; | |
} else millHour = (aHour - cHour) * 3600000; | |
if(aMin < cMin) { | |
millMin = ((60 - cMin) + aMin) * 600000; | |
} else millMin = (aMin - cMin) * 600000; | |
tillAlarm = millHour + millMin; | |
clearInterval(alarmLoop); | |
alarmLoop = undefined; | |
alarmLoop = setTimeout(function() { | |
alert("alarm"); | |
}, tillAlarm); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment