Skip to content
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

Move TimeUtil ParseException throwing to ArgsParser::parse method #1990

Closed
chan-j-d opened this issue Apr 10, 2023 · 0 comments · Fixed by #2075 · May be fixed by nseah21/RepoSense#1
Closed

Move TimeUtil ParseException throwing to ArgsParser::parse method #1990

chan-j-d opened this issue Apr 10, 2023 · 0 comments · Fixed by #2075 · May be fixed by nseah21/RepoSense#1

Comments

@chan-j-d
Copy link
Contributor

Currently, the methods verifyDatesRangeIsCorrect and verifySinceDateIsValid in the TimeUtil class are throwing ParseException which is a side effect that might not make sense when the methods are reused.

public static void verifyDatesRangeIsCorrect(LocalDateTime sinceDate, LocalDateTime untilDate)
throws ParseException {
if (sinceDate.compareTo(untilDate) > 0) {
throw new ParseException(MESSAGE_SINCE_DATE_LATER_THAN_UNTIL_DATE);
}
}
/**
* Verifies that {@code sinceDate} is no later than the date of report generation, given by {@code currentDate}.
*
* @throws ParseException if {@code sinceDate} supplied is later than date of report generation.
*/
public static void verifySinceDateIsValid(LocalDateTime sinceDate, LocalDateTime currentDate)
throws ParseException {
if (sinceDate.compareTo(currentDate) > 0) {
throw new ParseException(MESSAGE_SINCE_DATE_LATER_THAN_TODAY_DATE);
}
}

The exception thrown should be in the ArgsParser::parse method itself where they are used. Since these methods have been changed since when they were written to be a simple compareTo call, we can consider removing these methods and replacing the equivalent lines in ArgsParser::parse with the appropriate compareTo check and throw a ParseException if necessary.

@HCY123902 HCY123902 moved this to For contributors in RepoSense Roadmap Apr 12, 2023
chan-j-d pushed a commit that referenced this issue Dec 30, 2023
…thod (#2075)

ArgsParser::parse uses the methods verifyDatesRangeIsCorrect
and verifySinceDateIsValid from TimeUtil to throw a 
ParseException if either of the checks fail. The throwing 
of an exception in a utility method is a side effect
that makes the methods less reusable.

Let's move the throwing of ParseException from TimeUtil 
into ArgsParser.
@github-project-automation github-project-automation bot moved this from For contributors to Closed/Completed in RepoSense Roadmap Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Closed/Completed
1 participant