Skip to content

Commit

Permalink
Merge cf116bb into da81eb8
Browse files Browse the repository at this point in the history
  • Loading branch information
stromblom committed Jun 21, 2019
2 parents da81eb8 + cf116bb commit a1fadec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions app/resources/js/ticker.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@

// todo: there's probably a more elegant way to implement this :)

let currentDateNow = null;

function ticker() {
tick();
setInterval(tick, 1000);
}

function tick() {
const now = new Date();
const nextHour = new Date();
nextHour.setHours(now.getHours() + 1);
nextHour.setMinutes(0);
nextHour.setSeconds(0);
const el = document.getElementById('tickers');

if (el != null) {
// el.getElementsByClassName('ticker-local')[0].innerHTML = hms(now);
el.getElementsByClassName('ticker-server')[0].innerHTML = hms(utc(now));
el.getElementsByClassName('ticker-next-tick')[0].innerHTML = hms(nextHour - now);
if(currentDateNow == null)
{
const currentServerTime = el.getElementsByClassName('ticker-server')[0].innerHTML;
currentDateNow = new Date('1970-01-01T' + currentServerTime + 'Z');
}

currentDateNow.setUTCSeconds(currentDateNow.getUTCSeconds() + 1);

const nextHour = new Date(currentDateNow);
nextHour.setUTCHours(currentDateNow.getUTCHours() + 1);
nextHour.setMinutes(0);
nextHour.setSeconds(0);

el.getElementsByClassName('ticker-server')[0].innerHTML = hms(utc(currentDateNow));
console.log(nextHour);
console.log(currentDateNow);
console.log(nextHour - currentDateNow);
el.getElementsByClassName('ticker-next-tick')[0].innerHTML = hms(nextHour - currentDateNow);
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/resources/views/partials/tickers.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Local: <span class="ticker-local">00:00:00</span>
</span>--}}
<span class="badge">
Server: <span class="ticker-server">00:00:00</span>
Server: <span class="ticker-server">{{date("H:i:s")}}</span>
</span>
<span class="badge">
Tick: <span class="ticker-next-tick">00:00:00</span>
Expand Down

0 comments on commit a1fadec

Please sign in to comment.