Fixed time formatter

This commit is contained in:
Risto Lahtela 2021-01-29 12:35:09 +02:00
parent 4b4aa2d7d9
commit f24abe797e
2 changed files with 12 additions and 6 deletions

View File

@ -277,7 +277,7 @@ function correctTime(value) {
while (hour > 23) hour--; while (hour > 23) hour--;
let minute = Number(d[2]); let minute = Number(d[2]);
while (minute > 59) minute--; while (minute > 59) minute--;
return hour + ":" + minute; return (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute);
} }
function setFilterOption( function setFilterOption(
@ -285,7 +285,8 @@ function setFilterOption(
elementId, elementId,
propertyName, propertyName,
isValidFunction, isValidFunction,
correctionFunction correctionFunction,
dontUpdateGraph
) { ) {
const query = id === 'view' ? filterView : filterQuery.find(function (f) { const query = id === 'view' ? filterView : filterQuery.find(function (f) {
return f.id === id; return f.id === id;
@ -301,7 +302,7 @@ function setFilterOption(
element.classList.remove("is-invalid"); element.classList.remove("is-invalid");
query[propertyName] = value; // Updates either the query or filterView properties query[propertyName] = value; // Updates either the query or filterView properties
InvalidEntries.setAsValid(elementId); InvalidEntries.setAsValid(elementId);
if (id === 'view') updateViewGraph(); if (id === 'view' && !dontUpdateGraph) updateViewGraph();
} else { } else {
element.classList.add("is-invalid"); element.classList.add("is-invalid");
InvalidEntries.setAsInvalid(elementId); InvalidEntries.setAsInvalid(elementId);
@ -321,7 +322,8 @@ function updateViewGraph() {
const parsedYear = Number(d[3]); const parsedYear = Number(d[3]);
let hour = Number(t[1]); let hour = Number(t[1]);
let minute = Number(t[2]); 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]; const graph = graphs[0];

View File

@ -364,7 +364,7 @@
const playersOnlineSeries = { const playersOnlineSeries = {
name: 'Players Online', type: 'areaspline', tooltip: {valueDecimals: 0}, 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', { graphs.push(Highcharts.stockChart('viewChart', {
@ -395,7 +395,11 @@
document.getElementById('viewFromTimeField').value = afterTime; document.getElementById('viewFromTimeField').value = afterTime;
document.getElementById('viewToDateField').value = beforeDate; document.getElementById('viewToDateField').value = beforeDate;
document.getElementById('viewToTimeField').value = beforeTime; 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);
} }
} }
} }