public String datesBetween (int startDay, int startMonth, int startYear, int endDay, int endMonth, int endYear) {
int month = startMonth;
int day = startDay;
int year = startYear; // start on the first day
String returnString = ""; // start with an empty list
while (nextDay(day, month, year, endDay, endMonth, endYear)){ // while the date is not yet the end date
returnString += day + "-" + month + "-" + year + "\n"; // add the date to the string being returned
}
return returnString; // return the string
}
public int dayMax(int month, int year) {
switch (month) {
case 1: case 3: case 5: case 7: case 8: case 10: case 12: {
return 31; // these months have 31 days
}
case 4: case 6: case 9: case 11: {
return 30; // these months have 30 days
}
case 2: {
return 28 + ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? 1 : 0;
// February has 28 plus an extra day if it's a leap year (divisible by 4 but not by 100, or divisible by 400)
}
}
}
public boolean nextDay(int day, int month, int year, int endDay, int endMonth, int endYear){
day++; // adds 1 to the day
if (day > dayMax(month, year)) {
month++;
day = 1; // if day too high, add 1 to month and reset day to 1
}
if (month > 12) {
year++;
month = 1; // if month too high, add 1 to year and reset month
}
return year < endYear || (year == endYear && month < endMonth) || (year == endYear && month == endMonth && day < endDay);
}