fix: fix gap in schedule periods in composeChargingSchedules()
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 4 Aug 2023 10:22:37 +0000 (12:22 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 4 Aug 2023 10:22:37 +0000 (12:22 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts

index af2f6d03a1ce9c944ebc1e87116735f30c47019e..537449dfbcc55a3149f5c25792ac3982b1640c3c 100644 (file)
@@ -1046,7 +1046,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
           };
         }),
         ...compositeChargingScheduleLower!.chargingSchedulePeriod
-          .filter((schedulePeriod) => {
+          .filter((schedulePeriod, index) => {
             if (
               higherFirst &&
               isWithinInterval(
@@ -1062,6 +1062,33 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
             ) {
               return false;
             }
+            if (
+              higherFirst &&
+              index < compositeChargingScheduleLower!.chargingSchedulePeriod.length - 1 &&
+              !isWithinInterval(
+                addSeconds(
+                  compositeChargingScheduleLowerInterval.start,
+                  schedulePeriod.startPeriod,
+                ),
+                {
+                  start: compositeChargingScheduleLowerInterval.start,
+                  end: compositeChargingScheduleHigherInterval.end,
+                },
+              ) &&
+              isWithinInterval(
+                addSeconds(
+                  compositeChargingScheduleLowerInterval.start,
+                  compositeChargingScheduleLower!.chargingSchedulePeriod[index + 1].startPeriod,
+                ),
+                {
+                  start: compositeChargingScheduleLowerInterval.start,
+                  end: compositeChargingScheduleHigherInterval.end,
+                },
+              )
+            ) {
+              schedulePeriod.startPeriod = 0;
+              return false;
+            }
             if (
               !higherFirst &&
               isWithinInterval(