From 164d0b1d0e53c3aa0bd4038e464a150f479bd41a Mon Sep 17 00:00:00 2001 From: Mantas VilĨinskas Date: Sat, 1 May 2021 23:15:09 +0300 Subject: v5.0.2 fix #180 by showing date instead of relative time for future dates report by @untuned --- layouts/partials/js.html | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'layouts/partials/js.html') diff --git a/layouts/partials/js.html b/layouts/partials/js.html index 939cb9a..ef9464a 100644 --- a/layouts/partials/js.html +++ b/layouts/partials/js.html @@ -3,7 +3,7 @@ * Dev toolset */ - console.log('cState v5.0.1 - https://github.com/cstate/cstate'); + console.log('cState v5.0.2 - https://github.com/cstate/cstate'); document.getElementsByTagName('html')[0].className = 'js'; /** @@ -80,6 +80,13 @@ if (interval > 1) { return interval + ' {{ T "minsAgo" }}'; } + + // Negative value + if(Math.floor(seconds) < 0) { + return Math.floor(seconds); + } + + // Non-negative seconds {{ if .Site.Params.skipSeconds }} return '<1 {{ T "minsAgo" }}' {{ else }} @@ -98,10 +105,14 @@ var element = elements[i]; var time = Date.parse(element.getAttribute('title')); var html = element.getAttribute('data-time-prefix') || ''; + + if (!time) { time = element.innerText; element.setAttribute('title', time || new Date); html += '{{ T "justNow" }}'; + } else if (timeSince(time) < 0) { + html = element.innerText; } else { html += timeSince(time) + ' {{ T "someTimeAgo" }}'; } -- cgit v1.2.3-70-g09d2