Skip to content

Commit 074fd95

Browse files
committed
front: guard times-stops arrival interpolation against stale simulation data
1 parent e1bce0e commit 074fd95

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

front/src/modules/timesStops/hooks/useTimesStopsTableData.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,15 @@ const useTimesStopsTableData = (
365365
const matchingReportTrainIndex = stableTrain.positions.findIndex(
366366
(position) => position === op.position
367367
);
368+
const isWithinRange =
369+
op.position >= stableTrain.positions[0] &&
370+
op.position <= stableTrain.positions[stableTrain.positions.length - 1];
368371
const computedArrivalMs =
369-
matchingReportTrainIndex === -1
370-
? interpolateValue(stableTrain, op.position, 'times')
371-
: stableTrain.times[matchingReportTrainIndex];
372+
matchingReportTrainIndex !== -1
373+
? stableTrain.times[matchingReportTrainIndex]
374+
: isWithinRange
375+
? interpolateValue(stableTrain, op.position, 'times')
376+
: undefined;
372377
computedArrival =
373378
computedArrivalMs !== undefined
374379
? new Duration({ milliseconds: computedArrivalMs })

0 commit comments

Comments
 (0)