Extend data in the schedule box

This commit is contained in:
2026-05-04 21:49:59 +01:00
parent 1c4c7ccabc
commit 6a857c2d64
3 changed files with 407 additions and 298 deletions

View File

@@ -23,27 +23,28 @@ export function formatUkTime(dateStr: string | Date | undefined): string {
* @param 'Schedule Location' object
* @returns Delay string for departure boards
*/
export function calculateDelay(loc: ApiTrainsTrainDetails.ServiceLocation): {val: string, type: string} {
const pairs = [
{ actual: loc.atd, sched: loc.ptd ?? loc.wtd },
{ actual: loc.ata, sched: loc.pta ?? loc.wta },
{ actual: loc.atp, sched: loc.wtp }
];
export function calculateDelay(loc: ApiTrainsTrainDetails.ServiceLocation): {
val: string;
type: string;
} {
const pairs = [
{ actual: loc.atd, sched: loc.ptd ?? loc.wtd },
{ actual: loc.ata, sched: loc.pta ?? loc.wta },
{ actual: loc.atp, sched: loc.wtp }
];
const match = pairs.find(p => p.actual && p.sched);
const match = pairs.find((p) => p.actual && p.sched);
if (!match || !match.actual || !match.sched) return {val: '', type: 'none'};
if (!match || !match.actual || !match.sched) return { val: '', type: 'none' };
const diffMinutes = Math.round(
(Date.parse(match.actual) - Date.parse(match.sched)) / 60000
);
const diffMinutes = Math.round((Date.parse(match.actual) - Date.parse(match.sched)) / 60000);
if (diffMinutes === 0) return {val: 'RT', type: 'ontime'};
if (diffMinutes === 0) return { val: 'RT', type: 'ontime' };
const absDiff = Math.abs(diffMinutes);
if (diffMinutes > 0) {
return { val: `${absDiff}L`, type: 'late' };
} else {
return { val: `${absDiff}E`, type: 'early' };
}
const absDiff = Math.abs(diffMinutes);
if (diffMinutes > 0) {
return { val: `${absDiff}L`, type: 'late' };
} else {
return { val: `${absDiff}E`, type: 'early' };
}
}