avoiding weekends in calendar
String durationToFollowUp = "";
Calendar durationToFollowUpTime = Calendar.getInstance();
durationToFollowUpTime.setTime(getNow().getTime());
durationToFollowUpTime.add(Calendar.DATE, getDurationToFollowUp());
folks my code looks like the above.
I get the current date and add the value from getDurationToFollowUp().
What I am trying to do is when a superuser posts a entry and assigns it to a user he can also set the number of days for the user to respond.
The problem is I have to avoid the weekends and just count the business days. Not a problem if it is a holiday for now I just need to avoid saturdays and sundays.
[670 byte] By [
javapunta] at [2007-11-26 13:10:13]

public static void main(String[] args) throws ParseException {
Calendar cal = Calendar.getInstance();
Date start = cal.getTime();
cal.add(Calendar.DATE,60);
Date end = cal.getTime();
int days = calculateWeekdays(start,end);
System.out.println("There are " + days + " weekdays between " + start + " and " + end);
}
private static int calculateWeekdays(Date start, Date end)
{
int days = 0;
Calendar cal = Calendar.getInstance();
cal.setTime(start);
while(cal.getTime().getTime() < end.getTime())
{
cal.add(Calendar.DATE,1);
int day = cal.get(Calendar.DAY_OF_WEEK);
if( day == Calendar.SATURDAY || day == Calendar.SUNDAY )
continue;
days++;
}
return days;
}
~Tim