refactor: cleanup date handling
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Jul 2023 09:10:11 +0000 (11:10 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Jul 2023 09:10:11 +0000 (11:10 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationUtils.ts

index b74f8b5ddd27905dba8a4701832725ce697bb264..b44bf75d0d735c16eb1db19ce550548c8341925b 100644 (file)
@@ -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,
index 09e0b8e420334aaadf0aeb29ca21013fe6fea102..e8ba2db5b979979c62830d00ebdcd53ae8e6c6c9 100644 (file)
@@ -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(),