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.
@@ -13002,29 +13002,35 @@ class Route {
13002
13002
  * @returns The index of the earliest trip meeting the criteria, or undefined if no such trip is found.
13003
13003
  */
13004
13004
  findEarliestTrip(stopId, after = Time.origin(), beforeTrip) {
13005
- const maxTripIndex = beforeTrip !== undefined
13006
- ? Math.min(beforeTrip - 1, this.nbTrips - 1)
13007
- : this.nbTrips - 1;
13008
- if (maxTripIndex < 0) {
13005
+ if (this.nbTrips <= 0)
13009
13006
  return undefined;
13010
- }
13011
- let earliestTripIndex;
13012
- let lowTrip = 0;
13013
- let highTrip = maxTripIndex;
13014
- while (lowTrip <= highTrip) {
13015
- const midTrip = Math.floor((lowTrip + highTrip) / 2);
13016
- const departure = this.departureFrom(stopId, midTrip);
13017
- const pickUpType = this.pickUpTypeFrom(stopId, midTrip);
13018
- if ((departure.isAfter(after) || departure.equals(after)) &&
13019
- pickUpType !== 'NOT_AVAILABLE') {
13020
- earliestTripIndex = midTrip;
13021
- highTrip = midTrip - 1;
13007
+ let hi = this.nbTrips - 1;
13008
+ if (beforeTrip !== undefined)
13009
+ hi = Math.min(hi, beforeTrip - 1);
13010
+ if (hi < 0)
13011
+ return undefined;
13012
+ let lo = 0;
13013
+ let lb = -1;
13014
+ while (lo <= hi) {
13015
+ const mid = (lo + hi) >>> 1;
13016
+ const depMid = this.departureFrom(stopId, mid);
13017
+ if (depMid.isBefore(after)) {
13018
+ lo = mid + 1;
13022
13019
  }
13023
13020
  else {
13024
- lowTrip = midTrip + 1;
13021
+ lb = mid;
13022
+ hi = mid - 1;
13023
+ }
13024
+ }
13025
+ if (lb === -1)
13026
+ return undefined;
13027
+ for (let t = lb; t < (beforeTrip !== null && beforeTrip !== void 0 ? beforeTrip : this.nbTrips); t++) {
13028
+ const pickup = this.pickUpTypeFrom(stopId, t);
13029
+ if (pickup !== 'NOT_AVAILABLE') {
13030
+ return t;
13025
13031
  }
13026
13032
  }
13027
- return earliestTripIndex;
13033
+ return undefined;
13028
13034
  }
13029
13035
  /**
13030
13036
  * Retrieves the index of a stop within the route.