Search code examples
javascriptjquerycountdown

Getting countdown to count correctly


Hey all i have this code posted here: http://jsfiddle.net/mN6Gy/12/

Problem is it skips numbers in the seconds (goes from 30, 25, 24, 23, 22, 21, 20, 15,...)

and once the seconds reach 00 it start back over on 99, 98, 97, 96...!!

Any help to find this in the code would be great!

Thanks,

David


Solution

  • Oh boy, this is was not fun to debug - and I'm not sure I have all the answers...

    The issue I found is that you have too many days so your indexes are off.

    Options.format: "dd:hh:mm:ss"
    > Actually have '119:01:16:18' (for example)
    

    So when you are looping through, all your indexes are off by one - for now. But when the time gets to <100 days, it would be right - I think.

    As a hacky solution to see what I mean (and so you may have a place to start the fix), see this editing snippet:

        switch (options.format[i]) {
          case 'h':
            digits[c].__max = ((c-1) % 2 == 0) ? 2: 9;  // <== EDIT
            if (c % 2 == 0)
              digits[c].__condmax = 4;
            break;
          case 'd':
            digits[c].__max = 9;
            break;
          case 'm':
          case 's':
            digits[c].__max = ((c-1) % 2 == 0) ? 5: 9;  // <== EDIT
        }