relative date test
Anirudh Oppiliappan x@icyphox.sh
Tue, 08 Nov 2022 20:26:21 +0530
3 files changed,
24 insertions(+),
7 deletions(-)
M
views/header.html
→
views/header.html
@@ -20,7 +20,7 @@ {{ if .UserInfo }}
<nav> <ul class="easylinks"> <li><a id="homelink" href="/">home</a> - <li><a id="atmelink" href="/atme">@me<span style="padding:0;margin:0;" id=mecount>{{ if .UserInfo.Options.MeCount }}({{ .UserInfo.Options.MeCount }}){{ end }}</span></a> + <li><a id="atmelink" href="/atme">@me<span style="padding-left:3px;margin:0;" id=mecount>{{ if .UserInfo.Options.MeCount }}({{ .UserInfo.Options.MeCount }}){{ end }}</span></a> <li><a href="/account">account</a> <li><a href="/honkers">honkers</a> <li><a href="/{{ .UserSep }}/{{ .UserInfo.Name }}">{{ .UserInfo.Name }}</a>
M
views/honk.html
→
views/honk.html
@@ -27,7 +27,7 @@ <a class="honkerlink" href="/h?xid={{ .Honker }}" data-xid="{{ .Honker }}">{{ .Username }}</a>
{{ else }} <a href="{{ .Honker }}" rel=noreferrer>{{ .Username }}</a> {{ end }} -<span class="clip"><a href="{{ .URL }}" rel=noreferrer>{{ .What }}</a> {{ .Date.Local.Format "02 Jan 2006 15:04 -0700" }}</span> +<span class="clip"><a href="{{ .URL }}" rel=noreferrer>{{ .What }}</a> <span style="float: right;" id="honkdate">{{ .Date.Local.Format "02 Jan 2006 15:04 MST" }}</span> </span> {{ if .Oonker }} <br> <span class="left1em clip">
M
views/local.js
→
views/local.js
@@ -1,6 +1,23 @@
- const donk = document.getElementById("donkinput"); +function timeSince(timeStamp) { + var now = new Date(), + secondsPast = (now.getTime() - timeStamp) / 1000; + if (secondsPast < 60) { + return parseInt(secondsPast) + 's'; + } + if (secondsPast < 3600) { + return parseInt(secondsPast / 60) + 'm'; + } + if (secondsPast <= 86400) { + return parseInt(secondsPast / 3600) + 'h'; + } + if (secondsPast > 86400) { + day = timeStamp.getDate(); + month = timeStamp.toDateString().match(/ [a-zA-Z]*/)[0].replace(" ", ""); + year = timeStamp.getFullYear() == now.getFullYear() ? "" : " " + timeStamp.getFullYear(); + return day + " " + month + year; + } +} - window.addEventListener('paste', e => { - donk.files = e.clipboardData.files; - }); - donk.onchange(); +var honkdate = document.getElementbyId("honkdate").value; +const ts = Date.parse(honkdate); +honkdate.value = timeSince(ts);