robcowie / jquery-stopwatch

A jQuery plugin that renders a count-up clock from a defined start time
http://robcowie.github.com/jquery-stopwatch/
87 stars 31 forks source link

Use the system clock to determine elapsed time #9

Open MicahChalmer opened 11 years ago

MicahChalmer commented 11 years ago

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.

Yoda-BZH commented 10 years ago

:+1: Tested this weekend on ~24H, works as expected. Fixes #6 for me.

Thanks !