repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
feat: improve duration formatting
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
ChargingStationUtils.ts
diff --git
a/src/charging-station/ChargingStationUtils.ts
b/src/charging-station/ChargingStationUtils.ts
index 383db84780f53aa22bb415ba7b3603e6b32bea2f..09e0b8e420334aaadf0aeb29ca21013fe6fea102 100644
(file)
--- a/
src/charging-station/ChargingStationUtils.ts
+++ b/
src/charging-station/ChargingStationUtils.ts
@@
-4,7
+4,7
@@
import { basename, dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import chalk from 'chalk';
import { fileURLToPath } from 'node:url';
import chalk from 'chalk';
-import
moment from 'moment
';
+import
{ addSeconds, isAfter } from 'date-fns
';
import type { ChargingStation } from './ChargingStation';
import { BaseError } from '../exception';
import type { ChargingStation } from './ChargingStation';
import { BaseError } from '../exception';
@@
-538,7
+538,7
@@
export const waitChargingStationEvents = async (
event: ChargingStationWorkerMessageEvents,
eventsToWait: number,
): Promise<number> => {
event: ChargingStationWorkerMessageEvents,
eventsToWait: number,
): Promise<number> => {
- return new Promise((resolve) => {
+ return new Promise
<number>
((resolve) => {
let events = 0;
if (eventsToWait === 0) {
resolve(events);
let events = 0;
if (eventsToWait === 0) {
resolve(events);
@@
-661,7
+661,6
@@
const getLimitFromChargingProfiles = (
matchingChargingProfile: ChargingProfile;
} | null => {
const debugLogMsg = `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Matching charging profile found for power limitation: %j`;
matchingChargingProfile: ChargingProfile;
} | null => {
const debugLogMsg = `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Matching charging profile found for power limitation: %j`;
- const currentMoment = moment();
const currentDate = new Date();
for (const chargingProfile of chargingProfiles) {
// Set helpers
const currentDate = new Date();
for (const chargingProfile of chargingProfiles) {
// Set helpers
@@
-676,7
+675,7
@@
const getLimitFromChargingProfiles = (
if (
chargingProfile.chargingProfileKind === ChargingProfileKindType.RECURRING &&
chargingProfile.recurrencyKind === RecurrencyKindType.DAILY &&
if (
chargingProfile.chargingProfileKind === ChargingProfileKindType.RECURRING &&
chargingProfile.recurrencyKind === RecurrencyKindType.DAILY &&
-
currentMoment.isAfter(chargingSchedule.startSchedule
)
+
isAfter(currentDate, chargingSchedule.startSchedule!
)
) {
if (!(chargingSchedule?.startSchedule instanceof Date)) {
logger.warn(
) {
if (!(chargingSchedule?.startSchedule instanceof Date)) {
logger.warn(
@@
-690,17
+689,15
@@
const getLimitFromChargingProfiles = (
currentDate.getDate(),
);
// Check if the start of the schedule is yesterday
currentDate.getDate(),
);
// Check if the start of the schedule is yesterday
- if (
moment(chargingSchedule.startSchedule).isAfter(currentMoment
)) {
+ if (
isAfter(chargingSchedule.startSchedule, currentDate
)) {
chargingSchedule.startSchedule.setDate(currentDate.getDate() - 1);
}
chargingSchedule.startSchedule.setDate(currentDate.getDate() - 1);
}
- } else if (
moment(chargingSchedule.startSchedule).isAfter(currentMoment
)) {
+ } else if (
isAfter(chargingSchedule.startSchedule!, currentDate
)) {
return null;
}
// Check if the charging profile is active
if (
return null;
}
// Check if the charging profile is active
if (
- moment(chargingSchedule.startSchedule)
- .add(chargingSchedule.duration, 's')
- .isAfter(currentMoment)
+ isAfter(addSeconds(chargingSchedule.startSchedule!, chargingSchedule.duration!), currentDate)
) {
let lastButOneSchedule: ChargingSchedulePeriod | undefined;
// Search the right schedule period
) {
let lastButOneSchedule: ChargingSchedulePeriod | undefined;
// Search the right schedule period
@@
-719,9
+716,10
@@
const getLimitFromChargingProfiles = (
}
// Find the right schedule period
if (
}
// Find the right schedule period
if (
- moment(chargingSchedule.startSchedule)
- .add(schedulePeriod.startPeriod, 's')
- .isAfter(currentMoment)
+ isAfter(
+ addSeconds(chargingSchedule.startSchedule!, schedulePeriod.startPeriod),
+ currentDate,
+ )
) {
// Found the schedule: last but one is the correct one
const result = {
) {
// Found the schedule: last but one is the correct one
const result = {