X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStationUtils.ts;fp=src%2Fcharging-station%2FChargingStationUtils.ts;h=709d1dd11747f4106f5bac1ec9bc0531c6e0fa19;hb=975e18ec2b21e99f182dc0df1e7fb0fe1454665c;hp=b26f9970bfa3be2e2b8d72ef226e3c799e761c38;hpb=55f2ab602b8b52836cbf267e960b7c11633a2e97;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index b26f9970..709d1dd1 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -733,21 +733,22 @@ const getLimitFromChargingProfiles = ( // Check if the charging profile is active if ( isValidDate(chargingSchedule.startSchedule) && - isAfter(addSeconds(chargingSchedule.startSchedule!, chargingSchedule.duration!), currentDate) + isWithinInterval(currentDate, { + start: chargingSchedule.startSchedule!, + end: addSeconds(chargingSchedule.startSchedule!, chargingSchedule.duration!), + }) ) { if (isNotEmptyArray(chargingSchedule.chargingSchedulePeriod)) { chargingSchedule.chargingSchedulePeriod.sort((a, b) => a.startPeriod - b.startPeriod); + // Check if the first schedule period start period is equal to 0 if (chargingSchedule.chargingSchedulePeriod[0].startPeriod !== 0) { logger.error( `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Charging profile id ${chargingProfile.chargingProfileId} first schedule period start period ${chargingSchedule.chargingSchedulePeriod[0].startPeriod} is not equal to 0`, ); - // continue; + continue; } - // Handling of only one schedule period with startPeriod = 0 - if ( - chargingSchedule.chargingSchedulePeriod.length === 1 && - chargingSchedule.chargingSchedulePeriod[0].startPeriod === 0 - ) { + // Handling of only one schedule period + if (chargingSchedule.chargingSchedulePeriod.length === 1) { const result: ChargingProfilesLimit = { limit: chargingSchedule.chargingSchedulePeriod[0].limit, matchingChargingProfile: chargingProfile, @@ -757,7 +758,7 @@ const getLimitFromChargingProfiles = ( } let lastButOneSchedule: ChargingSchedulePeriod | undefined; // Search for the right schedule period - for (const schedulePeriod of chargingSchedule.chargingSchedulePeriod) { + for (const [index, schedulePeriod] of chargingSchedule.chargingSchedulePeriod.entries()) { // Find the right schedule period if ( isAfter( @@ -775,12 +776,18 @@ const getLimitFromChargingProfiles = ( } // Keep it lastButOneSchedule = schedulePeriod; - // Handle the last schedule period + // Handle the last schedule period within the charging profile duration if ( - schedulePeriod.startPeriod === - chargingSchedule.chargingSchedulePeriod[ - chargingSchedule.chargingSchedulePeriod.length - 1 - ].startPeriod + index === chargingSchedule.chargingSchedulePeriod.length - 1 || + (index < chargingSchedule.chargingSchedulePeriod.length - 1 && + chargingSchedule.duration! > + differenceInSeconds( + chargingSchedule.startSchedule!, + addSeconds( + chargingSchedule.startSchedule!, + chargingSchedule.chargingSchedulePeriod[index + 1].startPeriod, + ), + )) ) { const result: ChargingProfilesLimit = { limit: lastButOneSchedule.limit,