From: Jérôme Benoit Date: Tue, 25 Jul 2023 14:35:03 +0000 (+0200) Subject: refactor: add sanity check on recurring charging profile duration X-Git-Tag: v1.2.20~150 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d476bc1be87bb63cfd8c494ce1ed41204992806f;hp=522e4b058bc5ed1015cdf902e36a107490824f73;p=e-mobility-charging-stations-simulator.git refactor: add sanity check on recurring charging profile duration Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 9da406c2..0d349d22 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -9,6 +9,7 @@ import { addSeconds, addWeeks, differenceInDays, + differenceInSeconds, differenceInWeeks, isAfter, isBefore, @@ -810,6 +811,7 @@ const prepareRecurringChargingProfile = ( start: chargingSchedule.startSchedule!, end: addDays(chargingSchedule.startSchedule!, 1), }; + checkRecurringChargingProfileDuration(chargingProfile, recurringInterval, logPrefix); if ( !isWithinInterval(currentDate, recurringInterval) && isBefore(chargingSchedule.startSchedule!, currentDate) @@ -829,6 +831,7 @@ const prepareRecurringChargingProfile = ( start: chargingSchedule.startSchedule!, end: addWeeks(chargingSchedule.startSchedule!, 1), }; + checkRecurringChargingProfileDuration(chargingProfile, recurringInterval, logPrefix); if ( !isWithinInterval(currentDate, recurringInterval) && isBefore(chargingSchedule.startSchedule!, currentDate) @@ -857,6 +860,27 @@ const prepareRecurringChargingProfile = ( } }; +const checkRecurringChargingProfileDuration = ( + chargingProfile: ChargingProfile, + interval: Interval, + logPrefix: string, +) => { + if ( + chargingProfile.chargingSchedule.duration! > differenceInSeconds(interval.end, interval.start) + ) { + logger.warn( + `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Recurring ${ + chargingProfile.chargingProfileKind + } charging profile id ${chargingProfile.chargingProfileId} duration ${ + chargingProfile.chargingSchedule.duration + } is greater than the recurrency time interval ${differenceInSeconds( + interval.end, + interval.start, + )} duration`, + ); + } +}; + const getRandomSerialNumberSuffix = (params?: { randomBytesLength?: number; upperCase?: boolean;