Skip to content

Commit ee39167

Browse files
committed
Reviewer suggestions
Signed-off-by: Adam Warner <[email protected]>
1 parent 6ba28e1 commit ee39167

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

scripts/js/queries.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// These values are provided by the API (/info/database).
1313
// We initialize them as null and populate them during page init.
1414
let beginningOfTime = null; // seconds since epoch (set from API: info/database.earliest_timestamp)
15-
let endOfTime = null; // seconds since epoch (set to end of today)
15+
// endOfTime should be the start of tomorrow in seconds since epoch
16+
// We don't use 23:59:59 as the picker increments are set to 5 minutes
17+
const endOfTime = luxon.DateTime.now().plus({ days: 1 }).startOf("day").toSeconds(); // seconds since epoch (start of tomorrow)
1618
let from = null;
1719
let until = null;
1820

@@ -63,10 +65,6 @@ function getDatabaseInfo() {
6365
beginningOfTime = Math.floor(beginningOfTime / 300) * 300;
6466
}
6567

66-
// endOfTime should be the start of tomorrow in seconds since epoch
67-
// We don't use 23:59:59 as the picker increments are set to 5 minutes
68-
endOfTime = luxon.DateTime.now().plus({ days: 1 }).startOf("day").toSeconds();
69-
7068
// If from/until were not provided via GET, default them
7169
// Only use defaults if beginningOfTime is valid
7270
if (beginningOfTime !== null) {
@@ -80,25 +78,28 @@ function getDatabaseInfo() {
8078

8179
function initDateRangePicker() {
8280
// If there's no valid data in the database, disable the datepicker
83-
if (beginningOfTime === null || endOfTime === null) {
81+
if (beginningOfTime === null) {
8482
$("#querytime").prop("disabled", true);
8583
$("#querytime").addClass("disabled");
86-
$("#querytime-note").text("ℹ️ No data in the database");
84+
$("#querytime-note").text("No data in the database");
8785
return;
8886
}
8987

9088
const now = luxon.DateTime.now();
9189
const minDateDt = luxon.DateTime.fromSeconds(beginningOfTime);
9290
const maxDateDt = luxon.DateTime.fromSeconds(endOfTime);
9391
const earliestDateStr = minDateDt.toFormat(dateformat);
94-
$("#querytime-note").text(`ℹ️ Earliest date: ${earliestDateStr}`);
92+
$("#querytime-note").text(`Earliest date: ${earliestDateStr}`);
9593

9694
$("#querytime").daterangepicker(
9795
{
9896
timePicker: true,
9997
timePickerIncrement: 5,
10098
timePicker24Hour: true,
101-
locale: { format: dateformat },
99+
locale: {
100+
format: dateformat,
101+
firstDay: 7,
102+
},
102103
// Use Luxon DateTime objects for the picker ranges/start/end. The
103104
// daterangepicker in this build expects Luxon DateTime or ISO strings.
104105
startDate: luxon.DateTime.fromSeconds(from),
@@ -110,12 +111,12 @@ function initDateRangePicker() {
110111
Yesterday: [now.minus({ days: 1 }).startOf("day"), now.minus({ days: 1 }).endOf("day")],
111112
"Last 7 Days": [now.minus({ days: 6 }), maxDateDt],
112113
"Last 30 Days": [now.minus({ days: 29 }), maxDateDt],
113-
"This Month": [now.startOf("month"), now.endOf("month")],
114+
"This Month": [now.startOf("month"), maxDateDt],
114115
"Last Month": [
115116
now.minus({ months: 1 }).startOf("month"),
116117
now.minus({ months: 1 }).endOf("month"),
117118
],
118-
"This Year": [now.startOf("year"), now.endOf("year")],
119+
"This Year": [now.startOf("year"), maxDateDt],
119120
"All Time": [minDateDt, maxDateDt],
120121
},
121122
// Don't allow selecting dates outside the database range

0 commit comments

Comments
 (0)