minotor 7.0.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13004,29 +13004,35 @@ class Route {
13004
13004
  * @returns The index of the earliest trip meeting the criteria, or undefined if no such trip is found.
13005
13005
  */
13006
13006
  findEarliestTrip(stopId, after = Time.origin(), beforeTrip) {
13007
- const maxTripIndex = beforeTrip !== undefined
13008
- ? Math.min(beforeTrip - 1, this.nbTrips - 1)
13009
- : this.nbTrips - 1;
13010
- if (maxTripIndex < 0) {
13007
+ if (this.nbTrips <= 0)
13011
13008
  return undefined;
13012
- }
13013
- let earliestTripIndex;
13014
- let lowTrip = 0;
13015
- let highTrip = maxTripIndex;
13016
- while (lowTrip <= highTrip) {
13017
- const midTrip = Math.floor((lowTrip + highTrip) / 2);
13018
- const departure = this.departureFrom(stopId, midTrip);
13019
- const pickUpType = this.pickUpTypeFrom(stopId, midTrip);
13020
- if ((departure.isAfter(after) || departure.equals(after)) &&
13021
- pickUpType !== 'NOT_AVAILABLE') {
13022
- earliestTripIndex = midTrip;
13023
- highTrip = midTrip - 1;
13009
+ let hi = this.nbTrips - 1;
13010
+ if (beforeTrip !== undefined)
13011
+ hi = Math.min(hi, beforeTrip - 1);
13012
+ if (hi < 0)
13013
+ return undefined;
13014
+ let lo = 0;
13015
+ let lb = -1;
13016
+ while (lo <= hi) {
13017
+ const mid = (lo + hi) >>> 1;
13018
+ const depMid = this.departureFrom(stopId, mid);
13019
+ if (depMid.isBefore(after)) {
13020
+ lo = mid + 1;
13024
13021
  }
13025
13022
  else {
13026
- lowTrip = midTrip + 1;
13023
+ lb = mid;
13024
+ hi = mid - 1;
13025
+ }
13026
+ }
13027
+ if (lb === -1)
13028
+ return undefined;
13029
+ for (let t = lb; t < (beforeTrip !== null && beforeTrip !== void 0 ? beforeTrip : this.nbTrips); t++) {
13030
+ const pickup = this.pickUpTypeFrom(stopId, t);
13031
+ if (pickup !== 'NOT_AVAILABLE') {
13032
+ return t;
13027
13033
  }
13028
13034
  }
13029
- return earliestTripIndex;
13035
+ return undefined;
13030
13036
  }
13031
13037
  /**
13032
13038
  * Retrieves the index of a stop within the route.