How block system change time ?
Mijeko opened this issue ยท 7 comments
Hello. Why time changed when i set time by Windows? I set start value as [0, 0, 0, 0, 5] (5 days ) then i change day in my PC +2 days and that timer changed from 5d to 3d. Why ?
Hi!
It is a know issue of the library. It uses the system date to make the calculations, but this method has the problem that you commented. I have tried to solve it with other methods, but this is the best I found.
The only thing I can do is to put a Warning in the docs explaining the problem.
Best reards!
Hi @albert-gonzalez can you help me understanding the issue a bit better? Maybe I can help with it.
hi @ewerton-azevedo !
Sure. The issue is that the library uses Date to calculate the elapsed time. Date uses the system clock, so if the clock changes while the timer is running, the initial date will have the original clock value, but the current value will get the new one, and the difference between dates will be wrong. You can see how the lib uses Date here: https://github.com/albert-gonzalez/easytimer.js/blob/master/src/easytimer/easytimer.js#L154
Best regards!
I am not completely sure whether this is an issue or not.
Javascript uses the system clock by design, that means, there is no issue with the library.
I tried to come up with something to "solve" that but so far my only idea was to make an external api call to get the date from another source but, is that really a good idea?
@albert-gonzalez what other methods have you tried using, I am really interested on that because I could not find anything and will def learn something new from it.
Best regards!
Hi @ewerton-azevedo . I think the same as you, it is a limitation, so there is nothing we can do about it.
I tried two other methods:
- The first versions of the lib used setInterval and calculate the difference every time counting units of time instead of using Dates. That wasn't a good idea because setInterval is not precise, and the timer didn't work well.
- I tried to use performance.now, but that didn't work as expected neither.
Best regards!
Thank you for explaining it to me.
I would like to help with something but in this case I dont believe we can change anything.
Best regards!
I have added a Known Issues mentioning this case. I close this issue for now.