Extend data in the schedule box
This commit is contained in:
@@ -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' };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user