Just take a quick look at the calendar:
Note. Make sure thatimport java.util.GregorianCalendar;
public static boolean isDateInRange(int month, int day,
int monthFrom, int dayFrom,
int monthUntil, int dayUntil) {
int yearRoll = 0;
int currentRoll = 0;
if (monthUntil < monthFrom) yearRoll = -1;
if (month >= monthFrom && yearRoll < 0) currentRoll = -1;
GregorianCalendar testDate = new GregorianCalendar(currentRoll, month, day);
GregorianCalendar startDate = new GregorianCalendar(yearRoll, monthFrom, dayFrom);
GregorianCalendar endDate = new GregorianCalendar(0, monthUntil, dayUntil);
if (testDate.compareTo(startDate) == 0 || testDate.compareTo(endDate) == 0) {
return true;
}
return !(testDate.before(startDate) || testDate.after(endDate));
}
, - . , from
, .
, . , . :
public static boolean isDateInRange(int year, int month, int day,
int yearFrom, int monthFrom, int dayFrom,
int yearUntil, int monthUntil, int dayUntil) {
GregorianCalendar testDate = new GregorianCalendar(year, month, day);
GregorianCalendar startDate = new GregorianCalendar(yearFrom, monthFrom, dayFrom);
GregorianCalendar endDate = new GregorianCalendar(yearUntil, monthUntil, dayUntil);
return !(testDate.before(startDate) || testDate.after(endDate));
}
, , :
public static void main(String[] args) {
System.out.println(isDateInRange(1, 2,
11, 24,
3, 3));
System.out.println(isDateInRange(11, 25,
11, 24,
3, 3));
System.out.println(isDateInRange(1, 2,
1, 1,
3, 3));
System.out.println(isDateInRange(1, 22,
1, 21,
1, 25));
}
:
true
true
true
true
@Marvin.