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--;
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];

View File

@ -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);
}
}
}