From 710d50eba8aa2b5bedb80092c715f6848d46c1f9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 25 Jul 2023 16:47:50 +0200 Subject: [PATCH] fix: ensure charging schedule periods are sorted by startPeriod MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStationUtils.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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`, + )}`, ); } }; -- 2.34.1