From f24abe797ee64b20c71dc37419655a10b5d592b4 Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+Rsl1122@users.noreply.github.com> Date: Fri, 29 Jan 2021 12:35:09 +0200 Subject: [PATCH] Fixed time formatter --- .../src/main/resources/assets/plan/web/js/query.js | 10 ++++++---- .../src/main/resources/assets/plan/web/query.html | 8 ++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Plan/common/src/main/resources/assets/plan/web/js/query.js b/Plan/common/src/main/resources/assets/plan/web/js/query.js index 19f13311a..96b71eaad 100644 --- a/Plan/common/src/main/resources/assets/plan/web/js/query.js +++ b/Plan/common/src/main/resources/assets/plan/web/js/query.js @@ -277,7 +277,7 @@ function correctTime(value) { while (hour > 23) hour--; let minute = Number(d[2]); while (minute > 59) minute--; - return hour + ":" + minute; + return (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute); } function setFilterOption( @@ -285,7 +285,8 @@ function setFilterOption( elementId, propertyName, isValidFunction, - correctionFunction + correctionFunction, + dontUpdateGraph ) { const query = id === 'view' ? filterView : filterQuery.find(function (f) { return f.id === id; @@ -301,7 +302,7 @@ function setFilterOption( element.classList.remove("is-invalid"); query[propertyName] = value; // Updates either the query or filterView properties InvalidEntries.setAsValid(elementId); - if (id === 'view') updateViewGraph(); + if (id === 'view' && !dontUpdateGraph) updateViewGraph(); } else { element.classList.add("is-invalid"); InvalidEntries.setAsInvalid(elementId); @@ -321,7 +322,8 @@ function updateViewGraph() { const parsedYear = Number(d[3]); let hour = Number(t[1]); let minute = Number(t[2]); - return new Date(parsedYear, parsedMonth, parsedDay, hour, minute).getTime(); + const date = new Date(parsedYear, parsedMonth, parsedDay, hour, minute); + return date.getTime() - (date.getTimezoneOffset() * 60000); } const graph = graphs[0]; diff --git a/Plan/common/src/main/resources/assets/plan/web/query.html b/Plan/common/src/main/resources/assets/plan/web/query.html index b8ce8d57f..dd61420cb 100644 --- a/Plan/common/src/main/resources/assets/plan/web/query.html +++ b/Plan/common/src/main/resources/assets/plan/web/query.html @@ -364,7 +364,7 @@ const playersOnlineSeries = { name: 'Players Online', type: 'areaspline', tooltip: {valueDecimals: 0}, - data: json.viewPoints, color: '#1E90FF', yAxis: 0 + data: json.viewPoints, color: '#9E9E9E', yAxis: 0 } graphs.push(Highcharts.stockChart('viewChart', { @@ -395,7 +395,11 @@ document.getElementById('viewFromTimeField').value = afterTime; document.getElementById('viewToDateField').value = beforeDate; document.getElementById('viewToTimeField').value = beforeTime; - filterView = {afterDate, afterTime, beforeDate, beforeTime}; + const dontUpdateGraph = true; + setFilterOption('view', 'viewFromDateField', 'afterDate', isValidDate, correctDate, dontUpdateGraph); + setFilterOption('view', 'viewFromTimeField', 'afterTime', isValidTime, correctTime, dontUpdateGraph); + setFilterOption('view', 'viewToDateField', 'beforeDate', isValidDate, correctDate, dontUpdateGraph); + setFilterOption('view', 'viewToTimeField', 'beforeTime', isValidTime, correctTime, dontUpdateGraph); } } }