HashAlgorithmEnumType,
InstallCertificateUseEnumType,
} from '../../../types/ocpp/2.0/Common.js'
-import { getErrorMessage } from '../../../utils/index.js'
+import { convertToDate, getErrorMessage } from '../../../utils/index.js'
/**
* Interface for ChargingStation with certificate manager
}
const cert = new X509Certificate(firstCertMatch[0])
const now = new Date()
- if (now < new Date(cert.validFrom)) {
+ const validFromDate = convertToDate(cert.validFrom)
+ const validToDate = convertToDate(cert.validTo)
+ if (validFromDate != null && now < validFromDate) {
return { reason: 'Certificate is not yet valid', valid: false }
}
- if (now > new Date(cert.validTo)) {
+ if (validToDate != null && now > validToDate) {
return { reason: 'Certificate has expired', valid: false }
}
if (!cert.issuer.trim()) {
OCPP20ChargingRateUnitEnumType,
OCPP20ReasonEnumType,
} from '../../../types/ocpp/2.0/Transaction.js'
-import { Constants, generateUUID, logger, sleep, validateUUID } from '../../../utils/index.js'
+import {
+ Constants,
+ convertToDate,
+ generateUUID,
+ logger,
+ sleep,
+ validateUUID,
+} from '../../../utils/index.js'
import { getConfigurationKey } from '../../ConfigurationKeyUtils.js'
import {
getIdTagsFile,
// C12: If retrieveDateTime is in the future, send DownloadScheduled and wait
const now = Date.now()
- const retrieveTime = new Date(retrieveDateTime).getTime()
+ const retrieveTime = convertToDate(retrieveDateTime)?.getTime() ?? now
if (retrieveTime > now) {
await this.sendFirmwareStatusNotification(
chargingStation,
// C12: If installDateTime is in the future, send InstallScheduled and wait
if (installDateTime != null) {
- const installTime = new Date(installDateTime).getTime()
const currentTime = Date.now()
+ const installTime = convertToDate(installDateTime)?.getTime() ?? currentTime
if (installTime > currentTime) {
await this.sendFirmwareStatusNotification(
chargingStation,
}
const now = new Date()
- if (chargingProfile.validFrom && chargingProfile.validTo) {
- if (chargingProfile.validFrom >= chargingProfile.validTo) {
+ const validFromDate = convertToDate(chargingProfile.validFrom)
+ const validToDate = convertToDate(chargingProfile.validTo)
+ if (validFromDate && validToDate) {
+ if (validFromDate >= validToDate) {
logger.warn(
`${chargingStation.logPrefix()} ${moduleName}.validateChargingProfile: validFrom must be before validTo`
)
}
}
- if (chargingProfile.validTo && chargingProfile.validTo <= now) {
+ if (validToDate && validToDate <= now) {
logger.warn(
`${chargingStation.logPrefix()} ${moduleName}.validateChargingProfile: Charging profile already expired`
)
return false
}
- if (
- schedule.startSchedule &&
- chargingProfile.validFrom &&
- schedule.startSchedule < chargingProfile.validFrom
- ) {
+ const startScheduleDate = convertToDate(schedule.startSchedule)
+ const validFromDate = convertToDate(chargingProfile.validFrom)
+ const validToDate = convertToDate(chargingProfile.validTo)
+
+ if (startScheduleDate != null && validFromDate != null && startScheduleDate < validFromDate) {
logger.warn(
`${chargingStation.logPrefix()} ${moduleName}.validateChargingSchedule: Schedule start time cannot be before profile validFrom`
)
return false
}
- if (
- schedule.startSchedule &&
- chargingProfile.validTo &&
- schedule.startSchedule >= chargingProfile.validTo
- ) {
+ if (startScheduleDate != null && validToDate != null && startScheduleDate >= validToDate) {
logger.warn(
`${chargingStation.logPrefix()} ${moduleName}.validateChargingSchedule: Schedule start time must be before profile validTo`
)
type ResponseHandler,
} from '../../../types/index.js'
import { OCPP20AuthorizationStatusEnumType } from '../../../types/ocpp/2.0/Transaction.js'
-import { logger } from '../../../utils/index.js'
+import { convertToDate, logger } from '../../../utils/index.js'
import { OCPPResponseService } from '../OCPPResponseService.js'
import { OCPP20ServiceUtils } from './OCPP20ServiceUtils.js'
payload: OCPP20HeartbeatResponse
): void {
logger.debug(
- `${chargingStation.logPrefix()} ${moduleName}.handleResponseHeartbeat: Heartbeat response received at ${payload.currentTime.toISOString()}`
+ `${chargingStation.logPrefix()} ${moduleName}.handleResponseHeartbeat: Heartbeat response received at ${convertToDate(payload.currentTime)?.toISOString() ?? 'unknown'}`
)
}