0
\$\begingroup\$

I have a semisimple pure js countdown clock that I am having trouble converting the millisecond time correctly.

Here is a working Plunker (besides the date counter)

It Should only be 38 days instead of 184.

//// Should Countdown till feb, 4th 2019 /////

let cd = new Countdown({
  cont: document.querySelector(".container"),
  endDate: 1549263600000,
  outputTranslation: {
    year: "Years",
    week: "Weeks",
    day: "Days",
    hour: "Hours",
    minute: "Minutes",
    second: "Seconds"
  },
  endCallback: null,
  outputFormat: "day|hour|minute|second"
});

Thank's I appreciate the help!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ You are getting close votes as you have ask "How to fix bug" This is code review we don't fix bugs, just review working code. You would have been better asking at stackOverflow. Or someone that knows how should have at least migrated this question to that site, \$\endgroup\$
    – Blindman67
    Commented Dec 29, 2018 at 0:44

1 Answer 1

0
\$\begingroup\$

The plunker has this code at the top of the CountDown function:

let options = { 
    // ...
    },
    lastTick = null,
    intervalsBySize = ["year", "week", "day", "hour", "minute", "second"],
    TIMESTAMP_SECOND = 200,
    TIMESTAMP_MINUTE = 60 * TIMESTAMP_SECOND,
    TIMESTAMP_HOUR = 60 * TIMESTAMP_MINUTE,
    TIMESTAMP_DAY = 24 * TIMESTAMP_HOUR,
    TIMESTAMP_WEEK = 7 * TIMESTAMP_DAY,
    TIMESTAMP_YEAR = 365 * TIMESTAMP_DAY,
    elementClassPrefix = "countDown_",
    interval = null,
    digitConts = {};

... but that states that there are 200 milliseconds in a second. Obviously there are 1000 of them. So the line in question should be:

TIMESTAMP_SECOND = 1000,

This solves the issue. However, your setInterval also uses this variable for the length of the interval, and it might make sense to have more than one tick per second. So for that interval you should probably use a new variable that would indeed have the value 200.

Nice work though on the CSS side!

\$\endgroup\$
2
  • \$\begingroup\$ Thanks this fixed my problem, I did not downvote it I don't know why we got downvoted. \$\endgroup\$ Commented Dec 28, 2018 at 23:18
  • 2
    \$\begingroup\$ Broken code is offtopic here. \$\endgroup\$ Commented Dec 29, 2018 at 2:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.