From: Jérôme Benoit Date: Mon, 24 Jul 2023 09:10:11 +0000 (+0200) Subject: refactor: cleanup date handling X-Git-Tag: v1.2.20~160 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b85cef4cba7e4d2294940aef29a9f74edf800dac;p=e-mobility-charging-stations-simulator.git refactor: cleanup date handling Signed-off-by: Jérôme Benoit --- 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(),