From: Jérôme Benoit Date: Wed, 26 Jul 2023 06:03:33 +0000 (+0200) Subject: refactor: refine charging profiles handling variables namespace X-Git-Tag: v1.2.20~132 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e30379693404ad623548b856606a689ff92c4c84;p=e-mobility-charging-stations-simulator.git refactor: refine charging profiles handling variables namespace Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 628b7eb9..fa834990 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -785,26 +785,29 @@ const getLimitFromChargingProfiles = ( logger.debug(debugLogMsg, result); return result; } - let lastButOneSchedule: ChargingSchedulePeriod | undefined; + let previousChargingSchedulePeriod: ChargingSchedulePeriod | undefined; // Search for the right schedule period - for (const [index, schedulePeriod] of chargingSchedule.chargingSchedulePeriod.entries()) { + for (const [ + index, + chargingSchedulePeriod, + ] of chargingSchedule.chargingSchedulePeriod.entries()) { // Find the right schedule period if ( isAfter( - addSeconds(chargingSchedule.startSchedule!, schedulePeriod.startPeriod), + addSeconds(chargingSchedule.startSchedule!, chargingSchedulePeriod.startPeriod), currentDate, ) ) { - // Found the schedule period: last but one is the correct one + // Found the schedule period: previous is the correct one const result: ChargingProfilesLimit = { - limit: lastButOneSchedule!.limit, + limit: previousChargingSchedulePeriod!.limit, matchingChargingProfile: chargingProfile, }; logger.debug(debugLogMsg, result); return result; } - // Keep it - lastButOneSchedule = schedulePeriod; + // Keep a reference to previous one + previousChargingSchedulePeriod = chargingSchedulePeriod; // Handle the last schedule period within the charging profile duration if ( index === chargingSchedule.chargingSchedulePeriod.length - 1 || @@ -819,7 +822,7 @@ const getLimitFromChargingProfiles = ( )) ) { const result: ChargingProfilesLimit = { - limit: lastButOneSchedule.limit, + limit: previousChargingSchedulePeriod.limit, matchingChargingProfile: chargingProfile, }; logger.debug(debugLogMsg, result);