-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add an argument for the cli (--date) that specifies the date to use during verification. #1628
feat: Add an argument for the cli (--date) that specifies the date to use during verification. #1628
Changes from 8 commits
44588f7
4b33022
9b08cc1
945a2d2
48d7014
b3d4148
86e7a9f
5f481fa
56568e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -25,10 +25,9 @@ | |||
import java.nio.charset.StandardCharsets; | ||||
import java.nio.file.Files; | ||||
import java.nio.file.Paths; | ||||
import java.text.SimpleDateFormat; | ||||
import java.time.Duration; | ||||
import java.time.LocalDate; | ||||
import java.util.Date; | ||||
import java.time.ZonedDateTime; | ||||
import java.time.format.DateTimeFormatter; | ||||
import java.util.List; | ||||
import java.util.stream.Collectors; | ||||
import org.mobilitydata.gtfsvalidator.input.DateForValidation; | ||||
|
@@ -120,7 +119,7 @@ public Status run(ValidationRunnerConfig config) { | |||
ValidationContext validationContext = | ||||
ValidationContext.builder() | ||||
.setCountryCode(config.countryCode()) | ||||
.setDateForValidation(new DateForValidation(LocalDate.now())) | ||||
.setDateForValidation(new DateForValidation(config.dateForValidation())) | ||||
.build(); | ||||
try { | ||||
feedContainer = | ||||
|
@@ -267,9 +266,9 @@ public static void exportReport( | |||
"Error creating output directory: %s", config.outputDirectory()); | ||||
} | ||||
} | ||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); | ||||
Date now = new Date(System.currentTimeMillis()); | ||||
String date = formatter.format(now); | ||||
ZonedDateTime now = ZonedDateTime.now(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. There have always been two times at play: the time used for validation and the time indicated in the report. In the current code (before this PR), only the report generation time is included in the output. Note that this part of the code is a refactor. The existing code uses System.currentTimeMillis() while the new code uses ZonedDateTime.now(). In either case, this time included in the report is the time that the report is generated (after validation steps have been done). The time used for validation is set at the start of processing if the new --date option isn't used. In that common case the two times differ by the processing time, which could be a fraction of a second or could be many minutes for large feeds (maybe even hours? I don't know how long the biggest feeds take). That was already true and remains true. A difference now is that both times are included in the JSON report, and both are included in the HTML report if the date differs. I'm open to changing any of that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the clarification. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I misunderstood your original question. Date and time handling is confusing. The computation of is_different_date converts both ZonedDateTime variables to LocalDate before comparing. It's looking to see if the date (not the time part) is different. In the common case that --date is not specified and the validation run completes on the same calendar date as it starts, is_different_date will be false and the HTML report will not have anything added. As you say, the date+time will always be different, but that isn't what is checked. My goal was to be conservative about changing the human-readable HTML output (although I'm open-minded). Part of why this is confusing is that I called the argument --date, but you must specify a time as well, so it's really a date+time. I have a suggestion to reduce the confusion: Refactor the code by replacing "currentDateTime" in ValidationContext with a LocalDate (no time). Currently the type is a ZonedDateTime, which is why I used that type in this PR and require that a time be specified along with a date. But I checked the uses of the ValidationContext, and the rules all convert to LocalDate when using currentDateTime anyway. (example: gtfs-validator/main/src/main/java/org/mobilitydata/gtfsvalidator/validator/DateTripsValidator.java Line 76 in 3d5ef6f
I'll create a PR with that refactor so you see what I mean. It won't change the current functionality at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I missed that the comparison was based only on the date. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just created PR #1636, a refactor to simplify and clarify the existing date handling. I'll wait to see if that is accepted and merged. If so, it will simplify this PR. |
||||
String date = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd 'at' HH:mm:ss z")); | ||||
boolean is_different_date = !now.toLocalDate().equals(config.dateForValidation()); | ||||
|
||||
Gson gson = createGson(config.prettyJson()); | ||||
HtmlReportGenerator htmlGenerator = new HtmlReportGenerator(); | ||||
|
@@ -291,7 +290,8 @@ public static void exportReport( | |||
config, | ||||
versionInfo, | ||||
config.outputDirectory().resolve(config.htmlReportFileName()), | ||||
date); | ||||
date, | ||||
is_different_date); | ||||
Files.write( | ||||
config.outputDirectory().resolve(config.systemErrorsReportFileName()), | ||||
gson.toJson(noticeContainer.exportSystemErrors()).getBytes(StandardCharsets.UTF_8)); | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bradyhunsaker It's a bit late, but I was wondering about this sentence. I don't see where these debugging rules are enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear. I meant that the main purpose of this option is debugging. For example, it could be used to debug an error with a rule like feed expiration.
There are not special debugging rules associated with it.
I think the use of the word "enables" was a bad choice. Feel free to remove or edit the description.