Browse Source

Added new row for ETA time and fixed a stupid date manipulation bug.

master
Trey Del Bonis 4 years ago
parent
commit
69b6a7966c
2 changed files with 21 additions and 2 deletions
  1. 1
    0
      www/index.html
  2. 20
    2
      www/main.js

+ 1
- 0
www/index.html View File

@@ -18,6 +18,7 @@
<h1>Bitcoin Block Halving Countdown!</h1>
<h3><span id="blocksleft">...</span> blocks left</h3>
<h3><span id="timeleft">... remaining</span></h3>
<h3 id="halftimectr"><span id="halftime">ETA ...</span></h3>
<p>
Click/tap on the rows for more statistics - <a href="#faq">FAQ</a>
</p>

+ 20
- 2
www/main.js View File

@@ -90,7 +90,7 @@ function toggleElemSelected(elem) {
function formatDate(date) {
let year = date.getUTCFullYear();
let month = "0" + (1 + date.getUTCMonth());
let day = "0" + (1 + date.getUTCDate());
let day = "0" + date.getUTCDate();
let hours = "0" + date.getUTCHours();
let minutes = "0" + date.getUTCMinutes();
let seconds = "0" + date.getUTCSeconds();
@@ -150,7 +150,7 @@ function makeBlockElem(block, prevBlock) {
// Make the timestamp element.
let timestampElem = document.createElement("span");
let timestampDate = new Date(block.timestamp * 1000);
timestampElem.innerHTML = formatDate(timestampDate);
timestampElem.innerHTML = formatDate(timestampDate) + " UTC";
dataElem.appendChild(timestampElem);

// this makes it look a lot nicer
@@ -251,6 +251,7 @@ function makeBlockElem(block, prevBlock) {

var blocksLeftElem = null;
var timeLeftElem = null;
var halfTimeElem = null;

function updateRemainingCount(block) {
if (blocksLeftElem == null) {
@@ -261,11 +262,20 @@ function updateRemainingCount(block) {
timeLeftElem = document.getElementById("timeleft");
}

if (halfTimeElem == null) {
halfTimeElem = document.getElementById("halftime");
}

let blocksLeft = nextHalvingHeight - curTipBlock.height;
blocksLeftElem.innerHTML = blocksLeft.toString()

if (blocksLeft < 1) {
timeLeftElem.innerHTML = "Halving imminent!";

// Hide the expected time.
let timectr = document.getElementById("halftimectr");
timectr.style.display = "none";

} else {
let nowUnix = Date.now() / 1000; // wtf???

@@ -286,6 +296,14 @@ function updateRemainingCount(block) {
}

timeLeftElem.innerHTML = "roughly " + acc + " remaining";

// Reward halving date.
let localNow = new Date();
let tzOff = (new Date()).getTimezoneOffset() * 60 * 1000;
let etaDate = new Date(localNow.getTime() + (secsLeft * 1000) - tzOff);
let formattedEtaDate = formatDate(etaDate);
halfTimeElem.innerHTML = "around " + formattedEtaDate + " local time";

}
}


Loading…
Cancel
Save