skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Friday, October 5, 2012

Finding out the Next Business Date of the Client for business purposes

Posted by Raju Gupta at 11:30 PM – 0 comments
 
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.

 public static Date findNextBusinessDate(Date inputDate,ArrayList holidayDates)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;
 }

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger