From: Jérôme Benoit Date: Mon, 24 Jul 2023 13:17:52 +0000 (+0200) Subject: fix: properly translate schedule start date to current recurring time X-Git-Tag: v1.2.20~159^2~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=497588ef4a25784044c3ffb0e92e0c7fa6874e5f;p=e-mobility-charging-stations-simulator.git fix: properly translate schedule start date to current recurring time windows Signed-off-by: Jérôme Benoit --- 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; }