Skip to content

Commit

Permalink
use seconds from midnight instead of minutes for test
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Dec 4, 2024
1 parent ee933f0 commit 16c4dc6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public TripUpdateBuilder(
);
}

public TripUpdateBuilder addStopTime(String stopId, int minutes) {
public TripUpdateBuilder addStopTime(String stopId, int secondsFromMidnight) {
return addStopTime(
stopId,
minutes,
secondsFromMidnight,
NO_VALUE,
NO_DELAY,
NO_DELAY,
Expand All @@ -66,10 +66,10 @@ public TripUpdateBuilder addStopTime(String stopId, int minutes) {
);
}

public TripUpdateBuilder addStopTime(String stopId, int minutes, String headsign) {
public TripUpdateBuilder addStopTime(String stopId, int secondsFromMidnight, String headsign) {
return addStopTime(
stopId,
minutes,
secondsFromMidnight,
NO_VALUE,
NO_DELAY,
NO_DELAY,
Expand All @@ -81,10 +81,10 @@ public TripUpdateBuilder addStopTime(String stopId, int minutes, String headsign
);
}

public TripUpdateBuilder addStopTimeWithDelay(String stopId, int minutes, int delay) {
public TripUpdateBuilder addStopTimeWithDelay(String stopId, int secondsFromMidnight, int delay) {
return addStopTime(
stopId,
minutes,
secondsFromMidnight,
NO_VALUE,
delay,
delay,
Expand All @@ -98,27 +98,31 @@ public TripUpdateBuilder addStopTimeWithDelay(String stopId, int minutes, int de

public TripUpdateBuilder addStopTimeWithScheduled(
String stopId,
int minutes,
int scheduledMinutes
int secondsFromMidnight,
int scheduledSeconds
) {
return addStopTime(
stopId,
minutes,
secondsFromMidnight,
NO_VALUE,
NO_DELAY,
NO_DELAY,
DEFAULT_SCHEDULE_RELATIONSHIP,
null,
null,
null,
scheduledMinutes
scheduledSeconds
);
}

public TripUpdateBuilder addStopTime(String stopId, int minutes, DropOffPickupType pickDrop) {
public TripUpdateBuilder addStopTime(
String stopId,
int secondsFromMidnight,
DropOffPickupType pickDrop
) {
return addStopTime(
stopId,
minutes,
secondsFromMidnight,
NO_VALUE,
NO_DELAY,
NO_DELAY,
Expand All @@ -132,12 +136,12 @@ public TripUpdateBuilder addStopTime(String stopId, int minutes, DropOffPickupTy

public TripUpdateBuilder addStopTime(
String stopId,
int minutes,
int secondsFromMidnight,
StopTimeUpdate.StopTimeProperties.DropOffPickupType pickDrop
) {
return addStopTime(
stopId,
minutes,
secondsFromMidnight,
NO_VALUE,
NO_DELAY,
NO_DELAY,
Expand Down Expand Up @@ -219,10 +223,10 @@ public TripUpdateBuilder addSkippedStop(int stopSequence) {
);
}

public TripUpdateBuilder addSkippedStop(String stopId, int minutes) {
public TripUpdateBuilder addSkippedStop(String stopId, int secondsFromMidnight) {
return addStopTime(
stopId,
minutes,
secondsFromMidnight,
NO_VALUE,
NO_DELAY,
NO_DELAY,
Expand All @@ -234,10 +238,14 @@ public TripUpdateBuilder addSkippedStop(String stopId, int minutes) {
);
}

public TripUpdateBuilder addSkippedStop(String stopId, int minutes, DropOffPickupType pickDrop) {
public TripUpdateBuilder addSkippedStop(
String stopId,
int secondsFromMidnight,
DropOffPickupType pickDrop
) {
return addStopTime(
stopId,
minutes,
secondsFromMidnight,
NO_VALUE,
NO_DELAY,
NO_DELAY,
Expand All @@ -260,15 +268,15 @@ public TripUpdateBuilder addRawStopTime(StopTimeUpdate stopTime) {

private TripUpdateBuilder addStopTime(
@Nullable String stopId,
int minutes,
int secondsFromMidnight,
int stopSequence,
int arrivalDelay,
int departureDelay,
StopTimeUpdate.ScheduleRelationship scheduleRelationShip,
@Nullable DropOffPickupType pickDrop,
@Nullable StopTimeUpdate.StopTimeProperties.DropOffPickupType gtfsPickDrop,
@Nullable String headsign,
int scheduledMinutes
int scheduledSeconds
) {
final StopTimeUpdate.Builder stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder();
stopTimeUpdateBuilder.setScheduleRelationship(scheduleRelationShip);
Expand Down Expand Up @@ -304,14 +312,14 @@ private TripUpdateBuilder addStopTime(
final GtfsRealtime.TripUpdate.StopTimeEvent.Builder arrivalBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
final GtfsRealtime.TripUpdate.StopTimeEvent.Builder departureBuilder = stopTimeUpdateBuilder.getDepartureBuilder();

if (minutes > NO_VALUE) {
var epochSeconds = midnight.plusHours(8).plusMinutes(minutes).toEpochSecond();
if (secondsFromMidnight > NO_VALUE) {
var epochSeconds = midnight.plusSeconds(secondsFromMidnight).toEpochSecond();
arrivalBuilder.setTime(epochSeconds);
departureBuilder.setTime(epochSeconds);
}

if (scheduledMinutes > NO_VALUE) {
var epochSeconds = midnight.plusHours(8).plusMinutes(scheduledMinutes).toEpochSecond();
if (scheduledSeconds > NO_VALUE) {
var epochSeconds = midnight.plusSeconds(scheduledSeconds).toEpochSecond();
arrivalBuilder.setScheduledTime(epochSeconds);
departureBuilder.setScheduledTime(epochSeconds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,10 @@ public void addedTripWithDelay() {
var env = RealtimeTestEnvironment.gtfs().build();
var builder = new TripUpdateBuilder(ADDED_TRIP_ID, SERVICE_DATE, ADDED, TIME_ZONE);

// A1: scheduled 08:30:00
// B1: scheduled 08:40:00, delay 300 seconds (actual 08:45:00)
// C1: scheduled 08:55:00
builder
.addStopTime(STOP_A1_ID, 30)
.addStopTimeWithDelay(STOP_B1_ID, 45, 300)
.addStopTimeWithScheduled(STOP_C1_ID, 55, 54);
.addStopTime(STOP_A1_ID, 10000)
.addStopTimeWithDelay(STOP_B1_ID, 11300, 300)
.addStopTimeWithScheduled(STOP_C1_ID, 12500, 12000);

var tripUpdate = builder.build();
env.applyTripUpdate(tripUpdate);
Expand All @@ -191,11 +188,11 @@ public void addedTripWithDelay() {
var forTodayAddedTripIndex = forToday.getTripIndex(ADDED_TRIP_ID);
var tripTimes = forToday.getTripTimes(forTodayAddedTripIndex);
assertEquals(0, tripTimes.getDepartureDelay(0));
assertEquals(30600, tripTimes.getDepartureTime(0)); // 08:30:00
assertEquals(10000, tripTimes.getDepartureTime(0));
assertEquals(300, tripTimes.getArrivalDelay(1));
assertEquals(31500, tripTimes.getArrivalTime(1)); // 08:45:00
assertEquals(60, tripTimes.getArrivalDelay(2));
assertEquals(32100, tripTimes.getArrivalTime(2)); // 08:55:00
assertEquals(11300, tripTimes.getArrivalTime(1));
assertEquals(500, tripTimes.getArrivalDelay(2));
assertEquals(12500, tripTimes.getArrivalTime(2));
}

private static TripPattern assertAddedTrip(String tripId, RealtimeTestEnvironment env) {
Expand Down

0 comments on commit 16c4dc6

Please sign in to comment.