-
Notifications
You must be signed in to change notification settings - Fork 153
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
[#1774] Fix unintended behavior related to --since d1 #1776
Changes from 5 commits
f1a67ea
37812bb
fc4fd16
06383a3
52a5a1a
1c2f8c3
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 | ||||
---|---|---|---|---|---|---|
|
@@ -172,6 +172,7 @@ This flag overrides the `Ignore file size limit` field in the CSV config file. | |||||
<box type="info" seamless> | ||||||
|
||||||
* If both start date and end date are not specified, the date of generating the report will be taken as the end date. | ||||||
* May analyse the incorrect date range if used with `--since d1`. The program will throw a warning. | ||||||
* Cannot be used with both `--since` and `--until`. The program will throw an exception. | ||||||
</box> | ||||||
<!-- ------------------------------------------------------------------------------------------------------ --> | ||||||
|
@@ -216,7 +217,8 @@ Cannot be used with `--last-modified-date`. This may result in an incorrect last | |||||
<box type="info" seamless> | ||||||
|
||||||
* If the start date is not specified, only commits made one month before the end date (if specified) or the date of generating the report, will be captured and analyzed. | ||||||
* If `d1` is specified as the start date (`--since d1` or `-s d1`), then the earliest commit date of all repositories will be taken as the start date. | ||||||
* If `d1` is specified as the start date (`--since d1` or `-s d1`), then the program will search for the earliest commit date of all repositories and use that as the start date. | ||||||
* If `d1` is specified together with `--period`, then the program will warn that the date range being analysed may be incorrect. | ||||||
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.
Suggested change
|
||||||
</box> | ||||||
<!-- ------------------------------------------------------------------------------------------------------ --> | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,8 @@ public class ArgsParser { | |
"Config path not provided, using the config folder as default."; | ||
private static final String MESSAGE_INVALID_CONFIG_PATH = "%s is malformed."; | ||
private static final String MESSAGE_INVALID_CONFIG_JSON = "%s Ignoring the report config provided."; | ||
private static final String MESSAGE_SINCE_D1_WITH_PERIOD = "You may be using --since d1 with the --period flag. " | ||
+ "This may result in an incorrect date range being analysed."; | ||
private static final Path EMPTY_PATH = Paths.get(""); | ||
private static final Path DEFAULT_CONFIG_PATH = Paths.get(System.getProperty("user.dir") | ||
+ File.separator + "config" + File.separator); | ||
|
@@ -290,6 +292,13 @@ public static CliArguments parse(String[] args) throws HelpScreenException, Pars | |
|
||
if (isSinceDateProvided) { | ||
sinceDate = TimeUtil.getSinceDate(cliSinceDate.get()); | ||
// For --since d1, need to adjust the arbitrary date based on timezone | ||
if (TimeUtil.isEqualToArbitraryFirstDateUtc(sinceDate)) { | ||
if (isPeriodProvided) { | ||
logger.warning(MESSAGE_SINCE_D1_WITH_PERIOD); | ||
} | ||
sinceDate = TimeUtil.getArbitraryFirstCommitDateConverted(zoneId); | ||
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. The indentation for this part seems to be quite deep. Is there any way to flatten this? |
||
} | ||
} else { | ||
if (isUntilDateProvided) { | ||
sinceDate = isPeriodProvided | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.util.Optional; | ||
|
||
import net.sourceforge.argparse4j.inf.Argument; | ||
|
@@ -16,14 +17,17 @@ | |
public class SinceDateArgumentType extends DateArgumentType { | ||
/* | ||
* When user specifies "d1", arbitrary first commit date will be returned. | ||
* This date is equivalent to 1970-01-01 00:00:00 in UTC time. | ||
* Then, ReportGenerator will replace the arbitrary since date with the earliest commit date. | ||
*/ | ||
public static final LocalDateTime ARBITRARY_FIRST_COMMIT_DATE = LocalDateTime.ofInstant( | ||
Instant.ofEpochMilli(Long.MIN_VALUE), ZoneId.of("Z")); | ||
public static final String FIRST_COMMIT_DATE_SHORTHAND = "d1"; | ||
private static final ZonedDateTime ARBITRARY_FIRST_COMMIT_DATE = ZonedDateTime.ofInstant( | ||
Instant.ofEpochMilli(0), ZoneId.of("Z")); | ||
private static final LocalDateTime ARBITRARY_FIRST_COMMIT_DATE_UTC_LOCAL = ARBITRARY_FIRST_COMMIT_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. The variable naming seems a little confusing. May I suggest using |
||
.toLocalDateTime(); | ||
|
||
/** | ||
* Returns an arbitrary year {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE} if user specifies | ||
* Returns an arbitrary year {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE_UTC_LOCAL} if user specifies | ||
* {@link SinceDateArgumentType#FIRST_COMMIT_DATE_SHORTHAND} in {@code value}, or attempts to return the | ||
* desired date otherwise. | ||
* | ||
|
@@ -33,9 +37,25 @@ public class SinceDateArgumentType extends DateArgumentType { | |
public Optional<LocalDateTime> convert(ArgumentParser parser, Argument arg, String value) | ||
throws ArgumentParserException { | ||
if (FIRST_COMMIT_DATE_SHORTHAND.equals(value)) { | ||
return Optional.of(ARBITRARY_FIRST_COMMIT_DATE); | ||
return Optional.of(ARBITRARY_FIRST_COMMIT_DATE_UTC_LOCAL); | ||
} | ||
String sinceDate = TimeUtil.extractDate(value); | ||
return super.convert(parser, arg, sinceDate + " 00:00:00"); | ||
} | ||
|
||
/** | ||
* Returns the {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE_UTC_LOCAL}, which is the | ||
* {@link LocalDateTime} of {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE}. | ||
*/ | ||
public static LocalDateTime getArbitraryFirstCommitDateUtcLocal() { | ||
return ARBITRARY_FIRST_COMMIT_DATE_UTC_LOCAL; | ||
} | ||
|
||
/** | ||
* Returns the {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE} adjusted for the time zone based on | ||
* {@code toZoneId} and converted to a {@link LocalDateTime} object. | ||
*/ | ||
public static LocalDateTime getArbitraryFirstCommitDateConverted(ZoneId toZoneId) { | ||
return ARBITRARY_FIRST_COMMIT_DATE.withZoneSameInstant(toZoneId).toLocalDateTime(); | ||
} | ||
} |
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.