Created
January 24, 2015 23:59
-
-
Save jessekinsman/306a7c53a7cfe2bb0797 to your computer and use it in GitHub Desktop.
Javascript function to check if time has elapsed between two dates
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
// lastUpdate param should be a date object or a number representing milliseconds since 1970 | |
// interval param should be seconds | |
// Interval is the elapsed time you are checking | |
// Returns true if the interval time has elapsed | |
// Returns false if the interval has not elapsed | |
function update(lastUpdate, interval) { | |
var curTime = new Date().getTime(); | |
lastUpdate = (typeof lastUpdate.getTime == "function")? lastUpdate.getTime(): lastUpdate; | |
interval *= 1000; | |
curTime -= interval; | |
return (lastUpdate >= curTime) ? false: true; | |
} | |
// You could do more typechecking on the lastUpdate param if you are unsure of the data you are passing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment