Skip to content

Fix & enhance service maintenance detect function logic #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/components/operationalStatus/OperationalStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,27 @@ export const OperationalStatus: FunctionComponent<OperationalStatusProps> = ({
return 0;
});

const isServiceInMaintenanceNow = (service: Service) => {
const serviceInMaintenance =
maintenances &&
maintenances.find(
(maintenance: PlannedMaintenanceItem) =>
maintenance.service.toLowerCase() === service.name.toLowerCase()
);
const isServiceInMaintenanceNow = (service: Service): boolean => {
if (!maintenances || maintenances.length === 0) {
return false;
}

const serviceInMaintenance = maintenances.find(
(maintenance: PlannedMaintenanceItem) =>
maintenance.service.toLowerCase() === service.name.toLowerCase()
);

if (!serviceInMaintenance) return false;
if (!serviceInMaintenance) {
return false;
}

const maintenanceFrom = new Date(serviceInMaintenance.date_time_from);
const maintenanceTo = new Date(serviceInMaintenance.date_time_to);

if (isNaN(maintenanceFrom.getTime()) || isNaN(maintenanceTo.getTime())) {
return false;
}

const currentTime = new Date();
return currentTime >= maintenanceFrom && currentTime <= maintenanceTo;
};
Expand Down