fix: properly translate schedule start date to current recurring time
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Jul 2023 13:17:52 +0000 (15:17 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Jul 2023 13:17:52 +0000 (15:17 +0200)
windows

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

index 8ff88a333eb62157456aeeb4916a778698f14445..1dffb0377949d4dc72dff8d84e2ec1235ff7161e 100644 (file)
@@ -8,9 +8,13 @@ import {
   addDays,
   addSeconds,
   addWeeks,
+  differenceInDays,
+  differenceInWeeks,
+  endOfDay,
+  endOfWeek,
   isAfter,
   isBefore,
-  isYesterday,
+  startOfDay,
   startOfWeek,
 } from 'date-fns';
 
@@ -691,13 +695,19 @@ const getLimitFromChargingProfiles = (
     if (chargingProfile.chargingProfileKind === ChargingProfileKindType.RECURRING) {
       switch (chargingProfile.recurrencyKind) {
         case RecurrencyKindType.DAILY:
-          if (isYesterday(chargingSchedule.startSchedule)) {
-            addDays(chargingSchedule.startSchedule, 1);
+          if (isBefore(chargingSchedule.startSchedule, startOfDay(currentDate))) {
+            addDays(
+              chargingSchedule.startSchedule,
+              differenceInDays(chargingSchedule.startSchedule, endOfDay(currentDate)),
+            );
           }
           break;
         case RecurrencyKindType.WEEKLY:
           if (isBefore(chargingSchedule.startSchedule, startOfWeek(currentDate))) {
-            addWeeks(chargingSchedule.startSchedule, 1);
+            addWeeks(
+              chargingSchedule.startSchedule,
+              differenceInWeeks(chargingSchedule.startSchedule, endOfWeek(currentDate)),
+            );
           }
           break;
       }