Skip to content

Instantly share code, notes, and snippets.

@cyb3rd4d
Created June 24, 2015 09:42
Show Gist options
  • Save cyb3rd4d/7b43c0e9e7dc70d487ac to your computer and use it in GitHub Desktop.
Save cyb3rd4d/7b43c0e9e7dc70d487ac to your computer and use it in GitHub Desktop.
A timers for Node.js
var now = new Date();
var valuatedAt = new Date();
var maxTime = new Date();
valuatedAt.setMinutes(now.getMinutes() - 1);
maxTime.setMinutes(valuatedAt.getMinutes());
maxTime.setSeconds(valuatedAt.getSeconds() + 80);
console.log('Initialization....');
console.log('now: ' + now);
console.log('valuatedAt: ' + valuatedAt);
console.log('maxTime: ' + maxTime);
console.log('---------------------------');
var interval = setInterval(function() {
var now = new Date();
console.log('Comparing ' + maxTime + ' and ' + now);
diffResult = maxTime > now;
console.log(maxTime > now);
if (!diffResult) {
clearInterval(interval);
}
}, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment