diff --git a/index.js b/index.js index e5648892668da21332dcb66061b5087ede9929e5..f3ed52ea2260ec3ae3cb7ff794e845651c4396a8 100644 --- a/index.js +++ b/index.js @@ -393,12 +393,16 @@ async function getMaxPowerData(url, apiAuthKey, userLogin, pointId) { /** * If start date exceed the maximum amount of data we can get with one query - * get only 36 month. + * get only 36 month. Or 12 month if manual execution * On manual execution, set the start date to one year ago. */ function limitStartDate() { const livingDuration = moment(endDate).diff(startDailyDate, 'months', true) - if (livingDuration > 36) { + // We need to prevent case that there is less than 12 month data + if (manualExecution && livingDuration > 12) { + startDailyDate = moment(endDate).subtract(12, 'month') + startDailyDateString = startDailyDate.format('YYYY-MM-DD') + } else if (livingDuration > 36) { log( 'info', 'Start date exceed 36 month, setting start date to current date minus 36 month' @@ -406,10 +410,6 @@ function limitStartDate() { startDailyDate = moment(endDate).subtract(36, 'month') startDailyDateString = startDailyDate.format('YYYY-MM-DD') } - if (manualExecution && livingDuration > 12) { - startDailyDate = moment(endDate).subtract(12, 'month') - startDailyDateString = startDailyDate.format('YYYY-MM-DD') - } } /**