Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(check-monitored-trip): advance to next trip day when itinerary is no longer valid #284

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use explict imports. Can you revert this please. There is also a setting in Intellij (assuming you are using this) that prevents this.

import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

Expand Down Expand Up @@ -673,7 +666,7 @@ public boolean shouldSkipMonitoredTripCheck(boolean persist) throws Exception {
}
}

if (isPrevMatchingItineraryNotConcluded()) {
if (isPrevMatchingItineraryNotConcluded() && isPrevMatchingItineraryDayValid()) {
// Skip checking the trip the rest of the time that it is active if the trip was deemed not possible for the
// next possible time during a previous query to find candidate itinerary matches.
if (previousJourneyState.tripStatus == TripStatus.NEXT_TRIP_NOT_POSSIBLE) {
Expand Down Expand Up @@ -771,6 +764,33 @@ public boolean shouldSkipMonitoredTripCheck(boolean persist) throws Exception {
return true;
}

// Check if previous matching itinerary day is still valid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to a method comment. Start with /** and end with */

private boolean isPrevMatchingItineraryDayValid() {
Calendar calendar = Calendar.getInstance();
calendar.setTime(previousMatchingItinerary.startTime);

int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. You could in-line this variable.


switch (dayOfWeek) {
case Calendar.SUNDAY:
return trip.sunday;
case Calendar.MONDAY:
return trip.monday;
case Calendar.TUESDAY:
return trip.tuesday;
case Calendar.WEDNESDAY:
return trip.wednesday;
case Calendar.THURSDAY:
return trip.thursday;
case Calendar.FRIDAY:
return trip.friday;
case Calendar.SATURDAY:
return trip.saturday;
default:
return false; // This should never happen, but for safety
}
}

private void advanceToNextMonitoredDay() {
// Check if the journeyState indicates that an itinerary has already been calculated in a previous run of
// this CheckMonitoredTrip. If the targetDate is null, then the current date has not yet been checked. If
Expand Down
Loading