From: Jérôme Benoit Date: Mon, 8 Jan 2024 12:09:49 +0000 (+0100) Subject: fix: compute the ATG stop date only once X-Git-Tag: v1.2.32~49 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0193fdd350fa2b861631493bb2d3f857a69dda5f;p=e-mobility-charging-stations-simulator.git fix: compute the ATG stop date only once Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 3b27f247..b2f095b1 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -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