"ajv-formats": "^2.1.1",
"basic-ftp": "^5.0.3",
"chalk": "^5.3.0",
+ "date-fns": "^2.30.0",
"http-status-codes": "^2.2.0",
"just-clone": "^6.2.0",
"just-merge": "^3.2.0",
"logform": "^2.5.1",
"mnemonist": "^0.39.5",
- "moment": "^2.29.4",
"mongodb": "^5.7.0",
"poolifier": "^2.6.20",
"source-map-support": "^0.5.21",
chalk:
specifier: ^5.3.0
version: 5.3.0
+ date-fns:
+ specifier: ^2.30.0
+ version: 2.30.0
http-status-codes:
specifier: ^2.2.0
version: 2.2.0
mnemonist:
specifier: ^0.39.5
version: 0.39.5
- moment:
- specifier: ^2.29.4
- version: 2.29.4
mongodb:
specifier: ^5.7.0
version: 5.7.0
js-tokens: 4.0.0
dev: true
+ /@babel/runtime@7.22.6:
+ resolution: {integrity: sha512-wDb5pWm4WDdF6LFUde3Jl8WzPA+3ZbxYqkC6xAXuD3irdEHN1k0NfTRrJD8ZD378SJ61miMLCqIOXYhd8x+AJQ==}
+ engines: {node: '>=6.9.0'}
+ dependencies:
+ regenerator-runtime: 0.13.11
+ dev: false
+
/@bcoe/v8-coverage@0.2.3:
resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==}
dev: true
engines: {node: '>= 14'}
dev: true
+ /date-fns@2.30.0:
+ resolution: {integrity: sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==}
+ engines: {node: '>=0.11'}
+ dependencies:
+ '@babel/runtime': 7.22.6
+ dev: false
+
/dateformat@4.6.3:
resolution: {integrity: sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==}
dev: true
/reflect-metadata@0.1.13:
resolution: {integrity: sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==}
+ /regenerator-runtime@0.13.11:
+ resolution: {integrity: sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==}
+ dev: false
+
/regexp.prototype.flags@1.5.0:
resolution: {integrity: sha512-0SutC3pNudRKgquxGoRGIz946MZVHqbNfPjBdxeOhBrdgDKlRoXmYLQN9xRbrR09ZXWeGAdPuif7egofn6v5LA==}
engines: {node: '>= 0.4'}
'ajv-formats',
'basic-ftp',
'chalk',
+ 'date-fns',
'http-status-codes',
'just-clone',
'just-merge',
'mnemonist/lru-map-with-delete.js',
'mnemonist/queue.js',
- 'moment',
'mongodb',
'node:async_hooks',
'node:crypto',
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';
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
if (
chargingProfile.chargingProfileKind === ChargingProfileKindType.RECURRING &&
chargingProfile.recurrencyKind === RecurrencyKindType.DAILY &&
- currentMoment.isAfter(chargingSchedule.startSchedule)
+ isAfter(currentDate, chargingSchedule.startSchedule!)
) {
if (!(chargingSchedule?.startSchedule instanceof Date)) {
logger.warn(
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);
}
- } else if (moment(chargingSchedule.startSchedule).isAfter(currentMoment)) {
+ } else if (isAfter(chargingSchedule.startSchedule!, currentDate)) {
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
}
// 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 = {
import { randomBytes, randomInt, randomUUID } from 'node:crypto';
import { inspect } from 'node:util';
+import { formatDuration, secondsToMilliseconds } from 'date-fns';
import clone from 'just-clone';
import { Constants } from './Constants';
export const formatDurationMilliSeconds = (duration: number): string => {
duration = convertToInt(duration);
- const hours = Math.floor(duration / (3600 * 1000));
- const minutes = Math.floor((duration / 1000 - hours * 3600) / 60);
- const seconds = duration / 1000 - hours * 3600 - minutes * 60;
- let hoursStr = hours.toString();
- let minutesStr = minutes.toString();
- let secondsStr = seconds.toString();
-
- if (hours < 10) {
- hoursStr = `0${hours.toString()}`;
- }
- if (minutes < 10) {
- minutesStr = `0${minutes.toString()}`;
- }
- if (seconds < 10) {
- secondsStr = `0${seconds.toString()}`;
- }
- return `${hoursStr}:${minutesStr}:${secondsStr.substring(0, 6)}`;
+ const days = Math.floor(duration / (24 * 3600 * 1000));
+ const hours = Math.floor(duration / (3600 * 1000) - days * 24);
+ const minutes = Math.floor(duration / (60 * 1000) - days * 24 * 60 - hours * 60);
+ const seconds = Math.floor(duration / 1000 - days * 24 * 3600 - hours * 3600 - minutes * 60);
+ return formatDuration({
+ days,
+ hours,
+ minutes,
+ seconds,
+ });
};
export const formatDurationSeconds = (duration: number): string => {
- return formatDurationMilliSeconds(duration * 1000);
+ return formatDurationMilliSeconds(secondsToMilliseconds(duration));
};
export const convertToDate = (