fix: ensure charging schedule periods are sorted by startPeriod
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 25 Jul 2023 14:47:50 +0000 (16:47 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 25 Jul 2023 14:47:50 +0000 (16:47 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStationUtils.ts

index 0d349d22518def767afb3d535ba0fb5abbd96525..fd6079d00f7fda00fbfe94382f3d3f8dc0979ccb 100644 (file)
@@ -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<ChargingProfile[]>(
         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`,
+      )}`,
     );
   }
 };