refactor: add sanity checks to recurring profiles translation to current
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Jul 2023 14:31:08 +0000 (16:31 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Jul 2023 14:31:08 +0000 (16:31 +0200)
time windows

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStationUtils.ts

index 1dffb0377949d4dc72dff8d84e2ec1235ff7161e..33d259afe43bf5437a30f173d142089aa55d2dde 100644 (file)
@@ -700,6 +700,16 @@ const getLimitFromChargingProfiles = (
               chargingSchedule.startSchedule,
               differenceInDays(chargingSchedule.startSchedule, endOfDay(currentDate)),
             );
+            if (
+              isBefore(chargingSchedule.startSchedule, startOfDay(currentDate)) ||
+              isAfter(chargingSchedule.startSchedule, endOfDay(currentDate))
+            ) {
+              logger.error(
+                `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Recurring charging profile id ${
+                  chargingProfile.chargingProfileId
+                } startSchedule ${chargingSchedule.startSchedule.toISOString()} is not properly translated to the current day`,
+              );
+            }
           }
           break;
         case RecurrencyKindType.WEEKLY:
@@ -708,6 +718,16 @@ const getLimitFromChargingProfiles = (
               chargingSchedule.startSchedule,
               differenceInWeeks(chargingSchedule.startSchedule, endOfWeek(currentDate)),
             );
+            if (
+              isBefore(chargingSchedule.startSchedule, startOfWeek(currentDate)) ||
+              isAfter(chargingSchedule.startSchedule, endOfWeek(currentDate))
+            ) {
+              logger.error(
+                `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Recurring charging profile id ${
+                  chargingProfile.chargingProfileId
+                } startSchedule ${chargingSchedule.startSchedule.toISOString()} is not properly translated to the current week`,
+              );
+            }
           }
           break;
       }