From: Jérôme Benoit Date: Tue, 1 Aug 2023 00:20:33 +0000 (+0200) Subject: refactor: cleanup get composite schedule code X-Git-Tag: v1.2.20~49 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d372f6da34cd27ce947ea2457dc37646a7edb472;p=e-mobility-charging-stations-simulator.git refactor: cleanup get composite schedule code Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 01d1211d..81f7540f 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -677,7 +677,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { return OCPP16Constants.OCPP_RESPONSE_REJECTED; } const startDate = new Date(); - const endDate = addSeconds(startDate, duration); + const interval: Interval = { + start: startDate, + end: addSeconds(startDate, duration), + }; let compositeSchedule: OCPP16ChargingSchedule | undefined; for (const chargingProfile of chargingStation.getConnectorStatus(connectorId)! .chargingProfiles!) { @@ -693,24 +696,18 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { continue; } if ( - isWithinInterval(chargingProfile.chargingSchedule.startSchedule!, { - start: startDate, - end: endDate, - }) && + isWithinInterval(chargingProfile.chargingSchedule.startSchedule!, interval) && isWithinInterval( addSeconds( chargingProfile.chargingSchedule.startSchedule!, chargingProfile.chargingSchedule.duration!, ), - { - start: startDate, - end: endDate, - }, + interval, ) ) { compositeSchedule = { startSchedule: max([ - compositeSchedule?.startSchedule ?? startDate, + compositeSchedule?.startSchedule ?? interval.start, chargingProfile.chargingSchedule.startSchedule!, ]), duration: Math.max(