From: Jérôme Benoit Date: Mon, 24 Jul 2023 14:31:08 +0000 (+0200) Subject: refactor: add sanity checks to recurring profiles translation to current X-Git-Tag: v1.2.20~159^2~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7cf61ec26bcf3603879846ddf12165b75fb6468d;hp=497588ef4a25784044c3ffb0e92e0c7fa6874e5f;p=e-mobility-charging-stations-simulator.git refactor: add sanity checks to recurring profiles translation to current time windows Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 1dffb037..33d259af 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -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; }