From 7cf61ec26bcf3603879846ddf12165b75fb6468d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 24 Jul 2023 16:31:08 +0200 Subject: [PATCH] refactor: add sanity checks to recurring profiles translation to current 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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; } -- 2.34.1