From d372f6da34cd27ce947ea2457dc37646a7edb472 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 1 Aug 2023 02:20:33 +0200 Subject: [PATCH] refactor: cleanup get composite schedule code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) 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( -- 2.34.1