From 0939e405b4019772d4984484761a003da23ff410 Mon Sep 17 00:00:00 2001 From: oemel09 Date: Thu, 2 Jul 2020 20:54:20 +0200 Subject: [PATCH] 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;