From 0939e405b4019772d4984484761a003da23ff410 Mon Sep 17 00:00:00 2001 From: oemel09 Date: Thu, 2 Jul 2020 20:54:20 +0200 Subject: [PATCH 1/4] Adjusts maxNumberOfDays depending on the endpoint --- modules/default/weatherforecast/weatherforecast.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/default/weatherforecast/weatherforecast.js b/modules/default/weatherforecast/weatherforecast.js index 83389911..ecda5a53 100644 --- a/modules/default/weatherforecast/weatherforecast.js +++ b/modules/default/weatherforecast/weatherforecast.js @@ -294,7 +294,15 @@ Module.register("weatherforecast", { return; } - params += "&cnt=" + (this.config.maxNumberOfDays < 1 || this.config.maxNumberOfDays > 17 ? 7 : this.config.maxNumberOfDays); + let numberOfDays; + if (this.config.forecastEndpoint === "forecast") { + numberOfDays = (this.config.maxNumberOfDays < 1 || this.config.maxNumberOfDays > 5 ? 5 : this.config.maxNumberOfDays); + // don't get forecasts for the 6th day, as it would not represent the whole day + numberOfDays = numberOfDays * 8 - Math.ceil(new Date().getHours() / 3) % 8; + } else { + numberOfDays = (this.config.maxNumberOfDays < 1 || this.config.maxNumberOfDays > 17) ? 7 : this.config.maxNumberOfDays; + } + params += "&cnt=" + numberOfDays; params += "&units=" + this.config.units; params += "&lang=" + this.config.lang; From 4ed323559058932dd58c012d39757e7fd7cea140 Mon Sep 17 00:00:00 2001 From: oemel09 Date: Thu, 2 Jul 2020 20:56:48 +0200 Subject: [PATCH 2/4] Adds fix to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 069c61f8..68ebc0ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ _This release is scheduled to be released on 2020-10-01._ ### Deleted ### Fixed +- Fix the use of "maxNumberOfDays" in the module "weatherforecast depending on the endpoint (forecast/daily or forecast)". [#2018](https://github.com/MichMich/MagicMirror/issues/2018) ## [2.12.0] - 2020-07-01 From 246dc663c4a82f9f0284de21577f3c24cd7ace9c Mon Sep 17 00:00:00 2001 From: oemel09 Date: Thu, 2 Jul 2020 22:22:04 +0200 Subject: [PATCH 3/4] Applies suggestions from prettier, floor instead of ceil --- modules/default/weatherforecast/weatherforecast.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/default/weatherforecast/weatherforecast.js b/modules/default/weatherforecast/weatherforecast.js index ecda5a53..d872ee01 100644 --- a/modules/default/weatherforecast/weatherforecast.js +++ b/modules/default/weatherforecast/weatherforecast.js @@ -296,11 +296,11 @@ Module.register("weatherforecast", { let numberOfDays; if (this.config.forecastEndpoint === "forecast") { - numberOfDays = (this.config.maxNumberOfDays < 1 || this.config.maxNumberOfDays > 5 ? 5 : this.config.maxNumberOfDays); + numberOfDays = this.config.maxNumberOfDays < 1 || this.config.maxNumberOfDays > 5 ? 5 : this.config.maxNumberOfDays; // don't get forecasts for the 6th day, as it would not represent the whole day - numberOfDays = numberOfDays * 8 - Math.ceil(new Date().getHours() / 3) % 8; + numberOfDays = numberOfDays * 8 - (Math.floor(new Date().getHours() / 3) % 8); } else { - numberOfDays = (this.config.maxNumberOfDays < 1 || this.config.maxNumberOfDays > 17) ? 7 : this.config.maxNumberOfDays; + numberOfDays = this.config.maxNumberOfDays < 1 || this.config.maxNumberOfDays > 17 ? 7 : this.config.maxNumberOfDays; } params += "&cnt=" + numberOfDays; From 92cc41dec661f7f8cca593e4da25895c40f7bb4c Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Fri, 3 Jul 2020 21:53:18 +0200 Subject: [PATCH 4/4] Fix linting issue. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68ebc0ea..66c307c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ _This release is scheduled to be released on 2020-10-01._ ### Deleted ### Fixed + - Fix the use of "maxNumberOfDays" in the module "weatherforecast depending on the endpoint (forecast/daily or forecast)". [#2018](https://github.com/MichMich/MagicMirror/issues/2018) ## [2.12.0] - 2020-07-01