Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing an option always resets relative countdowns. #96

Open
bzurmaar opened this issue Feb 28, 2024 · 0 comments
Open

Changing an option always resets relative countdowns. #96

bzurmaar opened this issue Feb 28, 2024 · 0 comments

Comments

@bzurmaar
Copy link

Using the option function causes relative countdowns to restart. This can be reproduced with the following steps:

  1. Visit the demo page at http://keith-wood.name/countdownBasics.html. Open the browser's developer console to enter JS.
  2. Stop the running countdown with
    $('#defaultCountdown').countdown('destroy');
  3. Start a new countdown with a relative expiry with
    $('#defaultCountdown').countdown({until: '+1m'});
  4. Change anything in the configuration with e.g.
    $('#defaultCountdown').countdown('option', 'format', 'MS');

You'll see that the countdown starts counting down again from 1 minute although that option wasn't changed. After a brief inspection of the code I pinned the error down to https://github.com/kbwood/countdown/blob/master/src/js/jquery.countdown.js#L384. There is a check if the timezone changed. It is assume changed, if the two timezones are not equal. As the new config option does not have a timezone set the test always concludes that the timezone changed an the countdown has to be restarted.

There is also a workaround for this. You can grab the current timezone from the options and reapply that together with the actual change intended like this:

let timezone = $('#defaultCountdown').countdown('option', 'timezone');
$('#defaultCountdown').countdown('option', { format: 'YODHMS', timezone: timezone });

Thanks for the great component! My team is using it in an E-Assessment system at the university of Duisburg-Essen and it works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant