From 0e14e1d42f7fbe28955be2cb77e6ad3f7277e9a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 4 Aug 2023 15:05:08 +0200 Subject: [PATCH] fix: ensure composite schedule period start at 0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCPP16ServiceUtils.ts | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index 537449df..914886bd 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -1086,7 +1086,6 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { }, ) ) { - schedulePeriod.startPeriod = 0; return false; } if ( @@ -1106,7 +1105,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { } return true; }) - .map((schedulePeriod) => { + .map((schedulePeriod, index) => { + if (index === 0 && schedulePeriod.startPeriod !== 0) { + schedulePeriod.startPeriod = 0; + } return { ...schedulePeriod, startPeriod: higherFirst @@ -1178,8 +1180,8 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { ...chargingSchedule, startSchedule: targetInterval.start as Date, duration: differenceInSeconds(chargingScheduleInterval.end, targetInterval.start as Date), - chargingSchedulePeriod: chargingSchedule.chargingSchedulePeriod.filter( - (schedulePeriod, index) => { + chargingSchedulePeriod: chargingSchedule.chargingSchedulePeriod + .filter((schedulePeriod, index) => { if ( isWithinInterval( addSeconds(chargingScheduleInterval.start, schedulePeriod.startPeriod)!, @@ -1202,12 +1204,16 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { targetInterval, ) ) { - schedulePeriod.startPeriod = 0; return true; } return false; - }, - ), + }) + .map((schedulePeriod, index) => { + if (index === 0 && schedulePeriod.startPeriod !== 0) { + schedulePeriod.startPeriod = 0; + } + return schedulePeriod; + }), }; } if (isAfter(chargingScheduleInterval.end, targetInterval.end)) { -- 2.34.1