- // Add active charging profiles into chargingProfiles array
- if (
- isValidTime(storedChargingProfile.chargingSchedule?.startSchedule) &&
- isWithinInterval(storedChargingProfile.chargingSchedule.startSchedule!, interval) &&
- (isEmptyArray(chargingProfiles) ||
- (isNotEmptyArray(chargingProfiles) &&
- (isBefore(
- storedChargingProfile.chargingSchedule.startSchedule!,
- min(
- chargingProfiles.map(
- (chargingProfile) => chargingProfile.chargingSchedule.startSchedule ?? maxTime,
- ),
- ),
- ) ||
- isAfter(
- storedChargingProfile.chargingSchedule.startSchedule!,
- max(
- chargingProfiles.map(
- (chargingProfile) =>
- addSeconds(
- chargingProfile.chargingSchedule.startSchedule!,
- chargingProfile.chargingSchedule.duration!,
- ) ?? minTime,
- ),
- ),
- ))))
- ) {
- chargingProfiles.push(storedChargingProfile);
- }
- }
- const compositeScheduleStart: Date = min(
- chargingProfiles.map(
- (chargingProfile) => chargingProfile.chargingSchedule.startSchedule ?? maxTime,
- ),
- );
- const compositeScheduleDuration: number = Math.max(
- ...chargingProfiles.map(
- (chargingProfile) => chargingProfile.chargingSchedule.duration ?? -Infinity,
- ),
- );
- // FIXME: remove overlapping charging schedule periods
- const compositeSchedulePeriods: OCPP16ChargingSchedulePeriod[] = chargingProfiles
- .map((chargingProfile) => chargingProfile.chargingSchedule.chargingSchedulePeriod)
- .reduce(
- (accumulator, value) =>
- accumulator.concat(value).sort((a, b) => a.startPeriod - b.startPeriod),
- [],
+ compositeSchedule = OCPP16ServiceUtils.composeChargingSchedules(
+ previousCompositeSchedule,
+ chargingProfile.chargingSchedule,
+ compositeScheduleInterval,