whattimeisitrightmeow icon indicating copy to clipboard operation
whattimeisitrightmeow copied to clipboard

Please show seconds

Open ehuggett opened this issue 6 years ago • 4 comments

😄

ehuggett avatar Sep 19 '17 00:09 ehuggett

We could use javascript to get the seconds!1! :rofl: :man_facepalming: :nerd_face:

We don't want to trust the client, however, do we?

neuhaus avatar Sep 19 '17 08:09 neuhaus

Oh boy

smaslennikov avatar Sep 19 '17 11:09 smaslennikov

I have requested #13 as i found time.txt to be quite useful for ""resynchronising"" the clock periodically in its current format (while playing around, below), and this didn't seem to be intentional.

var time = document.getElementById("time").innerHTML;
var date = new Date();
date.setHours(time.substring(0,3));
date.setMinutes(time.substring(4,7));
date.setSeconds(00);
localStorage.setItem("now", date);
setInterval(updateClock, 1000);

function updateClock() {
  if ( Math.floor(Math.random() * 60) != 0) {
    var notNow = new Date(localStorage.now);
    notNow.setSeconds(notNow.getSeconds() + 1);
    // notNow is now now, as we have updated the seconds so that it is now now.
    time.innerHTML = notNow;
    localStorage.setItem("now",notNow);
  } else {
    // get the new now
    fetch('http://smaslennikov.com/whattimeisitrightmeow/time.txt').then(function(response) {
      return response.text();
    }).then(function(text) {
      var date = new Date();
      date.setHours(text.substring(0,3));
      date.setMinutes(text.substring(4,6));
      date.setSeconds(00);

      time.innerHTML = date;
      localStorage.setItem("now",date);
    });
  }
}

edit: anyone got anything more creative?

ehuggett avatar Sep 19 '17 16:09 ehuggett

+1 on this issue. This is a major blocker for me in using your code in production.

thecosmicfrog avatar Sep 23 '17 21:09 thecosmicfrog