From: Jérôme Benoit Date: Tue, 25 Jul 2023 14:47:50 +0000 (+0200) Subject: fix: ensure charging schedule periods are sorted by startPeriod X-Git-Tag: v1.2.20~149 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=710d50eba8aa2b5bedb80092c715f6848d46c1f9;p=e-mobility-charging-stations-simulator.git fix: ensure charging schedule periods are sorted by startPeriod Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 0d349d22..fd6079d0 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -474,7 +474,7 @@ export const getChargingStationConnectorChargingProfilesPowerLimit = ( chargingStation.getConnectorStatus(connectorId)!.chargingProfiles!, )?.sort((a, b) => b.stackLevel - a.stackLevel) ?? []; // Get charging profiles on connector 0 and sort by stack level - if (chargingStation.getConnectorStatus(0)?.chargingProfiles) { + if (isNotEmptyArray(chargingStation.getConnectorStatus(0)?.chargingProfiles)) { chargingProfiles.push( ...cloneObject( chargingStation.getConnectorStatus(0)!.chargingProfiles!, @@ -738,6 +738,7 @@ const getLimitFromChargingProfiles = ( isValidDate(chargingSchedule.startSchedule) && isAfter(addSeconds(chargingSchedule.startSchedule!, chargingSchedule.duration!), currentDate) ) { + chargingSchedule.chargingSchedulePeriod.sort((a, b) => a.startPeriod - b.startPeriod); if (isNotEmptyArray(chargingSchedule.chargingSchedulePeriod)) { // Handling of only one schedule period if ( @@ -873,10 +874,10 @@ const checkRecurringChargingProfileDuration = ( chargingProfile.chargingProfileKind } charging profile id ${chargingProfile.chargingProfileId} duration ${ chargingProfile.chargingSchedule.duration - } is greater than the recurrency time interval ${differenceInSeconds( + } is greater than the recurrency time interval duration ${differenceInSeconds( interval.end, interval.start, - )} duration`, + )}`, ); } };