perf: only sort charging schdule periods if needed
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 25 Jul 2023 15:24:34 +0000 (17:24 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 25 Jul 2023 15:24:34 +0000 (17:24 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStationUtils.ts

index fd6079d00f7fda00fbfe94382f3d3f8dc0979ccb..5feec88329d5eca9275d252d3ae2c7c854d2fe47 100644 (file)
@@ -738,7 +738,6 @@ 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 (
@@ -752,6 +751,7 @@ const getLimitFromChargingProfiles = (
           logger.debug(debugLogMsg, result);
           return result;
         }
+        chargingSchedule.chargingSchedulePeriod.sort((a, b) => a.startPeriod - b.startPeriod);
         let lastButOneSchedule: ChargingSchedulePeriod | undefined;
         // Search for the right schedule period
         for (const schedulePeriod of chargingSchedule.chargingSchedulePeriod) {