I am comparing the start Date of a treatement to its End to check if it lasts more than 6 months. If the period doesn't include the month of February all is good but if I compare the 1st of January to the 30th of June, it throws my Exception. To compare both periods I add 6 months to the start Date and compare the result to the end Date like so:
Date start = new Date(2017,1,1);
Date end = new Date(2017,6,30);
Calendar startOfTreatment = new Calendar.getInstance();
startOfTreatment.setTime(start);
Calendar endOfTreatment = new Calendar.getInstance();
endOfTreatment.setTime(end);
startOfTreatment.add(Calendar.MONTH, 6);
if (startOfTreatment.compareTo(endOfTreatment) > 0) {
throw new InfinishedTreatmentException(startOfTreatment,endOfTreatment);
}
How can I fix this?