Skip to content

Commit d9f12de

Browse files
committed
Discard date from URL if it's not within the right range
1 parent cd448c3 commit d9f12de

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/modes/exportdata/ExportData.svelte

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,24 @@
5454
// Populate date based on URL params or, if absent, the current date
5555
if (sensor && !sensor.active) {
5656
// If the sensor is inactive, set the start and end dates to its historical range rather than current date
57-
startDate = urlParams.has('start_day') ? new Date(urlParams.get('start_day')) : sensor.meta.minTime;
58-
endDate = urlParams.has('end_day') ? new Date(urlParams.get('end_day')) : sensor.meta.maxTime;
57+
if (
58+
urlParams.has('start_day') &&
59+
new Date(urlParams.get('start_day')) >= sensor.meta.minTime &&
60+
new Date(urlParams.get('start_day')) <= sensor.meta.maxTime
61+
) {
62+
startDate = new Date(urlParams.get('start_day'));
63+
} else {
64+
startDate = sensor.meta.minTime;
65+
}
66+
if (
67+
urlParams.has('end_day') &&
68+
new Date(urlParams.get('end_day')) <= sensor.meta.minTime &&
69+
new Date(urlParams.get('end_day')) <= sensor.meta.maxTime
70+
) {
71+
endDate = new Date(urlParams.get('end_day'));
72+
} else {
73+
endDate = sensor.meta.maxTime;
74+
}
5975
} else {
6076
startDate = urlParams.has('start_day') ? new Date(urlParams.get('start_day')) : param.sparkLineTimeFrame.min;
6177
endDate = urlParams.has('end_day') ? new Date(urlParams.get('end_day')) : param.sparkLineTimeFrame.max;

0 commit comments

Comments
 (0)