you can customise this code as per your requirement
if u need previous business day then just give - value instead of 1 in red area
---------------------------------------------import files-------------------------------------
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import org.apache.commons.lang.time.DateUtils;
import org.apache.log.Logger;
----------------------------------------
private void setExpectedPerfectionDate() {
Row printakeRow =ADFUtils.findIterator("CasePreIntakeVOIterator").getCurrentRow();
oracle.jbo.domain.Date createdDate=null,updatedDate=null;
if (printakeRow != null) {
createdDate = (oracle.jbo.domain.Date)printakeRow.getAttribute("CreatedDttm");
updatedDate=getTwoBusinessDateAdded(createdDate);
ViewObject casesVo = ADFUtils.findIterator("CasesVOIterator").getViewObject();
// casesVo.setNamedWhereClauseParam("bindCaseId",printakeRow.getAttribute("CaseId").toString());
// casesVo.executeQuery();
Row row = casesVo.getCurrentRow();
if(row!=null){
row.setAttribute("ExpectedPerfectionDate", updatedDate);
ADFUtils.findOperation("Commit").execute();
}
}
}
--------------this method wil add two business days ----------------------
private oracle.jbo.domain.Date getTwoBusinessDateAdded(oracle.jbo.domain.Date createdDate) {
oracle.jbo.domain.Date date=new oracle.jbo.domain.Date();
Date Date=getNextBusinessDay(getNextBusinessDay(createdDate.dateValue()));
java.sql.Date sqlDate = new java.sql.Date(Date.getTime());
oracle.jbo.domain.Date jboDate = new oracle.jbo.domain.Date(sqlDate);
return jboDate;
}
--------------------------- get the next business day------------
public Date getNextBusinessDay(Date startDate) {
System.out.println("Date in getNextBusinessDay - >"+startDate);
//Decrement the Date object by a Day and clear out hour/min/sec information
Date nextDay =DateUtils.truncate(addDays(startDate, 1), Calendar.DATE);
//If yesterday is a valid business day, return it
if (isBusinessDay(nextDay))
return nextDay;
//Else we recursively call our function until we find one.
else
return getNextBusinessDay(nextDay);
}
-----------------------------it returns wheather the nest day is business day or not-----------
public boolean isBusinessDay(Date dateToCheck) {
System.out.println("Date in isBusinessDay - >"+dateToCheck);
//Setup the calendar to have the start date truncated
Calendar baseCal = Calendar.getInstance();
baseCal.setTime(DateUtils.truncate(dateToCheck, Calendar.DATE));
List<Date> offlimitDates;
//Grab the list of dates for the year. These SHOULD NOT be modified.
synchronized (computedDates) {
int year = baseCal.get(Calendar.YEAR);
//If the map doesn't already have the dates computed, create them.
if (!computedDates.containsKey(year))
computedDates.put(year, getOfflimitDates(year));
offlimitDates = computedDates.get(year);
}
//Determine if the date is on a weekend.
int dayOfWeek = baseCal.get(Calendar.DAY_OF_WEEK);
boolean onWeekend =dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY;
//If it's on a holiday, increment and test again
//If it's on a weekend, increment necessary amount and test again
//System.out.println(offlimitDates);
if (offlimitDates.contains(baseCal.getTime()) || onWeekend)
return false;
else
return true;
}
/**
* Based on a year, this will compute the actual dates of
*
*
**/
private List<Date> getOfflimitDates(int year) {
System.out.println("Year in getOfflimitDates - >"+year);
List<Date> offlimitDates = new ArrayList<Date>();
Calendar baseCalendar = GregorianCalendar.getInstance();
baseCalendar.clear();
//Add in the static dates for the year.
//New years day
baseCalendar.set(year, Calendar.JANUARY, 1);
offlimitDates.add(baseCalendar.getTime());
//Christmas
baseCalendar.set(year, Calendar.DECEMBER, 25);
offlimitDates.add(baseCalendar.getTime());
baseCalendar.set(year, Calendar.DECEMBER, 26);
offlimitDates.add(baseCalendar.getTime());
//Greece Specific
Date pasxa = getOrthodoxEaster(year);
offlimitDates.add(pasxa);
offlimitDates.add(addDays(pasxa, -3));
offlimitDates.add(addDays(pasxa, 1));
//25 March
baseCalendar.set(year, Calendar.MARCH, 25);
offlimitDates.add(baseCalendar.getTime());
//28 October
baseCalendar.set(year, Calendar.OCTOBER, 28);
offlimitDates.add(baseCalendar.getTime());
//Fwta
baseCalendar.set(year, Calendar.JANUARY, 6);
offlimitDates.add(baseCalendar.getTime());
//May Day
baseCalendar.set(year, Calendar.MAY, 1);
offlimitDates.add(baseCalendar.getTime());
// 15 August
baseCalendar.set(year, Calendar.AUGUST, 15);
offlimitDates.add(baseCalendar.getTime());
return offlimitDates;
}
/**
* Compute the day of the year that Orthodox Easter falls on.
* Based on Gausean Algorithm.
*
* @param the_year Year
* @return Orthodox Easter Sunday
*/
public Date getOrthodoxEaster(int the_year) {
//Gaus Algorithm
Date easter;
int res =(19 * (the_year % 19) + 16) % 30 + (2 * (the_year % 4) + 4 * (the_year %7) +6 *(((19 * (the_year % 19)) + 16) %30)) % 7 + 3;
if (res < 31)
easter =(new GregorianCalendar(the_year, Calendar.APRIL, res)).getTime(); // 4-1 // pasxa = res+"/"+"04"+"/"+the_year;
else
easter =(new GregorianCalendar(the_year, Calendar.MAY, res - 30)).getTime(); // 5-1 // pasxa = (res-30)+"/"+"05"+"/"+the_year;
return easter;
}
/**
* Private method simply adds
* @param dateToAdd
* @param numberOfDay
* @return
*/
private Date addDays(Date dateToAdd, int numberOfDay) {
if (dateToAdd == null)
throw new IllegalArgumentException("Date can't be null!");
Calendar tempCal = Calendar.getInstance();
tempCal.setTime(dateToAdd);
tempCal.add(Calendar.DATE, numberOfDay);
return tempCal.getTime();
}
if u need previous business day then just give - value instead of 1 in red area
---------------------------------------------import files-------------------------------------
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import org.apache.commons.lang.time.DateUtils;
import org.apache.log.Logger;
----------------------------------------
private void setExpectedPerfectionDate() {
Row printakeRow =ADFUtils.findIterator("CasePreIntakeVOIterator").getCurrentRow();
oracle.jbo.domain.Date createdDate=null,updatedDate=null;
if (printakeRow != null) {
createdDate = (oracle.jbo.domain.Date)printakeRow.getAttribute("CreatedDttm");
updatedDate=getTwoBusinessDateAdded(createdDate);
ViewObject casesVo = ADFUtils.findIterator("CasesVOIterator").getViewObject();
// casesVo.setNamedWhereClauseParam("bindCaseId",printakeRow.getAttribute("CaseId").toString());
// casesVo.executeQuery();
Row row = casesVo.getCurrentRow();
if(row!=null){
row.setAttribute("ExpectedPerfectionDate", updatedDate);
ADFUtils.findOperation("Commit").execute();
}
}
}
--------------this method wil add two business days ----------------------
private oracle.jbo.domain.Date getTwoBusinessDateAdded(oracle.jbo.domain.Date createdDate) {
oracle.jbo.domain.Date date=new oracle.jbo.domain.Date();
Date Date=getNextBusinessDay(getNextBusinessDay(createdDate.dateValue()));
java.sql.Date sqlDate = new java.sql.Date(Date.getTime());
oracle.jbo.domain.Date jboDate = new oracle.jbo.domain.Date(sqlDate);
return jboDate;
}
--------------------------- get the next business day------------
public Date getNextBusinessDay(Date startDate) {
System.out.println("Date in getNextBusinessDay - >"+startDate);
//Decrement the Date object by a Day and clear out hour/min/sec information
Date nextDay =DateUtils.truncate(addDays(startDate, 1), Calendar.DATE);
//If yesterday is a valid business day, return it
if (isBusinessDay(nextDay))
return nextDay;
//Else we recursively call our function until we find one.
else
return getNextBusinessDay(nextDay);
}
-----------------------------it returns wheather the nest day is business day or not-----------
public boolean isBusinessDay(Date dateToCheck) {
System.out.println("Date in isBusinessDay - >"+dateToCheck);
//Setup the calendar to have the start date truncated
Calendar baseCal = Calendar.getInstance();
baseCal.setTime(DateUtils.truncate(dateToCheck, Calendar.DATE));
List<Date> offlimitDates;
//Grab the list of dates for the year. These SHOULD NOT be modified.
synchronized (computedDates) {
int year = baseCal.get(Calendar.YEAR);
//If the map doesn't already have the dates computed, create them.
if (!computedDates.containsKey(year))
computedDates.put(year, getOfflimitDates(year));
offlimitDates = computedDates.get(year);
}
//Determine if the date is on a weekend.
int dayOfWeek = baseCal.get(Calendar.DAY_OF_WEEK);
boolean onWeekend =dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY;
//If it's on a holiday, increment and test again
//If it's on a weekend, increment necessary amount and test again
//System.out.println(offlimitDates);
if (offlimitDates.contains(baseCal.getTime()) || onWeekend)
return false;
else
return true;
}
/**
* Based on a year, this will compute the actual dates of
*
*
**/
private List<Date> getOfflimitDates(int year) {
System.out.println("Year in getOfflimitDates - >"+year);
List<Date> offlimitDates = new ArrayList<Date>();
Calendar baseCalendar = GregorianCalendar.getInstance();
baseCalendar.clear();
//Add in the static dates for the year.
//New years day
baseCalendar.set(year, Calendar.JANUARY, 1);
offlimitDates.add(baseCalendar.getTime());
//Christmas
baseCalendar.set(year, Calendar.DECEMBER, 25);
offlimitDates.add(baseCalendar.getTime());
baseCalendar.set(year, Calendar.DECEMBER, 26);
offlimitDates.add(baseCalendar.getTime());
//Greece Specific
Date pasxa = getOrthodoxEaster(year);
offlimitDates.add(pasxa);
offlimitDates.add(addDays(pasxa, -3));
offlimitDates.add(addDays(pasxa, 1));
//25 March
baseCalendar.set(year, Calendar.MARCH, 25);
offlimitDates.add(baseCalendar.getTime());
//28 October
baseCalendar.set(year, Calendar.OCTOBER, 28);
offlimitDates.add(baseCalendar.getTime());
//Fwta
baseCalendar.set(year, Calendar.JANUARY, 6);
offlimitDates.add(baseCalendar.getTime());
//May Day
baseCalendar.set(year, Calendar.MAY, 1);
offlimitDates.add(baseCalendar.getTime());
// 15 August
baseCalendar.set(year, Calendar.AUGUST, 15);
offlimitDates.add(baseCalendar.getTime());
return offlimitDates;
}
/**
* Compute the day of the year that Orthodox Easter falls on.
* Based on Gausean Algorithm.
*
* @param the_year Year
* @return Orthodox Easter Sunday
*/
public Date getOrthodoxEaster(int the_year) {
//Gaus Algorithm
Date easter;
int res =(19 * (the_year % 19) + 16) % 30 + (2 * (the_year % 4) + 4 * (the_year %7) +6 *(((19 * (the_year % 19)) + 16) %30)) % 7 + 3;
if (res < 31)
easter =(new GregorianCalendar(the_year, Calendar.APRIL, res)).getTime(); // 4-1 // pasxa = res+"/"+"04"+"/"+the_year;
else
easter =(new GregorianCalendar(the_year, Calendar.MAY, res - 30)).getTime(); // 5-1 // pasxa = (res-30)+"/"+"05"+"/"+the_year;
return easter;
}
/**
* Private method simply adds
* @param dateToAdd
* @param numberOfDay
* @return
*/
private Date addDays(Date dateToAdd, int numberOfDay) {
if (dateToAdd == null)
throw new IllegalArgumentException("Date can't be null!");
Calendar tempCal = Calendar.getInstance();
tempCal.setTime(dateToAdd);
tempCal.add(Calendar.DATE, numberOfDay);
return tempCal.getTime();
}
Comments
Post a Comment