Skip to content

Commit a258afb

Browse files
committed
Merge remote-tracking branch 'origin/issue-6475-quick-fix' into dev-2.x
2 parents 5822923 + 1a1926d commit a258afb

File tree

5 files changed

+65
-11
lines changed

5 files changed

+65
-11
lines changed

application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/StoptimeImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ public DataFetcher<Integer> stopPositionInPattern() {
8585

8686
@Override
8787
public DataFetcher<Long> serviceDay() {
88-
return environment -> getSource(environment).getServiceDayMidnight();
88+
return environment -> {
89+
Long midnight = getSource(environment).getServiceDayMidnight();
90+
return midnight != TripTimeOnDate.UNDEFINED ? midnight : null;
91+
};
8992
}
9093

9194
@Override

application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/TripImpl.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ public DataFetcher<Iterable<TripTimeOnDate>> stoptimes() {
252252
getTransitService(environment).getScheduledTripTimes(getSource(environment)).orElse(null);
253253
}
254254

255+
/**
256+
* If stoptimesForDate does not have a parameter, and the trip does not run today, we will
257+
* still return a list of TripTimeOnDates, the same list as bare stoptimes() would return.
258+
* This is illogical, but existing UIs depend on this longstanding behavior.
259+
* @return
260+
*/
255261
@Override
256262
public DataFetcher<Iterable<TripTimeOnDate>> stoptimesForDate() {
257263
return environment -> {
@@ -260,11 +266,12 @@ public DataFetcher<Iterable<TripTimeOnDate>> stoptimesForDate() {
260266
var args = new GraphQLTypes.GraphQLTripStoptimesForDateArgs(environment.getArguments());
261267

262268
ZoneId timeZone = transitService.getTimeZone();
263-
LocalDate serviceDate = args.getGraphQLServiceDate() != null
264-
? ServiceDateUtils.parseString(args.getGraphQLServiceDate())
265-
: LocalDate.now(timeZone);
266-
267-
return transitService.getTripTimeOnDates(trip, serviceDate).orElse(null);
269+
if (args.getGraphQLServiceDate() != null) {
270+
LocalDate serviceDate = ServiceDateUtils.parseString(args.getGraphQLServiceDate());
271+
return transitService.getTripTimeOnDates(trip, serviceDate).orElse(null);
272+
} else {
273+
return transitService.getTripTimeOnDates(trip, LocalDate.now(timeZone), true).orElse(null);
274+
}
268275
};
269276
}
270277

application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,28 @@ public Optional<List<TripTimeOnDate>> getScheduledTripTimes(Trip trip) {
117117
}
118118

119119
@Override
120-
public Optional<List<TripTimeOnDate>> getTripTimeOnDates(Trip trip, LocalDate serviceDate) {
120+
public Optional<List<TripTimeOnDate>> getTripTimeOnDates(
121+
Trip trip,
122+
LocalDate serviceDate,
123+
boolean useScheduledWhenNonRunning
124+
) {
121125
TripPattern pattern = findPattern(trip, serviceDate);
122126

123127
Timetable timetable = findTimetable(pattern, serviceDate);
124128

125129
// This check is made here to avoid changing TripTimeOnDate.fromTripTimes
126130
TripTimes times = timetable.getTripTimes(trip);
127-
if (
128-
times == null ||
129-
!this.getServiceCodesRunningForDate(serviceDate).contains(times.getServiceCode())
130-
) {
131+
if (times == null) {
131132
return Optional.empty();
133+
} else if (!this.getServiceCodesRunningForDate(serviceDate).contains(times.getServiceCode())) {
134+
if (useScheduledWhenNonRunning) {
135+
// Technically not returning empty here is incorrect, you should use getScheduledTripTimes
136+
// above instead if you want this, but it has been the behavior for a very long time, and
137+
// at least one longstanding front end will fail without this.
138+
return Optional.ofNullable(TripTimeOnDate.fromTripTimes(timetable, trip));
139+
} else {
140+
return Optional.empty();
141+
}
132142
} else {
133143
Instant midnight = ServiceDateUtils.asStartOfService(
134144
serviceDate,
@@ -138,6 +148,11 @@ public Optional<List<TripTimeOnDate>> getTripTimeOnDates(Trip trip, LocalDate se
138148
}
139149
}
140150

151+
@Override
152+
public Optional<List<TripTimeOnDate>> getTripTimeOnDates(Trip trip, LocalDate serviceDate) {
153+
return getTripTimeOnDates(trip, serviceDate, false);
154+
}
155+
141156
@Override
142157
public Collection<String> listFeedIds() {
143158
return this.timetableRepository.getFeedIds();

application/src/main/java/org/opentripplanner/transit/service/TransitService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ public interface TransitService {
7373
*/
7474
Optional<List<TripTimeOnDate>> getScheduledTripTimes(Trip trip);
7575

76+
/**
77+
* @return if the trip doesn't run on the date specified, return schedule if
78+
* useScheduledWhenNonRunning is true, empty otherwise. Logically this is confusing,
79+
* but existing UIs depend on this.
80+
*/
81+
Optional<List<TripTimeOnDate>> getTripTimeOnDates(
82+
Trip trip,
83+
LocalDate serviceDate,
84+
boolean useScheduledWhenNonRunning
85+
);
86+
7687
/**
7788
* @return empty if the trip doesn't run on the date specified
7889
*/

application/src/test/java/org/opentripplanner/transit/service/DefaultTransitServiceTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,24 @@ void getRealtimeTripTimes() {
241241
);
242242
}
243243

244+
@Test
245+
void getTripTimesOnNoServiceDayWithUseScheduleOption() {
246+
Instant midnight = ServiceDateUtils.asStartOfService(
247+
SERVICE_DATE,
248+
service.getTimeZone()
249+
).toInstant();
250+
251+
assertEquals(
252+
Optional.of(
253+
List.of(
254+
new TripTimeOnDate(REALTIME_TRIP_TIMES, 0, REAL_TIME_PATTERN, SERVICE_DATE, midnight),
255+
new TripTimeOnDate(REALTIME_TRIP_TIMES, 1, REAL_TIME_PATTERN, SERVICE_DATE, midnight)
256+
)
257+
),
258+
service.getTripTimeOnDates(TRIP, SERVICE_DATE, true)
259+
);
260+
}
261+
244262
@Test
245263
void getTripTimesOnNoServiceDay() {
246264
assertEquals(Optional.empty(), service.getTripTimeOnDates(TRIP, NO_SERVICE_DATE));

0 commit comments

Comments
 (0)