Refactor 'classGenerator()'

This commit is contained in:
Fred Boniface 2023-09-14 21:30:56 +01:00
parent b173410dd6
commit ef7d965523

View File

@ -37,47 +37,20 @@
platArr.push('nonPass');
}
if (service.sta !== undefined) {
if (service.eta !== undefined) {
if (service.sta < service.eta) {
arrArr.push('late');
}
} else if (service.ata !== undefined) {
if (service.sta < service.ata) {
arrArr.push('late');
}
}
if (service.eta !== undefined) {
if (service.sta > service.eta) {
arrArr.push('early');
}
} else if (service.ata !== undefined) {
if (service.sta > service.ata) {
arrArr.push('early');
function checkLateEarly(originalTime: Date | undefined, comparedTime: Date | undefined, arr: string[]) {
if (originalTime !== undefined && comparedTime instanceof Date) {
if (originalTime < comparedTime) {
arr.push('late');
} else if (originalTime > comparedTime) {
arr.push('early');
}
}
}
if (service.std !== undefined) {
if (service.etd !== undefined) {
if (service.std < service.etd) {
depArr.push('late');
}
} else if (service.atd !== undefined) {
if (service.std < service.atd) {
depArr.push('late');
}
}
if (service.etd !== undefined) {
if (service.std > service.etd) {
depArr.push('early');
}
} else if (service.atd !== undefined) {
if (service.std > service.atd) {
depArr.push('early');
}
}
}
checkLateEarly(service.sta, service.eta, arrArr);
checkLateEarly(service.sta, service.ata, arrArr);
checkLateEarly(service.std, service.etd, depArr);
checkLateEarly(service.std, service.atd, depArr);
return {
other: otherArr.join(' '),
@ -88,7 +61,7 @@
}
function fmtTime(date: Date | string | undefined): string | false {
if (date === 'RT' || date === "CANC" || date === "LATE") return date;
if (typeof date === 'string') return date;
if (date instanceof Date) {
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');