From 497588ef4a25784044c3ffb0e92e0c7fa6874e5f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 24 Jul 2023 15:17:52 +0200 Subject: [PATCH] fix: properly translate schedule start date to current recurring time windows MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStationUtils.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 8ff88a33..1dffb037 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -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; } -- 2.34.1