Skip to content

Commit

Permalink
Merge pull request #4 from HSLdevcom/feat/dst_fix
Browse files Browse the repository at this point in the history
Fix start time not working with DST
  • Loading branch information
mjaakko authored Mar 31, 2020
2 parents f86b168 + 956c895 commit a6d5464
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/fi/hsl/suomenlinna_hfp/TripProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
public class TripProcessor {
private static final Logger LOG = LoggerFactory.getLogger(TripProcessor.class);

private static final int ONE_DAY_IN_SECONDS = 24 * 60 * 60;

private Map<VehicleId, TripAndRouteWithStopTimes> registeredTrips = new HashMap<>();
//Time when vehicle registered for the trip
private Map<VehicleId, ZonedDateTime> registrationTimes = new HashMap<>();
Expand Down Expand Up @@ -88,7 +90,17 @@ public void updateGtfsData(GtfsIndex gtfsIndex, ServiceDates serviceDates) {
value = new TreeMap<>();
}

ZonedDateTime startTime = date.atStartOfDay(timezone).plus(stopTimes.first().getDepartureTime(), ChronoUnit.SECONDS);
ZonedDateTime startTime;

int departureTimeSeconds = stopTimes.first().getDepartureTime();
if (departureTimeSeconds >= ONE_DAY_IN_SECONDS) {
//If the trip starts at or after midnight add one day to date and minus one day in seconds from start time
//This is needed to get the start time for correct date
startTime = date.plusDays(1).atTime(LocalTime.ofSecondOfDay(departureTimeSeconds - ONE_DAY_IN_SECONDS)).atZone(timezone);
} else {
startTime = date.atTime(LocalTime.ofSecondOfDay(departureTimeSeconds)).atZone(timezone);
}

value.put(startTime, new TripAndRouteWithStopTimes(trip,
gtfsIndex.routesById.get(trip.getRouteId()),
date,
Expand Down

0 comments on commit a6d5464

Please sign in to comment.