From b85cef4cba7e4d2294940aef29a9f74edf800dac Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 24 Jul 2023 11:10:11 +0200 Subject: [PATCH] refactor: cleanup date handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 6 +++--- src/charging-station/ChargingStationUtils.ts | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index b74f8b5d..b44bf75d 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1031,11 +1031,11 @@ export class ChargingStation { ); if (interval > 0) { this.reservationExpirationSetInterval = setInterval((): void => { - const now = new Date(); + const dateNow = new Date(); if (this.hasEvses) { for (const evseStatus of this.evses.values()) { for (const connectorStatus of evseStatus.connectors.values()) { - if (connectorStatus.reservation && connectorStatus.reservation.expiryDate < now) { + if (connectorStatus.reservation && connectorStatus.reservation.expiryDate < dateNow) { this.removeReservation( connectorStatus.reservation, ReservationTerminationReason.EXPIRED, @@ -1045,7 +1045,7 @@ export class ChargingStation { } } else { for (const connectorStatus of this.connectors.values()) { - if (connectorStatus.reservation && connectorStatus.reservation.expiryDate < now) { + if (connectorStatus.reservation && connectorStatus.reservation.expiryDate < dateNow) { this.removeReservation( connectorStatus.reservation, ReservationTerminationReason.EXPIRED, diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 09e0b8e4..e8ba2db5 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -36,6 +36,7 @@ import { Constants, DCElectricUtils, cloneObject, + convertToDate, convertToInt, isEmptyObject, isEmptyString, @@ -681,7 +682,7 @@ const getLimitFromChargingProfiles = ( logger.warn( `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: startSchedule is not a Date object in charging profile id ${chargingProfile.chargingProfileId}. Trying to convert it to a Date object`, ); - chargingSchedule.startSchedule = new Date(chargingSchedule.startSchedule!); + chargingSchedule.startSchedule = convertToDate(chargingSchedule.startSchedule)!; } chargingSchedule.startSchedule.setFullYear( currentDate.getFullYear(), -- 2.34.1