I want to run a function at specific time points in a particular timeframe, say from 5:30 to 14:30. The specific time points would be increments of 3 minutes from 5:30 like so, 5:30, 5:33, 5:36,...,6:00 etc until 14:30. I thought the logic would be as simple as checking if the current time in integer format was a multiple of 3 and checking if the "seconds" in the current time was "00", since I want to run it only at the beginning of these specific time points. But this logic is incorrect. Since a lot of time points such as 10:00, 11:00, 13:00, 14:00 etc are not divisible by 3. Also, the browser freezes because of the while loop. How do I go about this and what is the correct logic here?
myFunc = () => {
//Some Task
};
myFunc();
var dateToday = Date();
while (Number(dateToday.getHours()+(dateToday.getMinutes()<10?'0':'') + dateToday.getMinutes())) >= 530 && Number(dateToday.getHours()+(dateToday.getMinutes()<10?'0':'') + dateToday.getMinutes()) <= 1430){
var dateTodayCheck = new Date(),
hoursCheck = dateTodayCheck.getHours(),
minutesCheck = (dateTodayCheck.getMinutes()<10?'0':'')
+ dateTodayCheck.getMinutes(),
secondsCheck = (dateTodayCheck.getSeconds()<10?'0':'')
+ dateTodayCheck.getSeconds();
var timeNowCheck = Number(hoursCheck+minutesCheck)
var remainder = timeNowCheck % 3
if (remainder === 0 && secondsCheck==="00") {
myFunc();
};
};