diff --git a/cli/src/main/java/org/mobilitydata/gtfsvalidator/cli/Arguments.java b/cli/src/main/java/org/mobilitydata/gtfsvalidator/cli/Arguments.java
index d7dda065c0..d79bfbfeeb 100644
--- a/cli/src/main/java/org/mobilitydata/gtfsvalidator/cli/Arguments.java
+++ b/cli/src/main/java/org/mobilitydata/gtfsvalidator/cli/Arguments.java
@@ -21,6 +21,8 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
import org.mobilitydata.gtfsvalidator.input.CountryCode;
import org.mobilitydata.gtfsvalidator.runner.ValidationRunnerConfig;
@@ -52,6 +54,14 @@ public class Arguments {
+ "It must be a two-letter country code (ISO 3166-1 alpha-2)")
private String countryCode;
+ @Parameter(
+ names = {"-d", "--date"},
+ description =
+ "Date to simulate when validating, in ISO_LOCAL_DATE format like "
+ + "'2001-01-30'. By default, the current date is used. "
+ + "This option enables debugging rules like feed expiration.")
+ private String dateString;
+
@Parameter(
names = {"-u", "--url"},
description = "Fully qualified URL to download GTFS archive")
@@ -111,6 +121,9 @@ ValidationRunnerConfig toConfig() throws URISyntaxException {
if (countryCode != null) {
builder.setCountryCode(CountryCode.forStringOrUnknown(countryCode));
}
+ if (dateString != null) {
+ builder.setDateForValidation(LocalDate.parse(dateString, DateTimeFormatter.ISO_LOCAL_DATE));
+ }
if (validationReportName != null) {
builder.setValidationReportFileName(validationReportName);
}
diff --git a/cli/src/test/java/org/mobilitydata/gtfsvalidator/cli/ArgumentsTest.java b/cli/src/test/java/org/mobilitydata/gtfsvalidator/cli/ArgumentsTest.java
index 795215c72a..4cba280185 100644
--- a/cli/src/test/java/org/mobilitydata/gtfsvalidator/cli/ArgumentsTest.java
+++ b/cli/src/test/java/org/mobilitydata/gtfsvalidator/cli/ArgumentsTest.java
@@ -87,7 +87,8 @@ public void longNameShouldInitializeArguments() throws URISyntaxException {
"--input", "/tmp/gtfs.zip",
"--output_base", "/tmp/output",
"--country_code", "ca",
- "--threads", "4"
+ "--threads", "4",
+ "--date", "2020-01-02"
};
Arguments underTest = new Arguments();
@@ -100,6 +101,7 @@ public void longNameShouldInitializeArguments() throws URISyntaxException {
assertThat(config.validationReportFileName()).matches("report.json");
assertThat(config.htmlReportFileName()).matches("report.html");
assertThat(config.systemErrorsReportFileName()).matches("system_errors.json");
+ assertThat(config.dateForValidation().toString()).matches("2020-01-02");
}
@Test
diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/report/HtmlReportGenerator.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/report/HtmlReportGenerator.java
index 0cdef7acf4..3d72409b8a 100644
--- a/main/src/main/java/org/mobilitydata/gtfsvalidator/report/HtmlReportGenerator.java
+++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/report/HtmlReportGenerator.java
@@ -39,7 +39,8 @@ public void generateReport(
ValidationRunnerConfig config,
VersionInfo versionInfo,
Path reportPath,
- String date)
+ String date,
+ boolean is_different_date)
throws IOException {
TemplateEngine templateEngine = new TemplateEngine();
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
@@ -54,6 +55,7 @@ public void generateReport(
context.setVariable("summary", summary);
context.setVariable("config", config);
context.setVariable("date", date);
+ context.setVariable("is_different_date", is_different_date);
try (FileWriter writer = new FileWriter(reportPath.toFile())) {
templateEngine.process("report.html", context, writer);
diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/report/JsonReportSummary.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/report/JsonReportSummary.java
index 8ee69ae308..08470a1ca3 100644
--- a/main/src/main/java/org/mobilitydata/gtfsvalidator/report/JsonReportSummary.java
+++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/report/JsonReportSummary.java
@@ -29,6 +29,7 @@ public class JsonReportSummary {
private String validationReportName;
private String htmlReportName;
private String countryCode;
+ private String dateForValidation;
private JsonReportFeedInfo feedInfo;
private ListGTFS Schedule Validation Report
+
Use this report alongside our documentation.
diff --git a/main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/JsonReportSummaryTest.java b/main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/JsonReportSummaryTest.java index c9587c34d7..0c6fedea7d 100644 --- a/main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/JsonReportSummaryTest.java +++ b/main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/JsonReportSummaryTest.java @@ -9,6 +9,7 @@ import com.google.gson.JsonParser; import java.net.URI; import java.nio.file.Path; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Arrays; import java.util.Map; @@ -41,6 +42,7 @@ private static ValidationRunnerConfig generateValidationRunnerConfig() throws Ex builder.setPrettyJson(true); builder.setSystemErrorsReportFileName("some_error_filename"); builder.setValidationReportFileName("some_report_filename"); + builder.setDateForValidation(LocalDate.parse("2020-01-02")); return builder.build(); } @@ -91,7 +93,8 @@ public void noFeedMetadataWithConfigTest() throws Exception { + "\"systemErrorsReportName\":\"some_error_filename\"," + "\"validationReportName\":\"some_report_filename\"," + "\"htmlReportName\":\"some_html_filename\"," - + "\"countryCode\":\"GB\"}"; + + "\"countryCode\":\"GB\"," + + "\"dateForValidation\":\"2020-01-02\"}"; assertEquals(JsonParser.parseString(expected), gson.toJsonTree(reportSummary)); } @@ -113,6 +116,7 @@ public void withFeedMetadataWithConfigTest() throws Exception { + "\"validationReportName\":\"some_report_filename\"," + "\"htmlReportName\":\"some_html_filename\"," + "\"countryCode\":\"GB\"," + + "\"dateForValidation\":\"2020-01-02\"," + "\"feedInfo\":{\"publisherName\":\"value1\",\"publisherUrl\":\"value2\"}," + "\"agencies\":[" + "{\"name\":\"agency1\",\"url\":\"some URL 1\",\"phone\":\"phone1\",\"email\":\"email1\"},"