66 Place
77} from '@opentripplanner/types'
88import { isTransitLeg } from '@opentripplanner/core-utils/lib/itinerary'
9- import { toDate , utcToZonedTime } from 'date-fns-tz'
9+ import { utcToZonedTime } from 'date-fns-tz'
1010import coreUtils from '@opentripplanner/core-utils'
1111import hash from 'object-hash'
1212import memoize from 'lodash.memoize'
@@ -21,15 +21,6 @@ export interface ItineraryStartTime {
2121 realtime : boolean
2222}
2323
24- // FIXME: replace with OTP2 logic.
25- interface LegWithOtp1HailedCar extends Leg {
26- hailedCar ?: boolean
27- }
28-
29- export interface ItineraryWithOtp1HailedCar extends Itinerary {
30- legs : LegWithOtp1HailedCar [ ]
31- }
32-
3324interface OtpResponse {
3425 plan : {
3526 itineraries : Itinerary [ ]
@@ -69,14 +60,11 @@ interface RelaxedFareProductSelector {
6960 * @returns true if an itinerary has no rental or ride hail leg (e.g. CAR_RENT, CAR_HAIL, BICYCLE_RENT, etc.).
7061 * (We use the corresponding fields returned by OTP to get transit legs and rental/ride hail legs.)
7162 */
72- export function itineraryCanBeMonitored (
73- itinerary ?: ItineraryWithOtp1HailedCar
74- ) : boolean {
63+ export function itineraryCanBeMonitored ( itinerary ?: Itinerary ) : boolean {
7564 return (
7665 ! ! itinerary ?. legs &&
7766 ! itinerary . legs . some (
78- ( leg : LegWithOtp1HailedCar ) =>
79- leg . rentedBike || leg . rentedCar || leg . rentedVehicle || leg . hailedCar
67+ ( leg : Leg ) => leg . rentedBike || ! ! leg . rideHailingEstimate
8068 )
8169 )
8270}
@@ -85,43 +73,19 @@ export function getMinutesUntilItineraryStart(itinerary: Itinerary): number {
8573 return differenceInMinutes ( new Date ( itinerary . startTime ) , new Date ( ) )
8674}
8775
88- /**
89- * Gets the first transit leg of the given itinerary, or null if none found.
90- */
91- function getFirstTransitLeg ( itinerary : Itinerary ) {
92- return itinerary ?. legs ?. find ( isTransitLeg )
93- }
94-
95- /**
96- * Get the first stop ID from the itinerary in the underscore format required by
97- * the startTransitStopId query param (e.g., TRIMET_12345 instead of TRIMET:12345).
98- */
99- export function getFirstStopId ( itinerary : Itinerary ) : string | undefined {
100- return getFirstTransitLeg ( itinerary ) ?. from . stopId ?. replace ( ':' , '_' )
101- }
102-
10376/**
10477 * Returns the set of monitored days that will be initially shown to the user
10578 * for the given itinerary.
10679 * @param itinerary The itinerary from which the default monitored days are extracted.
107- * @returns ['monday' thru 'friday'] if itinerary happens on a weekday(*),
108- * ['saturday', 'sunday'] if itinerary happens on a saturday/sunday(*).
109- * (*) For transit itineraries, the first transit leg is used to make
110- * the determination. Otherwise, the itinerary startTime is used.
80+ * @returns ['monday' thru 'friday'] if itinerary happens on a weekday,
81+ * ['saturday', 'sunday'] if itinerary happens on a saturday/sunday,
82+ * based on the itinerary startTime.
11183 */
11284export function getItineraryDefaultMonitoredDays (
11385 itinerary : Itinerary ,
11486 timeZone = coreUtils . time . getUserTimezone ( )
11587) : string [ ] {
116- const firstTransitLeg = getFirstTransitLeg ( itinerary )
117- // firstTransitLeg should be non-null because only transit trips can be monitored at this time.
118- // - using serviceDate covers legs that start past midnight.
119- // - The format of serviceDate can either be 'yyyyMMdd' (OTP v1) or 'yyyy-MM-dd' (OTP v2)
120- // and both formats are correctly handled by toDate from date-fns-tz.
121- const startDate = firstTransitLeg
122- ? toDate ( firstTransitLeg . serviceDate || '' , { timeZone } )
123- : utcToZonedTime ( new Date ( itinerary . startTime ) , timeZone )
124-
88+ const startDate = utcToZonedTime ( new Date ( itinerary . startTime ) , timeZone )
12589 const dayOfWeek = startDate . getDay ( )
12690 return dayOfWeek === 0 || dayOfWeek === 6 ? WEEKEND_DAYS : WEEKDAYS
12791}
@@ -172,14 +136,10 @@ export function sortStartTimes(
172136}
173137
174138// Ignore certain keys that could add significant calculation time to hashing.
175- // The alerts are irrelevant, but the intermediateStops, interStopGeometry and
139+ // The alerts are irrelevant, but the intermediateStops, legGeometry and
176140// steps could have the legGeometry substitute as an equivalent hash value
177- const blackListedKeys = [
178- 'alerts' ,
179- 'intermediateStops' ,
180- 'interStopGeometry' ,
181- 'steps'
182- ]
141+ const blackListedKeys = [ 'alerts' , 'intermediateStops' , 'legGeometry' , 'steps' ]
142+
183143// make blackListedKeys into an object due to superior lookup performance
184144const blackListedKeyLookup : Record < string , boolean > = { }
185145blackListedKeys . forEach ( ( key ) => {
0 commit comments