Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setInterval for longer hours

Tags:

javascript

Is setInterval method reliable for longer hours? I have a requirement to trigger functions for once everyday and/or once everyweek. So am using setInterval(myFunc, 86400000) //For one day. similarly calculated number of milliseconds for one week Is this a good approach. or is there anyother technique i can use.

like image 290
Srikanth Avatar asked Nov 13 '22 23:11

Srikanth


1 Answers

I think a good option would be,

when the web page opens first store the date to local storage, when its open normally check the date in local storage every minute and then validate it and take action.

setIterval sounds like a very bad way of doing it here...

On start up get the data,

save the date using localStorage.setItem("date", datevariblename);

on load or everytime you in the set interval use localStorage.getItem("date") to get the date value

Then do what every comparsion is required between current date and save date

like image 161
Lemex Avatar answered Nov 15 '22 11:11

Lemex