diff --git a/index.js b/index.js index 60bd131cf3ba642e28c9b4756ac5847d0572c4dc..e5648892668da21332dcb66061b5087ede9929e5 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') }