I have a date, and I want to see if that date is further/less than 1 year away from today. For example, the the date is 13th May 2017, it would return true, if it was 13th May 2018, it would return false.
The bug at the moment in my code is that it would return true for December 2014 (which should return false).
Any ideas?
private boolean checkIfDateIsInRange() {
Calendar today = DateTimeHelper.dateToCalendar(new Date());
if (currentDate.get(Calendar.YEAR) > today.get(Calendar.YEAR) + 1 || currentDate.get(Calendar.YEAR) < today.get(Calendar.YEAR) - 1){
return false;
}
return true;
}
The dateToCalendar method is as follows:
public static Calendar dateToCalendar(Date date){
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal;
}