Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
<dependency>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-gtfs</artifactId>
<version>10.2.0</version>
<version>11.0.0</version>
</dependency>
<!-- Processing is used for the debug GUI (though we could probably use just Java2D) -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,36 @@ private BookingTime latestBookingTime(BookingRule rule) {
}

/**
* If GTFS does not specify the latest booking time/day, the underlying values default to 0.
* If GTFS does not specify the latest booking time/day, the underlying values default to NO_VALUE.
* In that case, we do not set the booking time so that min/max booking notice can apply.
*
* @return null if both timeSeconds and day are 0, otherwise a BookingTime instance
* @return null if either timeSeconds or day are NO_VALUE, otherwise a BookingTime instance
*/
@Nullable
private BookingTime resolveBookingTime(int timeSeconds, int day) {
if (timeSeconds == 0 && day == 0) {
if (timeSeconds == BookingRule.NO_VALUE || day == BookingRule.NO_VALUE) {
return null;
}

return new BookingTime(LocalTime.ofSecondOfDay(timeSeconds), day);
}

@Nullable
private Duration minimumBookingNotice(BookingRule rule) {
return Duration.ofMinutes(rule.getPriorNoticeDurationMin());
return resolveNoticePeriod(rule.getPriorNoticeDurationMin());
}

@Nullable
private Duration maximumBookingNotice(BookingRule rule) {
return Duration.ofMinutes(rule.getPriorNoticeDurationMax());
return resolveNoticePeriod(rule.getPriorNoticeDurationMax());
}

@Nullable
private static Duration resolveNoticePeriod(int minutes) {
if (minutes == BookingRule.NO_VALUE) {
return null;
}
return Duration.ofMinutes(minutes);
}

private String message(BookingRule rule) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.opentripplanner.gtfs.mapping;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.onebusaway.gtfs.model.BookingRule.NO_VALUE;

import java.time.Duration;
import java.time.LocalTime;
Expand All @@ -20,7 +22,7 @@ void mapNullIsNull() {

@Test
void mapContactInfoAndMessages() {
var rule = rule("A", "1");
var rule = rule("1");
rule.setPhoneNumber("123");
rule.setInfoUrl("https://info");
rule.setUrl("https://book");
Expand All @@ -37,11 +39,16 @@ void mapContactInfoAndMessages() {
assertEquals("msg", mapped.getMessage());
assertEquals("pmsg", mapped.getPickupMessage());
assertEquals("dmsg", mapped.getDropOffMessage());

assertNull(mapped.getLatestBookingTime());
assertNull(mapped.getLatestBookingTime());
assertThat(mapped.getMinimumBookingNotice()).isEmpty();
assertThat(mapped.getMaximumBookingNotice()).isEmpty();
}

@Test
void mapEarliestAndLatestBookingTime() {
var rule = rule("A", "2");
var rule = rule("2");
// earliest: 10:00, 1 day prior
rule.setPriorNoticeStartTime(LocalTime.of(10, 0).toSecondOfDay());
rule.setPriorNoticeStartDay(1);
Expand Down Expand Up @@ -70,12 +77,12 @@ void mapEarliestAndLatestBookingTime() {

@Test
void mapNoEarliestOrLatestFallsBackToMinMaxNotice() {
var rule = rule("A", "3");
// when both prior notice time and day are set to 0, they should be treated as "not set".
rule.setPriorNoticeStartTime(0);
rule.setPriorNoticeStartDay(0);
rule.setPriorNoticeLastTime(0);
rule.setPriorNoticeLastDay(0);
var rule = rule("3");
// when either of prior notice time and day are set to -999(NO_VALUE), they should be treated as "not set".
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// when either of prior notice time and day are set to -999(NO_VALUE), they should be treated as "not set".
// when either of prior notice time and day are set to -999 (NO_VALUE), they should be treated as "not set".

rule.setPriorNoticeStartTime(NO_VALUE);
rule.setPriorNoticeStartDay(NO_VALUE);
rule.setPriorNoticeLastTime(NO_VALUE);
rule.setPriorNoticeLastDay(NO_VALUE);

rule.setPriorNoticeDurationMin(45);
rule.setPriorNoticeDurationMax(120);
Expand All @@ -89,15 +96,28 @@ void mapNoEarliestOrLatestFallsBackToMinMaxNotice() {

@Test
void mapCacheReturnsSameInstanceForSameRule() {
var rule = rule("A", "4");
var rule = rule("4");
var r1 = subject.map(rule);
var r2 = subject.map(rule);
assertSame(r1, r2);
}

private static BookingRule rule(String agency, String id) {
@Test
void acceptZeroAsMidnight() {
var rule = rule("5");
rule.setPriorNoticeStartTime(0);
rule.setPriorNoticeStartDay(10);
rule.setPriorNoticeLastTime(0);
rule.setPriorNoticeLastDay(5);

var mapped = subject.map(rule);
assertEquals("00:00-10d", mapped.getEarliestBookingTime().toString());
assertEquals("00:00-5d", mapped.getLatestBookingTime().toString());
}

private static BookingRule rule(String id) {
var r = new BookingRule();
r.setId(new AgencyAndId(agency, id));
r.setId(new AgencyAndId("A", id));
return r;
}
}
Loading