Reputation:
I am using moment (for current time) and waitjs (repeat) modules.
If i write the codes as the below:
repeat(86400000, function() { //DASHBOARD
});
This function repeat every 1 hour. But it has counted since the program started.
I want to work with system time. For example; when the system time 1:00:00 (A.M.) the function will be work. And continues every hour.
How can i do this?
THANKS!
Upvotes: 0
Views: 645
Reputation: 1952
Using Moment.js and waitjs you would do something like this:
// Wait until end of hour
wait(moment().endOf('hour') - moment(), function() {
// Start executing repeat function
repeat(86400000, function() { //DASHBOARD
});
});
Check out Moment.js endOf
Upvotes: 1
Reputation: 2055
On program startup you can get the time until the next full hour, so for example:
Use this time to delay the execution of the first function call, this call be done with setTimemout (http://nodejs.org/api/timers.html). Following the example you would set a delay of forty minutes, and then the function would execute at 2:00AM.
You can then in this executed function, setup your repeat function to repeat every full hour.
Upvotes: 1