Read the statement by Michael Teeuw here.
Not updating at midnight...
-
@BKeyport the code sets the interval to midnight -now
So unless this is started at midnight- it will update whenever
So you need a set timeout for now til midnight, and then an interval for every midnight since this first midnight
So updateDom
Now
Timeout Midnight tonight
Start interval for next and following midnights -
I think you see it backwards.
Look at the reset variable again.
This line calculates the difference between the current time and midnight of the next day. It does this by creating a new Date object for the next day at 00:00:00.000 (midnight) and subtracting the current time from it.
The variable timer is then set using the reset variable, so…
new Date(year, month, nextday, 0, 0, 0, 0).getTime() - date.getTime()
Assuming it’s currently 6:30pm on August 8th, 2024.
2024/8/9 0:0:0.0 - 2024/8/8 18:30:0.0
1723186800 - 1723167000 (Dropping the milliseconds if used)
= 19800then the timer is set using setInterval() to “reset” or 19800 - which would be the next midnight.
After the first one, it should be calculating so close to midnight, it’s an non-issue.
-
@BKeyport setInterval creates a repeating timer with ONE elapsed time
6:30pm to midnight the next day is 24+5.5
So every 29.5 hours it will fire.
1st correct for tomorrow night,
it will miss tonight’s midnightAnd then be off from them on, shifting 5.5 hours later each time
24 hours of seconds is 86400
If you think of it as morning, then it will fire every 5.5 hours. Still not 24
After the first one, it should be calculating so close to midnight, it’s an non-issuee
This part is incorrect. setInterval only looks at the value ONE time.
Sorry, computer is stupid. It has one time event setTimeout, or interval setInterval. Both use the elapsed time only once, at creation
-
@sdetweil The problem is that it’s not firing at all - it was working as is… Now it’s not firing, first, last, middle, or any other time.
-
-
@sdetweil It’s people like you that drive people out of coding. This isn’t fun anymore.
Is there anyone other than Sam that could explain why this don’t work anymore?
-
@BKeyport that’s very disappointing to hear.
I thought I was being helpful in giving ways to debug the problem.
I do not KNOW why it appears to be failing. None of the changes to the mm core appear to affect updateDom
-
How about this? not tested.
start: function () { this.dailyTimer = null const moment = new Date() const midnight = new Date(moment.getFullYear(), moment.getMonth(), moment.getDate() + 1, 0, 0, 0, 0) const toMidnight = midnight - moment setTimeout(() => { this.doSomething() }, toMidnight) }, doSomething: function () { clearTimeout(this.dailyTimer) this.dailyTimer = null // Do your job here. this.dailyTimer = setTimeout(() => { this.doSomething() }, 24 * 60 * 60 * 1000) }
-
@MMRIZE right, thats a way without interval timer
I added this to compliments with the cron entries to get the interval synched to the minute
let minute_sync_delay = 1; // loop thru all the configured when events for (let m of Object.keys(this.config.compliments)) { // if it is a cron entry if (this.isCronEntry(m)) { // we need to synch our interval cycle to the minute minute_sync_delay = (60 - (moment().second())) * 1000; break; } } // Schedule update timer. sync to the minute start (if needed), so minute based events happen on the minute start setTimeout(() => { setInterval(() => { this.updateDom(this.config.fadeSpeed); }, this.config.updateInterval); }, minute_sync_delay);
-
@MMRIZE one thing
You can’t clear the timer if it has triggered, as the timer has expired. The handle is no longer valid