Align formatting with article

This commit is contained in:
Maiklins 2023-12-19 22:26:33 +01:00 committed by GitHub
parent c35c13d5d8
commit 65e23af90e
1 changed files with 10 additions and 3 deletions

View File

@ -9,12 +9,15 @@ public class MonthInterval {
if (startDate == null || endDate == null) {
throw new IllegalArgumentException("Both startDate and endDate must be provided");
}
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(startDate);
int startDateTotalMonths = 12 * startCalendar.get(Calendar.YEAR) + startCalendar.get(Calendar.MONTH);
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(endDate);
int endDateTotalMonths = 12 * endCalendar.get(Calendar.YEAR) + endCalendar.get(Calendar.MONTH);
return endDateTotalMonths - startDateTotalMonths;
}
@ -22,16 +25,20 @@ public class MonthInterval {
if (startDate == null || endDate == null) {
throw new IllegalArgumentException("Both startDate and endDate must be provided");
}
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(startDate);
int startDayOfMonth = startCalendar.get(Calendar.DAY_OF_MONTH);
int startDateDayOfMonth = startCalendar.get(Calendar.DAY_OF_MONTH);
int startDateTotalMonths = 12 * startCalendar.get(Calendar.YEAR) + startCalendar.get(Calendar.MONTH);
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(endDate);
int endDayOfMonth = endCalendar.get(Calendar.DAY_OF_MONTH);
int endDateDayOfMonth = endCalendar.get(Calendar.DAY_OF_MONTH);
int endDateTotalMonths = 12 * endCalendar.get(Calendar.YEAR) + endCalendar.get(Calendar.MONTH);
return (startDayOfMonth > endDayOfMonth) ? (endDateTotalMonths - startDateTotalMonths) - 1 : (endDateTotalMonths - startDateTotalMonths);
return (startDateDayOfMonth > endDateDayOfMonth) ? (endDateTotalMonths - startDateTotalMonths) - 1 : (endDateTotalMonths - startDateTotalMonths);
}
}