This commit is contained in:
2025-11-15 17:53:50 +01:00
parent 1bebded484
commit 5dc296805a
15 changed files with 634 additions and 688 deletions

View File

@@ -42,7 +42,28 @@ func (t *Trip) AddStopTime(stopTime *StopTime) {
if t.Stops == nil {
t.Stops = make([]*StopTime, 0)
}
t.Stops = append(t.Stops, stopTime)
// Find the index to insert based on StopSequence
idx := 0
for i, st := range t.Stops {
if stopTime.StopSequence < st.StopSequence {
idx = i
break
}
idx = i + 1
}
// Insert at the correct position
t.Stops = append(t.Stops[:idx], append([]*StopTime{stopTime}, t.Stops[idx:]...)...)
// Adjust times if necessary for next-day continuation
for i := idx; i < len(t.Stops)-1; i++ {
curr := t.Stops[i]
next := t.Stops[i+1]
if next.ArrivalTime < curr.ArrivalTime {
next.ArrivalTime += 86400
}
if next.DepartureTime < curr.DepartureTime {
next.DepartureTime += 86400
}
}
}
func (t *Trip) Has(stop *Stop) (*StopTime, bool) {