Skip to content

Commit

Permalink
Merge pull request moloch--#590 from sdoliner/master
Browse files Browse the repository at this point in the history
corrected countdown timer display
  • Loading branch information
eljeffeg committed Sep 19, 2023
2 parents b5aee17 + 41b921e commit 758fb57
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 36 deletions.
20 changes: 12 additions & 8 deletions static/js/pages/admin/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,25 @@ function setTimer(distance) {
// Update the count down every 1 second
var x = setInterval(function() {
// Time calculations for days, hours, minutes and seconds
var hours = Math.floor(distance / 3600000);
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
var days = Math.max(0,Math.floor((distance) / (1000 * 60 * 60 * 24)));
var hours = Math.max(0,Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)));
var minutes = Math.max(0,Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)));
var seconds = Math.max(0,Math.floor((distance % (1000 * 60)) / 1000));

// Display the result in the element with id="demo"
var hourval = "";
// Display the result in the element with id="timercount"
var timercount = padDigits(minutes,2) + "m " + padDigits(seconds,2) + "s ";
if (hours > 0) {
hourval = hours + "h ";
timercount = hours + "h " + timercount;
}
$("#timercount").text(hourval + padDigits(minutes,2) + "m " + padDigits(seconds,2) + "s ");
if (days > 0) {
timercount = days + "d " + timercount;
}
$("#timercount").text(timercount);

// If the count down is finished, write some text
if (distance <= 0) {
clearInterval(x);
$("#timercount").text("");
$("#timercount").text("EXPIRED");
location.reload()
}
distance = distance - 1000;
Expand Down
12 changes: 8 additions & 4 deletions static/js/pages/scoreboard/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,16 +492,20 @@ function setTimer(distance, id) {
// Update the count down every 1 second
var x = setInterval(function() {
// Time calculations for days, hours, minutes and seconds
var days = Math.max(0,Math.floor((distance) / (1000 * 60 * 60 * 24)));
var hours = Math.max(0,Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)));
var minutes = Math.max(0,Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)));
var seconds = Math.max(0,Math.floor((distance % (1000 * 60)) / 1000));

// Display the result in the element with id="demo"
var hourval = "";
// Display the result in the element with id="timercount"
var timercount = padDigits(minutes,2) + "m " + padDigits(seconds,2) + "s ";
if (hours > 0) {
hourval = hours + "h ";
timercount = hours + "h " + timercount;
}
$("#timercount" + id).text(hourval + padDigits(minutes,2) + "m " + padDigits(seconds,2) + "s ");
if (days > 0) {
timercount = days + "d " + timercount;
}
$("#timercount" + id).text(timercount);

// If the count down is finished, write some text
if (distance <= 0) {
Expand Down
13 changes: 8 additions & 5 deletions static/js/pages/scoreboard/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,23 @@ function padDigits(number, digits) {
}

function setTimer(distance, id) {

// Update the count down every 1 second
var x = setInterval(function() {
// Time calculations for days, hours, minutes and seconds
var days = Math.max(0,Math.floor((distance) / (1000 * 60 * 60 * 24)));
var hours = Math.max(0,Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)));
var minutes = Math.max(0,Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)));
var seconds = Math.max(0,Math.floor((distance % (1000 * 60)) / 1000));

// Display the result in the element with id="demo"
var hourval = "";
// Display the result in the element with id="timercount"
var timercount = padDigits(minutes,2) + "m " + padDigits(seconds,2) + "s ";
if (hours > 0) {
hourval = hours + "h ";
timercount = hours + "h " + timercount;
}
$("#timercount" + id).text(hourval + padDigits(minutes,2) + "m " + padDigits(seconds,2) + "s ");
if (days > 0) {
timercount = days + "d " + timercount;
}
$("#timercount" + id).text(timercount);

// If the count down is finished, write some text
if (distance <= 0) {
Expand Down
42 changes: 23 additions & 19 deletions static/js/pages/scoreboard/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,29 @@ function padDigits(number, digits) {
}

function setTimer(distance, id) {
// Update the count down every 1 second
var x = setInterval(function () {
// Time calculations for days, hours, minutes and seconds
var hours = Math.max(0,Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)));
var minutes = Math.max(0,Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)));
var seconds = Math.max(0,Math.floor((distance % (1000 * 60)) / 1000));
// Update the count down every 1 second
var x = setInterval(function() {
// Time calculations for days, hours, minutes and seconds
var days = Math.max(0,Math.floor((distance) / (1000 * 60 * 60 * 24)));
var hours = Math.max(0,Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)));
var minutes = Math.max(0,Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)));
var seconds = Math.max(0,Math.floor((distance % (1000 * 60)) / 1000));

// Display the result in the element with id="demo"
var hourval = "";
if (hours > 0) {
hourval = hours + "h ";
}
$("#timercount" + id).text(hourval + padDigits(minutes, 2) + "m " + padDigits(seconds, 2) + "s ");
// Display the result in the element with id="timercount"
var timercount = padDigits(minutes,2) + "m " + padDigits(seconds,2) + "s ";
if (hours > 0) {
timercount = hours + "h " + timercount;
}
if (days > 0) {
timercount = days + "d " + timercount;
}
$("#timercount" + id).text(timercount);

// If the count down is finished, write some text
if (distance <= 0) {
clearInterval(x);
$("#timercount" + id).text("EXPIRED");
}
distance = distance - 1000;
}, 1000);
// If the count down is finished, write some text
if (distance <= 0) {
clearInterval(x);
$("#timercount" + id).text("EXPIRED");
}
distance = distance - 1000;
}, 1000);
}

0 comments on commit 758fb57

Please sign in to comment.