You are reading a single comment by @Numerist and its replies.
Click here to read the full conversation.
-
Well my actual code is more complex but the basic idea is this:
setInterval(function() { // adjust by 630 milliseconds let adjusted_time = Date.now() - 630; let delay = 1000 - (adjusted_time % 1000); setTimeout(function() { setTime((adjusted_time + delay) / 1000); }, delay); // adjust every 3 hours }, 3 * 60 * 60 * 1000);
Every 3 hours:
- get current watch time
- calculate adjusted time
- calculate delay until adjusted time is exact second
- wait that delay and then set watch time in seconds
Only one running app must do this or else there will be too much adjustment. I'm currently using code like this in my clock app, but it would be best if it were run in a widget (however I havn't yet learned how to make widgets).
- get current watch time
For my test clock I'm currently using the option 5) I mentioned in 2nd message in this thread.