The solution is as follows:
Method Name : findNextBusinessDate(Date,ArrayList<Date>)
Parameters
a) Date for which the next business date has to be identified.
b) The arraylist of holiday dates of the client retrieved from the Holiday Lookup tables of database.
How it works?
a) Input date is checked for the Holiday date.If it is a holiday we increment the date by one and move it to the next day.That next day is checked for the Saturday/Sunday and also the new date is checked for the Holiday.If it is not an holiday/weekend then that date is considered to be the next business date.And this value will be returned back.
b) If the input date itself is a valid business date, then the same date will be returned.
Method Name : findNextBusinessDate(Date,ArrayList<Date>)
Parameters
a) Date for which the next business date has to be identified.
b) The arraylist of holiday dates of the client retrieved from the Holiday Lookup tables of database.
How it works?
a) Input date is checked for the Holiday date.If it is a holiday we increment the date by one and move it to the next day.That next day is checked for the Saturday/Sunday and also the new date is checked for the Holiday.If it is not an holiday/weekend then that date is considered to be the next business date.And this value will be returned back.
b) If the input date itself is a valid business date, then the same date will be returned.
public static Date findNextBusinessDate(Date inputDate,ArrayListholidayDates)throws Exception{ Date nextBusinessDate=null; boolean flag = true; try { Calendar inputCalendar = Calendar.getInstance(); int dayOfWeek = inputCalendar.get(Calendar.DAY_OF_WEEK); while(flag) { //Condition for checking the holiday from the CLIENT_HOLIDAY table if(holidayDates.contains(inputDate)){ inputCalendar.add(Calendar.DATE,1); dayOfWeek = inputCalendar.get(Calendar.DAY_OF_WEEK); } //If the current day is Saturday, the next business day is two days away,so add two days. if((dayOfWeek == 7)) { inputCalendar.add(Calendar.DATE,2); dayOfWeek = inputCalendar.get(Calendar.DAY_OF_WEEK); } //If the current day is Sunday, the next business day is one day away,so add one day. if((dayOfWeek == 1)) { inputCalendar.add(Calendar.DATE,1); dayOfWeek = inputCalendar.get(Calendar.DAY_OF_WEEK); } if((holidayDates.contains(inputCalendar.getTime()) && (dayOfWeek != 1) && (dayOfWeek != 7))) { nextBusinessDate=inputCalendar.getTime(); flag = false; } } }catch (Exception e){ CfLogWriter.debug("ERROR OCCURED findNextBusinessDate "); e.printStackTrace(); throw e; } return nextBusinessDate; }