fix: compute the ATG stop date only once
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 8 Jan 2024 12:09:49 +0000 (13:09 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 8 Jan 2024 12:09:49 +0000 (13:09 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts

index 3b27f247d3419f38756582f42ba9b83248049f9d..b2f095b1fd222faae7ba91c714f069f3202fa1ec 100644 (file)
@@ -260,30 +260,20 @@ export class AutomaticTransactionGenerator {
   }
 
   private setStartConnectorStatus (connectorId: number): void {
-    const previousRunDuration =
-      isValidTime(this.connectorsStatus.get(connectorId)?.startDate) &&
-      isValidTime(this.connectorsStatus.get(connectorId)?.lastRunDate) &&
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      this.connectorsStatus.get(connectorId)!.lastRunDate! >
-        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        this.connectorsStatus.get(connectorId)!.startDate!
-        ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-        this.connectorsStatus.get(connectorId)!.lastRunDate!.getTime() -
-          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-          this.connectorsStatus.get(connectorId)!.startDate!.getTime()
-        : 0
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     this.connectorsStatus.get(connectorId)!.startDate = new Date()
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    this.connectorsStatus.get(connectorId)!.stopDate = new Date(
+    if (!isValidTime(this.connectorsStatus.get(connectorId)!.stopDate)) {
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      this.connectorsStatus.get(connectorId)!.startDate!.getTime() +
-        hoursToMilliseconds(
-          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-          this.chargingStation.getAutomaticTransactionGeneratorConfiguration()!.stopAfterHours
-        ) -
-        previousRunDuration
-    )
+      this.connectorsStatus.get(connectorId)!.stopDate = new Date(
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        this.connectorsStatus.get(connectorId)!.startDate!.getTime() +
+          hoursToMilliseconds(
+            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+            this.chargingStation.getAutomaticTransactionGeneratorConfiguration()!.stopAfterHours
+          )
+      )
+    }
     delete this.connectorsStatus.get(connectorId)?.stoppedDate
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     this.connectorsStatus.get(connectorId)!.skippedConsecutiveTransactions = 0