I'm trying to create a program which takes two dates as arguments, and returns whether the dates are in the current week or not, but I am having an issue with the call to isDateInCurrentWeek
. When I try to compile the program, I receive an error saying
requestHoliday.java:16: isDateInCurrentWeek(java.util.GregorianCalendar) in requestHoliday cannot be applied to (java.util.Calendar)
if (isDateInCurrentWeek(startDate) && isDateInCurrentWeek(endDate));
.
import java.util.*;
import java.text.*;
public class hols {
public static void main( String[] args ) {
DateFormat df = new SimpleDateFormat("dd MM yyyy");
Date start = df.parse(args[0]);
Date end = df.parse(args[1]);
Calendar startDate = new GregorianCalendar();
Calendar endDate = new GregorianCalendar();
startDate.setTime(start);
endDate.setTime(end);
if( isDateInCurrentWeek( startDate ) && isDateInCurrentWeek( endDate ));
System.out.println( "Date is in current week!" );
}
public static boolean isDateInCurrentWeek(GregorianCalendar date) {
Calendar currentCalendar = GregorianCalendar.getInstance();
int week = currentCalendar.get(Calendar.WEEK_OF_YEAR);
int year = currentCalendar.get(Calendar.YEAR);
Calendar targetCalendar = GregorianCalendar.getInstance();
targetCalendar = date;
int targetWeek = targetCalendar.get(Calendar.WEEK_OF_YEAR);
int targetYear = targetCalendar.get(Calendar.YEAR);
return week == targetWeek && year == targetYear;
}
}
Not too sure what the issue is, as the method takes a Gregoriancalendar as input, and the two dates are in Gregorian Calendar format. Anybody know?