From fc10c736c9ceeda18df1cb491578d5eb49b97e76 Mon Sep 17 00:00:00 2001 From: Jon Ziebell Date: Sat, 26 Oct 2024 05:53:13 -0400 Subject: [PATCH] Fixed #418 - Sometimes you can set your chart ranges to > 30 days --- js/component/modal/air_quality_detail_custom.js | 11 +++++++++++ js/component/modal/runtime_sensor_detail_custom.js | 11 +++++++++++ .../modal/runtime_thermostat_detail_custom.js | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/js/component/modal/air_quality_detail_custom.js b/js/component/modal/air_quality_detail_custom.js index 3d496f5..61e190d 100644 --- a/js/component/modal/air_quality_detail_custom.js +++ b/js/component/modal/air_quality_detail_custom.js @@ -322,6 +322,17 @@ beestat.component.modal.air_quality_detail_custom.prototype.get_buttons_ = funct .set_text_color('#fff') .set_text('Save') .addEventListener('click', function() { + // Bit of a rig to fix the odd situation where somehow people are + // getting these values set to more than 30 days. + var air_quality_detail_range_static_begin_m = moment(self.state_.air_quality_detail_range_static_begin); + var air_quality_detail_range_static_end_m = moment(self.state_.air_quality_detail_range_static_end); + + var diff = Math.abs(air_quality_detail_range_static_begin_m.diff(air_quality_detail_range_static_end_m, 'day')) + 1; + if (diff > 30) { + air_quality_detail_range_static_end_m = air_quality_detail_range_static_begin_m.clone().add(29, 'days'); + self.state_.air_quality_detail_range_static_end = air_quality_detail_range_static_end_m.format('M/D/YYYY'); + } + this .set_background_color(beestat.style.color.gray.base) .set_background_hover_color() diff --git a/js/component/modal/runtime_sensor_detail_custom.js b/js/component/modal/runtime_sensor_detail_custom.js index 3b1760a..e5fa65c 100644 --- a/js/component/modal/runtime_sensor_detail_custom.js +++ b/js/component/modal/runtime_sensor_detail_custom.js @@ -322,6 +322,17 @@ beestat.component.modal.runtime_sensor_detail_custom.prototype.get_buttons_ = fu .set_text_color('#fff') .set_text('Save') .addEventListener('click', function() { + // Bit of a rig to fix the odd situation where somehow people are + // getting these values set to more than 30 days. + var runtime_sensor_detail_range_static_begin_m = moment(self.state_.runtime_sensor_detail_range_static_begin); + var runtime_sensor_detail_range_static_end_m = moment(self.state_.runtime_sensor_detail_range_static_end); + + var diff = Math.abs(runtime_sensor_detail_range_static_begin_m.diff(runtime_sensor_detail_range_static_end_m, 'day')) + 1; + if (diff > 30) { + runtime_sensor_detail_range_static_end_m = runtime_sensor_detail_range_static_begin_m.clone().add(29, 'days'); + self.state_.runtime_sensor_detail_range_static_end = runtime_sensor_detail_range_static_end_m.format('M/D/YYYY'); + } + this .set_background_color(beestat.style.color.gray.base) .set_background_hover_color() diff --git a/js/component/modal/runtime_thermostat_detail_custom.js b/js/component/modal/runtime_thermostat_detail_custom.js index e214b3a..f330956 100644 --- a/js/component/modal/runtime_thermostat_detail_custom.js +++ b/js/component/modal/runtime_thermostat_detail_custom.js @@ -322,6 +322,17 @@ beestat.component.modal.runtime_thermostat_detail_custom.prototype.get_buttons_ .set_text_color('#fff') .set_text('Save') .addEventListener('click', function() { + // Bit of a rig to fix the odd situation where somehow people are + // getting these values set to more than 30 days. + var runtime_thermostat_detail_range_static_begin_m = moment(self.state_.runtime_thermostat_detail_range_static_begin); + var runtime_thermostat_detail_range_static_end_m = moment(self.state_.runtime_thermostat_detail_range_static_end); + + var diff = Math.abs(runtime_thermostat_detail_range_static_begin_m.diff(runtime_thermostat_detail_range_static_end_m, 'day')) + 1; + if (diff > 30) { + runtime_thermostat_detail_range_static_end_m = runtime_thermostat_detail_range_static_begin_m.clone().add(29, 'days'); + self.state_.runtime_thermostat_detail_range_static_end = runtime_thermostat_detail_range_static_end_m.format('M/D/YYYY'); + } + this .set_background_color(beestat.style.color.gray.base) .set_background_hover_color()