michaelvillar/timer-app

Timer skips seconds

Closed this issue · 3 comments

Describe the bug
The timer skips seconds from time to time (pun intended). For example, it may go from 53 to 51 without seeing 52.

To Reproduce
Steps to reproduce the behavior:

  1. Set timer to 1 minute
  2. Watch it count down and observe it skipping numbers

Expected behavior
It shouldn't skip numbers.

Desktop (please complete the following information):

  • OS version: macOS 10.15.5
  • Version: 1.5.4

I noticed this too - I was poking around in the source to try to figure out why this was happening. Something related to Foundation.Timer.scheduledTimer(timeInterval maybe?

When I was making the app more energy efficient, I made sure that the UI is only updated once per second. I think what may be happening is that in the unusual case where you happen to start the countdown very close to the seconds boundary, you could get an update at, say 8.99 seconds and then at 8.01 seconds, which would both show as "8".

Note the Foundation repeating timers don't "drift" -- you don't get 8.99 then 7.95 then 6.91, then 5.86. It's just an issue of variance around the boundary where you might get 8.99 then 8.01 then 6.99 then 6.01.

This implies the fix is to make sure the repeating timer starts safely away from a boundary -- to make sure you get updates at for example 9.09, 8.11, 7.08, 6.10, 5.09 (the variance doesn't affect the significant digit).

Fix #94 looks good.