We have a use case of running the java script thread once a month. But what we observe is if we provide 3.5 weeks of delay for the setinterval function it does not respect it and starts getting scheduling once a second. is it a bug? does it have any maxiumum limit for giving the delay?
Interestingly same works fine for setTimeOut. -
<!DOCTYPE html>
<html>
<body>
<input type="text" id="clock" />
<script>
var int=setInterval(function(){clock()},1000*60*60*24*7*3.5);
function clock()
{
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("clock").value=t;
}
</script>
<button onclick="int=window.clearInterval(int)">Stop</button>
</body>
</html>
1000*60*60*24*7*3.5 = 0x7e2bce00
Which is awfully close to 0x80000000, I wonder if 32 but signed arithmetic somewhere might be responsible.
I just checked the specification and the timeout for setInterval and setTimeout are both defined as long values which means signed 32 bit. It is unclear how a negativetimeout value would be treated.
From the WhatWG spec :
long setTimeout(Function handler, optional long timeout, any... arguments);
From the WebIDL standard :
The long type is a signed integer type that has values in the range [−2147483648, 2147483647].
To fix your problem I can make two suggestions:
Since setTimeout works, use it and retrigger at the end of the processing function
Alternatively setInterval of half the period you want and use a toggle to execute your code every other time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With