Skip to content

Commit 13b6b2f

Browse files
authored
fix: Changed 7 and 30 day notices so the feedEndDate and suggestedEndDate are different (#2125)
1 parent f65221e commit 13b6b2f

4 files changed

Lines changed: 54 additions & 38 deletions

File tree

core/src/main/java/org/mobilitydata/gtfsvalidator/type/GtfsDate.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public static GtfsDate fromEpochDay(long epochDay) {
3535
return new GtfsDate(LocalDate.ofEpochDay(epochDay));
3636
}
3737

38+
public GtfsDate plusDays(long days) {
39+
return new GtfsDate(localDate.plusDays(days));
40+
}
41+
3842
/**
3943
* Parses date from string in {@code YYYYMMDD} format.
4044
*

core/src/test/java/org/mobilitydata/gtfsvalidator/type/GtfsDateTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,24 @@ public void toYYYYMMDD() {
8484
assertThat(GtfsDate.fromString("20210301").toYYYYMMDD()).isEqualTo("20210301");
8585
assertThat(GtfsDate.fromString("20210301").toString()).isEqualTo("20210301");
8686
}
87+
88+
@Test
89+
public void plusDays_addsPositiveOffset() {
90+
GtfsDate base = GtfsDate.fromString("20260304");
91+
// 30 days after 2026-03-04 is 2026-04-03
92+
assertThat(base.plusDays(30).toYYYYMMDD()).isEqualTo("20260403");
93+
}
94+
95+
@Test
96+
public void plusDays_withZeroDaysReturnsSameDate() {
97+
GtfsDate base = GtfsDate.fromString("20260304");
98+
assertThat(base.plusDays(0).toYYYYMMDD()).isEqualTo("20260304");
99+
}
100+
101+
@Test
102+
public void plusDays_supportsNegativeOffset() {
103+
GtfsDate base = GtfsDate.fromString("20260304");
104+
// 1 day before 2026-03-04 is 2026-03-03
105+
assertThat(base.plusDays(-1).toYYYYMMDD()).isEqualTo("20260303");
106+
}
87107
}

main/src/main/java/org/mobilitydata/gtfsvalidator/validator/FeedExpirationDateValidator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ public class FeedExpirationDateValidator extends SingleEntityValidator<GtfsFeedI
5656
public void validate(GtfsFeedInfo entity, NoticeContainer noticeContainer) {
5757
if (entity.hasFeedEndDate()) {
5858
GtfsDate currentDate = GtfsDate.fromLocalDate(dateForValidation.getDate());
59-
GtfsDate currentDatePlusSevenDays =
60-
GtfsDate.fromLocalDate(dateForValidation.getDate().plusDays(7));
61-
GtfsDate currentDatePlusThirtyDays =
62-
GtfsDate.fromLocalDate(dateForValidation.getDate().plusDays(30));
63-
if (entity.feedEndDate().compareTo(currentDatePlusSevenDays) <= 0) {
59+
GtfsDate currentDatePlusSevenDays = currentDate.plusDays(7);
60+
GtfsDate currentDatePlusThirtyDays = currentDate.plusDays(30);
61+
// Last day of the period is not included for issuing the notice.
62+
if (entity.feedEndDate().compareTo(currentDatePlusSevenDays) < 0) {
6463
noticeContainer.addValidationNotice(
6564
new FeedExpirationDate7DaysNotice(
6665
entity.csvRowNumber(),
@@ -69,7 +68,8 @@ public void validate(GtfsFeedInfo entity, NoticeContainer noticeContainer) {
6968
currentDatePlusSevenDays));
7069
return;
7170
}
72-
if (entity.feedEndDate().compareTo(currentDatePlusThirtyDays) <= 0) {
71+
// Last day of the period is not included for issuing the notice.
72+
if (entity.feedEndDate().compareTo(currentDatePlusThirtyDays) < 0) {
7373
noticeContainer.addValidationNotice(
7474
new FeedExpirationDate30DaysNotice(
7575
entity.csvRowNumber(),

main/src/test/java/org/mobilitydata/gtfsvalidator/validator/FeedExpirationDateValidatorTest.java

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
import org.mobilitydata.gtfsvalidator.validator.FeedExpirationDateValidator.FeedExpirationDate7DaysNotice;
3232

3333
public class FeedExpirationDateValidatorTest {
34-
private static final LocalDate TEST_NOW = LocalDate.of(2021, 1, 1);
34+
// Use a date in later in the month to test the rollover from month to month also.
35+
private static final GtfsDate TEST_NOW = GtfsDate.fromLocalDate(LocalDate.of(2021, 1, 25));
3536

3637
private List<ValidationNotice> validateFeedInfo(GtfsFeedInfo feedInfo) {
3738
NoticeContainer container = new NoticeContainer();
38-
new FeedExpirationDateValidator(new DateForValidation(TEST_NOW)).validate(feedInfo, container);
39+
new FeedExpirationDateValidator(new DateForValidation(TEST_NOW.getLocalDate()))
40+
.validate(feedInfo, container);
3941
return container.getValidationNotices();
4042
}
4143

@@ -50,52 +52,42 @@ private GtfsFeedInfo createFeedInfo(GtfsDate feedEndDate) {
5052
}
5153

5254
@Test
53-
public void feedExpiringInFiveDaysFromNowShouldGenerateNotice() {
54-
assertThat(validateFeedInfo(createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.plusDays(3)))))
55+
public void feedExpiringInSixDaysFromNowShouldGenerate7DaysNotice() {
56+
List<ValidationNotice> notices = validateFeedInfo(createFeedInfo(TEST_NOW.plusDays(6)));
57+
assertThat(notices)
5558
.containsExactly(
5659
new FeedExpirationDate7DaysNotice(
57-
1,
58-
GtfsDate.fromLocalDate(TEST_NOW),
59-
GtfsDate.fromLocalDate(TEST_NOW.plusDays(3)),
60-
GtfsDate.fromLocalDate(TEST_NOW.plusDays(7))));
60+
1, TEST_NOW, TEST_NOW.plusDays(6), TEST_NOW.plusDays(7)));
6161
}
6262

6363
@Test
64-
public void feedExpiringInSevenDaysFromNowShouldGenerateNotice() {
65-
assertThat(validateFeedInfo(createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.plusDays(7)))))
64+
public void feedExpiringInSevenDaysFromNowShouldGenerate30DaysNotice() {
65+
List<ValidationNotice> notices = validateFeedInfo(createFeedInfo(TEST_NOW.plusDays(7)));
66+
assertThat(notices)
6667
.containsExactly(
67-
new FeedExpirationDate7DaysNotice(
68-
1,
69-
GtfsDate.fromLocalDate(TEST_NOW),
70-
GtfsDate.fromLocalDate(TEST_NOW.plusDays(7)),
71-
GtfsDate.fromLocalDate(TEST_NOW.plusDays(7))));
68+
new FeedExpirationDate30DaysNotice(
69+
1, TEST_NOW, TEST_NOW.plusDays(7), TEST_NOW.plusDays(30)));
7270
}
7371

7472
@Test
75-
public void feedExpiring7to30DaysFromNowShouldGenerateNotice() {
76-
assertThat(validateFeedInfo(createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.plusDays(23)))))
73+
public void feedExpiring7to30DaysFromNowShouldGenerate30DaysNotice() {
74+
assertThat(validateFeedInfo(createFeedInfo(TEST_NOW.plusDays(29))))
7775
.containsExactly(
7876
new FeedExpirationDate30DaysNotice(
79-
1,
80-
GtfsDate.fromLocalDate(TEST_NOW),
81-
GtfsDate.fromLocalDate(TEST_NOW.plusDays(23)),
82-
GtfsDate.fromLocalDate(TEST_NOW.plusDays(30))));
77+
1, TEST_NOW, TEST_NOW.plusDays(29), TEST_NOW.plusDays(30)));
8378
}
8479

8580
@Test
86-
public void feedExpiring30DaysFromNowShouldGenerateNotice() {
87-
assertThat(validateFeedInfo(createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.plusDays(30)))))
88-
.containsExactly(
89-
new FeedExpirationDate30DaysNotice(
90-
1,
91-
GtfsDate.fromLocalDate(TEST_NOW),
92-
GtfsDate.fromLocalDate(TEST_NOW.plusDays(30)),
93-
GtfsDate.fromLocalDate(TEST_NOW.plusDays(30))));
81+
public void feedExpiring30DaysFromNowShouldNotGenerateNotice() {
82+
assertThat(validateFeedInfo(createFeedInfo(TEST_NOW.plusDays(30)))).isEmpty();
9483
}
9584

9685
@Test
97-
public void feedExpiringInMoreThan30DaysFromNowShouldNotGenerateNotice() {
98-
assertThat(validateFeedInfo(createFeedInfo(GtfsDate.fromLocalDate(TEST_NOW.plusDays(45)))))
99-
.isEmpty();
86+
public void feedExpiringInThePastShouldGenerate7DaysNotice() {
87+
List<ValidationNotice> notices = validateFeedInfo(createFeedInfo(TEST_NOW.plusDays(-1)));
88+
assertThat(notices)
89+
.containsExactly(
90+
new FeedExpirationDate7DaysNotice(
91+
1, TEST_NOW, TEST_NOW.plusDays(-1), TEST_NOW.plusDays(7)));
10092
}
10193
}

0 commit comments

Comments
 (0)