Commit c09a79ea authored by Murukesh Mohanan's avatar Murukesh Mohanan

fix long standing bugs in countup

parent 23271711
Pipeline #1368 failed with stage
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<div class="minutes" id="minutes"></div> <div class="minutes" id="minutes"></div>
</div> </div>
<svg id="arcs"> <svg id="arcs">
<circle class="years" id="yeararc" r="22vw" cx="50%" cy="50%"></circle>
<circle class="days" id="dayarc" r="24vw" cx="50%" cy="50%"></circle> <circle class="days" id="dayarc" r="24vw" cx="50%" cy="50%"></circle>
<circle class="hours" id="hourarc" r="25vw" cx="50%" cy="50%"></circle> <circle class="hours" id="hourarc" r="25vw" cx="50%" cy="50%"></circle>
<circle class="minutes" id="minarc" r="25.65vw" cx="50%" cy="50%"></circle> <circle class="minutes" id="minarc" r="25.65vw" cx="50%" cy="50%"></circle>
......
function getTimeSince(startTime) { function getTimeSince(startTime) {
var t = Date.parse(new Date()) - Date.parse(startTime); var t = new Date() - startTime;
var seconds = Math.floor((t / 1000) % 60); var seconds = Math.floor((t / 1000) % 60);
var minutes = Math.floor((t / 1000 / 60) % 60); var minutes = Math.floor((t / 1000 / 60) % 60);
var hours = Math.floor((t / (1000 * 60 * 60)) % 24); var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
...@@ -38,6 +38,9 @@ function initializeClock(id, startTime) { ...@@ -38,6 +38,9 @@ function initializeClock(id, startTime) {
var minutesElem = clock.querySelector('#minutes'); var minutesElem = clock.querySelector('#minutes');
function plural(n, w, wp) { function plural(n, w, wp) {
if (n == 0) {
return '';
}
if (n == 1) { if (n == 1) {
return n + ' ' + w; return n + ' ' + w;
} }
...@@ -47,6 +50,7 @@ function initializeClock(id, startTime) { ...@@ -47,6 +50,7 @@ function initializeClock(id, startTime) {
function updateClock() { function updateClock() {
var t = getTimeSince(startTime); var t = getTimeSince(startTime);
yearsElem.innerHTML = plural(t.years, 'year', 'years');
daysElem.innerHTML = plural(t.days, 'day', 'days'); daysElem.innerHTML = plural(t.days, 'day', 'days');
hoursElem.innerHTML = plural(t.hours, 'hour', 'hours'); hoursElem.innerHTML = plural(t.hours, 'hour', 'hours');
minutesElem.innerHTML = ('0' + t.minutes).slice(-2) + ':' + ('0' + t.seconds).slice(-2); minutesElem.innerHTML = ('0' + t.minutes).slice(-2) + ':' + ('0' + t.seconds).slice(-2);
...@@ -54,7 +58,9 @@ function initializeClock(id, startTime) { ...@@ -54,7 +58,9 @@ function initializeClock(id, startTime) {
minLength = t.minutes + t.seconds/60; minLength = t.minutes + t.seconds/60;
hrLength = t.hours + minLength/60; hrLength = t.hours + minLength/60;
dayLength = t.days + hrLength/24; dayLength = t.days + hrLength/24;
yearLength = t.years + t.days/365;
updateArc("yeararc", dayLength, 365);
updateArc("dayarc", dayLength, 365); updateArc("dayarc", dayLength, 365);
updateArc("hourarc", hrLength, 24); updateArc("hourarc", hrLength, 24);
updateArc("minarc", minLength, 60); updateArc("minarc", minLength, 60);
...@@ -68,7 +74,7 @@ function initializeClock(id, startTime) { ...@@ -68,7 +74,7 @@ function initializeClock(id, startTime) {
var timeinterval = setInterval(updateClock, 1000); var timeinterval = setInterval(updateClock, 1000);
} }
var deadline = new Date('2019-12-22 08:40 +5:30'); var deadline = new Date('2019-12-22T08:40+0530');
document.addEventListener("DOMContentLoaded", function(event) { document.addEventListener("DOMContentLoaded", function(event) {
initializeClock('countdown', deadline); initializeClock('countdown', deadline);
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment