Difference between revisions of "Widget:Countdown"

From Octopath Traveler Speedruns
Jump to navigation Jump to search
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
<span><!--{$time}--></span><br />
<!--{$time}--> ET<br />
<span id="countdown">Jan 1, 0000 00:00:00</span>
<i id="countdown">?</i>


<script>
<script>
// I literally just copied this from w3
// Modified version of https://www.w3schools.com/howto/howto_js_countdown.asp


var countDownDate = new Date("<!--{$time}-->").getTime();
// Conversion from Eastern Time to UTC
var easternTimeOffset = 5 * 60 * 60000;
if ("<!--{$dst}-->" == "true") {
  var easternTimeOffset = 4 * 60 * 60000;
}
 
var rawDateTimeET = new Date("<!--{$time}-->").getTime();
var countDownDateUTC = rawDateTimeET + easternTimeOffset;


// Update the count down every 1 second
// Update the count down every 1 second
var x = setInterval(function() {
var x = setInterval(function() {
 
   // Get the users date and time and convert to UTC
   // Get todays date and time
   var rawNow = new Date();
   var now = new Date().getTime();
  var nowUTC = rawNow.getTime() + (rawNow.getTimezoneOffset() * 60000);


   // Find the distance between now and the count down date
   // Find the distance between now and the count down date
   var distance = countDownDate - now;
   var distance = countDownDateUTC - nowUTC;


   // Time calculations for days, hours, minutes and seconds
   // Time calculations for days, hours, minutes
   var days = Math.floor(distance / (1000 * 60 * 60 * 24));
   var days = Math.floor(distance / (1000 * 60 * 60 * 24));
   var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
   var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
   var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
   var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((distance % (1000 * 60)) / 1000);
  // Display the result in the element with id="demo"
  document.getElementById("countdown").innerHTML = days + "d " + hours + "h "
  + minutes + "m " + seconds + "s ";


   // If the count down is finished, write some text
   // Display the result in the element with id="countdown"
  document.getElementById("countdown").innerHTML = "I am error.";
 
   if (distance < 0) {
   if (distance < 0) {
     clearInterval(x);
     clearInterval(x);
     document.getElementById("countdown").innerHTML = "EXPIRED";
     document.getElementById("countdown").innerHTML = "The race has ended.";
  } else if (days > 0) {
    document.getElementById("countdown").innerHTML = "(In about " + days + " days and " + hours + " hours)";
  } else if (days == 0) {
    document.getElementById("countdown").innerHTML = "(In about " + hours + " hours and " + minutes + " minutes)";
   }
   }
}, 1000);
}, 1000);
</script>
</script>

Latest revision as of 05:18, 27 January 2019

ET

?

<script> // Modified version of https://www.w3schools.com/howto/howto_js_countdown.asp

// Conversion from Eastern Time to UTC var easternTimeOffset = 5 * 60 * 60000; if ("" == "true") {

 var easternTimeOffset = 4 * 60 * 60000;

}

var rawDateTimeET = new Date("").getTime(); var countDownDateUTC = rawDateTimeET + easternTimeOffset;

// Update the count down every 1 second var x = setInterval(function() {

 // Get the users date and time and convert to UTC
 var rawNow = new Date();
 var nowUTC = rawNow.getTime() + (rawNow.getTimezoneOffset() * 60000);
 // Find the distance between now and the count down date
 var distance = countDownDateUTC - nowUTC;
 // Time calculations for days, hours, minutes
 var days = Math.floor(distance / (1000 * 60 * 60 * 24));
 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
 // Display the result in the element with id="countdown"
 document.getElementById("countdown").innerHTML = "I am error.";
 
 if (distance < 0) {
   clearInterval(x);
   document.getElementById("countdown").innerHTML = "The race has ended.";
 } else if (days > 0) {
   document.getElementById("countdown").innerHTML = "(In about " + days + " days and " + hours + " hours)";
 } else if (days == 0) {
   document.getElementById("countdown").innerHTML = "(In about " + hours + " hours and " + minutes + " minutes)";
 }

}, 1000); </script>