From 655dbd0942992a1c8ca81fdfced1168bc6095765 Mon Sep 17 00:00:00 2001 From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com> Date: Fri, 7 Oct 2022 14:18:19 +0200 Subject: [PATCH] publish: fix: error to warn log generated from commit 0741d040cf873b2c8785ae4192ee472295b00b98 --- index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 60bd131..e564889 100644 --- a/index.js +++ b/index.js @@ -319,7 +319,7 @@ async function getData(url, apiAuthKey, userLogin, pointId) { apikey: apiAuthKey, } - setStartDate() + limitStartDate() const { response } = await soapRequest({ url: url, @@ -363,7 +363,7 @@ async function getMaxPowerData(url, apiAuthKey, userLogin, pointId) { apikey: apiAuthKey, } - setStartDate() + limitStartDate() const { response } = await soapRequest({ url: url, @@ -396,8 +396,9 @@ async function getMaxPowerData(url, apiAuthKey, userLogin, pointId) { * get only 36 month. * On manual execution, set the start date to one year ago. */ -function setStartDate() { - if (moment(endDate).diff(startDailyDate, 'months', true) > 36) { +function limitStartDate() { + const livingDuration = moment(endDate).diff(startDailyDate, 'months', true) + if (livingDuration > 36) { log( 'info', 'Start date exceed 36 month, setting start date to current date minus 36 month' @@ -405,7 +406,7 @@ function setStartDate() { startDailyDate = moment(endDate).subtract(36, 'month') startDailyDateString = startDailyDate.format('YYYY-MM-DD') } - if (manualExecution) { + if (manualExecution && livingDuration > 12) { startDailyDate = moment(endDate).subtract(12, 'month') startDailyDateString = startDailyDate.format('YYYY-MM-DD') } -- GitLab