fix: handle recurring charging profiles only in the past
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Jul 2023 12:22:06 +0000 (14:22 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Jul 2023 12:22:06 +0000 (14:22 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStationUtils.ts

index 090ca65d1edcec3648c4fe9f6b3502d3e9097ae6..8ff88a333eb62157456aeeb4916a778698f14445 100644 (file)
@@ -8,14 +8,10 @@ import {
   addDays,
   addSeconds,
   addWeeks,
-  endOfWeek,
   isAfter,
   isBefore,
-  isTomorrow,
   isYesterday,
   startOfWeek,
-  subDays,
-  subWeeks,
 } from 'date-fns';
 
 import type { ChargingStation } from './ChargingStation';
@@ -691,21 +687,17 @@ const getLimitFromChargingProfiles = (
       );
       chargingSchedule.startSchedule = convertToDate(chargingSchedule.startSchedule)!;
     }
-    // Adjust recurring schedule
+    // Adjust recurring start schedule
     if (chargingProfile.chargingProfileKind === ChargingProfileKindType.RECURRING) {
       switch (chargingProfile.recurrencyKind) {
         case RecurrencyKindType.DAILY:
           if (isYesterday(chargingSchedule.startSchedule)) {
             addDays(chargingSchedule.startSchedule, 1);
-          } else if (isTomorrow(chargingSchedule.startSchedule)) {
-            subDays(chargingSchedule.startSchedule, 1);
           }
           break;
         case RecurrencyKindType.WEEKLY:
           if (isBefore(chargingSchedule.startSchedule, startOfWeek(currentDate))) {
             addWeeks(chargingSchedule.startSchedule, 1);
-          } else if (isAfter(chargingSchedule.startSchedule, endOfWeek(currentDate))) {
-            subWeeks(chargingSchedule.startSchedule, 1);
           }
           break;
       }