From 3e1ab7ceb34be7865771508f52f9c65477f6fb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 13 Nov 2023 13:58:17 +0100 Subject: [PATCH 1/2] Fix inital date/time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- scripts/pi-hole/js/queries.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 1e77f325..f4dcd380 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -34,8 +34,8 @@ function initDateRangePicker() { timePickerIncrement: 5, timePicker24Hour: true, locale: { format: dateformat }, - startDate: moment(from * 1000), - endDate: moment(until * 1000), + startDate: moment(from), + endDate: moment(until), ranges: { "Last 10 Minutes": [moment().subtract(10, "minutes"), moment()], "Last Hour": [moment().subtract(1, "hours"), moment()], From 3cf7eb82b95e9839750ec8ad72a304ac18eb0e34 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 13 Nov 2023 22:05:36 +0100 Subject: [PATCH 2/2] Be explicit about where seconds and where milliseconds are used Signed-off-by: DL6ER --- scripts/pi-hole/js/queries.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index f4dcd380..22674e9d 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -7,8 +7,8 @@ /* global moment:false, utils:false */ -const beginningOfTime = 1262304000000; // Jan 01 2010, 00:00 -const endOfTime = 2147483647000; // Jan 19, 2038, 03:14 +const beginningOfTime = 1262304000; // Jan 01 2010, 00:00 in seconds +const endOfTime = 2147483647; // Jan 19, 2038, 03:14 in seconds var from = beginningOfTime; var until = endOfTime; @@ -34,8 +34,8 @@ function initDateRangePicker() { timePickerIncrement: 5, timePicker24Hour: true, locale: { format: dateformat }, - startDate: moment(from), - endDate: moment(until), + startDate: moment(from * 1000), // convert to milliseconds since epoch + endDate: moment(until * 1000), // convert to milliseconds since epoch ranges: { "Last 10 Minutes": [moment().subtract(10, "minutes"), moment()], "Last Hour": [moment().subtract(1, "hours"), moment()], @@ -52,13 +52,15 @@ function initDateRangePicker() { moment().subtract(1, "month").endOf("month"), ], "This Year": [moment().startOf("year"), moment().endOf("year")], - "All Time": [moment(beginningOfTime), moment(endOfTime)], + "All Time": [moment(beginningOfTime * 1000), moment(endOfTime * 1000)], // convert to milliseconds since epoch }, opens: "center", showDropdowns: true, autoUpdateInput: true, }, function (startt, endt) { + // Update global variables + // Convert milliseconds (JS) to seconds (API) from = moment(startt).utc().valueOf() / 1000; until = moment(endt).utc().valueOf() / 1000; } @@ -447,7 +449,8 @@ function getAPIURL(filters) { } // Omit from/until filtering if we cannot reach these times. This will speed - // up the database lookups notably on slow devices. + // up the database lookups notably on slow devices. The API accepts timestamps + // in seconds since epoch if (from > beginningOfTime) apiurl += "&from=" + from; if (until > beginningOfTime && until < endOfTime) apiurl += "&until=" + until;