Skip to content

Commit 2ae95ab

Browse files
committed
fix: fix the calculation of collapsedsection total travel time
1 parent 2279e88 commit 2ae95ab

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/app/view/editor-main-view/data-views/trainrunsections.view.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -878,20 +878,24 @@ export class TrainrunSectionsView {
878878
break;
879879

880880
case TrainrunSectionText.TrainrunSectionTravelTime:
881-
// Special case for multiple sections: calculate total time
881+
// Special case for multiple sections: calculate total time including stop times at intermediate nodes
882882
if (viewObject.trainrunSections.length > 1) {
883-
const firstSection = viewObject.trainrunSections[0];
884-
const lastSection = viewObject.trainrunSections.at(-1)!;
883+
const totalTime = viewObject.trainrunSections.reduce((sum, section, index) => {
884+
// Add travel time for this section
885+
let sectionTime = section.getTravelTime();
886+
887+
// Add stop time at intermediate nodes (all except the last section)
888+
if (index < viewObject.trainrunSections.length - 1) {
889+
const nextSection = viewObject.trainrunSections[index + 1];
890+
const stopTime = Math.abs(
891+
nextSection.getSourceDepartureConsecutiveTime() -
892+
section.getTargetArrivalConsecutiveTime(),
893+
);
894+
sectionTime += stopTime;
895+
}
885896

886-
const startTime = TrainrunSectionsView.getTime(
887-
firstSection,
888-
TrainrunSectionText.SourceDeparture,
889-
);
890-
const endTime = TrainrunSectionsView.getTime(
891-
lastSection,
892-
TrainrunSectionText.TargetArrival,
893-
);
894-
const totalTime = endTime - startTime;
897+
return sum + sectionTime;
898+
}, 0);
895899

896900
return (
897901
TrainrunSectionsView.formatTime(totalTime, editorView.getTimeDisplayPrecision()) + "'"

0 commit comments

Comments
 (0)