From a13aea478e325b30d413da008d6d0e525720250b Mon Sep 17 00:00:00 2001 From: Nazar Kanaev Date: Tue, 20 Oct 2020 21:29:36 +0100 Subject: [PATCH] attack of the monster feeds from the future --- assets/javascripts/app.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/app.js b/assets/javascripts/app.js index 422233f..fad8b5b 100644 --- a/assets/javascripts/app.js +++ b/assets/javascripts/app.js @@ -80,14 +80,21 @@ Vue.component('drag', { function dateRepr(d) { var sec = (new Date().getTime() - d.getTime()) / 1000 + var neg = sec < 0 + var out = '' + + sec = Math.abs(sec) if (sec < 2700) // less than 45 minutes - return Math.round(sec / 60) + 'm' + out = Math.round(sec / 60) + 'm' else if (sec < 86400) // less than 24 hours - return Math.round(sec / 3600) + 'h' + out = Math.round(sec / 3600) + 'h' else if (sec < 604800) // less than a week - return Math.round(sec / 86400) + 'd' + out = Math.round(sec / 86400) + 'd' else - return d.toLocaleDateString(undefined, {year: "numeric", month: "long", day: "numeric"}) + out = d.toLocaleDateString(undefined, {year: "numeric", month: "long", day: "numeric"}) + + if (neg) return '-' + out + return out } Vue.component('relative-time', {