diff --git a/src/main/java/com/jatie/BeatmapDownloader.java b/src/main/java/com/jatie/BeatmapDownloader.java index f4b4d48..9fbfd9d 100644 --- a/src/main/java/com/jatie/BeatmapDownloader.java +++ b/src/main/java/com/jatie/BeatmapDownloader.java @@ -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!"); } }