From c5af89c44842371f6f5a50eaeb30b33aa806dd7d Mon Sep 17 00:00:00 2001 From: Cocker Koch Date: Tue, 27 Nov 2018 00:02:24 +0100 Subject: [PATCH] Issue-260: Correct Calculation of Timedifferences in index.html For calculating Timedifferences (12h, 7d, 30d) there is reused the Variable "now". Indeed the Substractions are cumulated in the Variable, resulting in incorrect Timedifferences. - use moment() instead of Variable "now" - rename Timevariables to be more speaking - introduce a Timevariable f0 for "now" - add Seconds to Timeformat to be more intuitive to ISO8601-Format - add GET-Variable "to", to be editable more easy in Addressbar - resort GET-Variables "from" and "to" to Front, to be editable more easy in Addressbar --- docroot/index.html | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docroot/index.html b/docroot/index.html index e0fb146..7227b55 100644 --- a/docroot/index.html +++ b/docroot/index.html @@ -52,11 +52,10 @@ console.log("dataURI = " + dataURI); - var now = moment(); - - var f12 = now.subtract(12, 'hours').utc().format('YYYY-MM-DDTHH:mm'); - var f7 = now.subtract(7, 'days').utc().format('YYYY-MM-DDTHH:mm'); - var f30 = now.subtract(30, 'days').utc().format('YYYY-MM-DDTHH:mm'); + var f0 = moment().utc().format('YYYY-MM-DDTHH:mm:ss'); + var f12h = moment().utc().subtract(12, 'hours').format('YYYY-MM-DDTHH:mm:ss'); + var f7d = moment().utc().subtract(7, 'days').format('YYYY-MM-DDTHH:mm:ss'); + var f30d = moment().utc().subtract(30, 'days').format('YYYY-MM-DDTHH:mm:ss'); $.ajax({ url: dataURI, @@ -75,17 +74,18 @@ continue; } d['udev'] = "user=" + d['username'] + "&device=" + d['device']; - d['f12'] = f12; - d['f7'] = f7; - d['f30'] = f30; + d['f0'] = f0; + d['f12h'] = f12h; + d['f7d'] = f7d; + d['f30d'] = f30d; var line = "{{ username }} / {{ device }}" + - "12h" + - "7d" + + "12h" + + "7d" + - "12h" + - "7d" + - "30d" + + "12h" + + "7d" + + "30d" + ""; var row = Mustache.render(line, d);