robcowie/jquery-stopwatch — pull request #9 by MicahChalmer (2013-01-14 04:56:34+00:00)
Title: Use the system clock to determine elapsed time

Hi Rob,

I created a patch to make it use the system clock, rather than relying on receiving every interval, to determine the elapsed time. This allows it to show the true elapsed time even if it missed (or duplicated) some of its timer events, which should make it more accurate.

The main reason I did this was for use on Android and iOS. On iOS, if I go back to the home screen or switch to a different browser tab, the page stops receiving javascript timer events. On Android it manages to send events while in the background, but only until the screen goes to sleep. With the code as it stands, the stopwatch won't advance when it's not receiving events, so you can't trust the time it shows if the page isn't constantly visible. With my patch, it is able to catch up and display the true elapsed time, even if the device has gone to sleep in the middle.

I would also guess that this probably fixes the problem @Blacksus described in #6. I don't know if it actually does fix it, because I never ran into the #6 problem myself. But this patch would make it show an accurate elapsed time, even if the time between the interval events becomes weird.