Skip to content

Commit

Permalink
split year input into either a range or a single year
Browse files Browse the repository at this point in the history
  • Loading branch information
Jatie1 committed Feb 14, 2022
1 parent 047880b commit cc7161d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/main/java/com/jatie/BeatmapDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,26 @@ public static boolean enterRankedStatusPreference(String status) {
public static String[] enterYearRange() {
while (true) {
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
System.out.println("Enter the year range you want to begin fetching beatmaps from (between 2007 to " + currentYear + " in the format 'YYYY-YYYY')");
System.out.print("EG: '2013-2020' will fetch all beatmaps between 2013 and 2020: ");
System.out.println("Enter either a single year or a year range you want to begin fetching beatmaps from (between 2007 to " + currentYear + " in the format 'YYYY' for single year and 'YYYY-YYYY' for a range)");
System.out.print("EG: '2019' will fetch all beatmaps from 2019 and '2013-2020' will fetch all beatmaps between 2013 and 2020: ");
String yearRange = SCANNER.nextLine();
if (yearRange.matches("[\\d]{4}-[\\d]{4}")) {
if (yearRange.matches("[\\d]{4}-[\\d]{4}")) { // Range
String[] yearRangeSplit = yearRange.split("-");
int yearStart = Integer.parseInt(yearRangeSplit[0]);
int yearEnd = Integer.parseInt(yearRangeSplit[1]);
if (yearStart >= 2007 && yearEnd <= currentYear && yearEnd >= yearStart) {
yearRangeSplit[0] += "-01-01";
yearRangeSplit[1] = Integer.toString(yearEnd + 1);
return yearRangeSplit;
if (yearStart >= 2007 && yearEnd <= currentYear && yearEnd > yearStart) {
System.out.print("\n");
return new String[]{yearRangeSplit[0] + "-01-01", Integer.toString(yearEnd + 1)};
}
}
System.out.println("Year range entered is invalid!");
else if (yearRange.matches("[\\d]{4}")) { // Single year
int year = Integer.parseInt(yearRange);
if (year >= 2007 && year <= currentYear) {
System.out.print("\n");
return new String[]{yearRange + "-01-01", Integer.toString(year + 1)};
}
}
System.out.println("\nYear input is invalid!");
}
}

Expand Down

0 comments on commit cc7161d

Please sign in to comment.