all repos — honk @ 1d3b7712ff6a76d511977cdf42d23040fa176de0

my fork of honk

views/local.js (view raw)

 1function timeSince(timeStamp) {
 2  var now = new Date(),
 3    secondsPast = (now.getTime() - timeStamp) / 1000;
 4  if (secondsPast < 60) {
 5    return parseInt(secondsPast) + 's';
 6  }
 7  if (secondsPast < 3600) {
 8    return parseInt(secondsPast / 60) + 'm';
 9  }
10  if (secondsPast <= 86400) {
11    return parseInt(secondsPast / 3600) + 'h';
12  }
13  if (secondsPast > 86400) {
14    day = timeStamp.getDate();
15    month = timeStamp.toDateString().match(/ [a-zA-Z]*/)[0].replace(" ", "");
16    year = timeStamp.getFullYear() == now.getFullYear() ? "" : " " + timeStamp.getFullYear();
17    return day + " " + month + year;
18  }
19}
20
21var honkdate = document.getElementbyId("honkdate").value;
22const ts = Date.parse(honkdate);
23honkdate.value = timeSince(ts);