Can somoene help by providing some code or existant code.
- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Originally posted by Tom Blough:
Bob,
For the second working day of a given month, create a Calendar object for the second day of the given month. If DAY_OF_WEEK is Saturday or Sunday use the add method to add 1 0r 2 days to the current value.
For the last working day of a specific month, get the first day of the specified month, add one month, then subtract one day. If the DAY_OF_WEEK is Saturday or Sunday add -1 or -2 days to get the last working day of the month.
tags 'cause UBB has a bug when there's code and quote tags in the same post. ]
[ April 20, 2004: Message edited by: Jessica Sant ]
Originally posted by bob morkos:
This is the method that I wrote to get the last day of the month. I don't know how to write a method to get the second working day of the month. The help that I need is to get the second working day of the month.
<code>
public static int getLastDayOfMonth(int month, boolean isLeapYear) {
switch (month) {
case JANUARY :
return 31;
case FEBRUARY :
if (isLeapYear)
return 29;
else
return 28;
case MARCH :
return 31;
case APRIL :
return 30;
case MAY :
return 31;
case JUNE :
return 30;
case JULY :
return 31;
case AUGUST :
return 31;
case SEPTEMBER :
return 30;
case OCTOBER :
return 31;
case NOVEMBER :
return 30;
case DECEMBER :
return 31;
default :
return 0;
}
}
public static boolean isLastDayOfWorkOfMonth(Date aDate) {
Calendar c = Calendar.getInstance();
c.setTime(aDate);
/**
* If the day is a saturday or a sunday, it's obvious
* than we are not the last day!
*/
if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
return false;
if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
return false;
/**
* So check if tomorrow is the first of month
*/
c.add(Calendar.DAY_OF_MONTH, 1);
// We are friday? Add one more day to know if next
// monday will be the first of month.
if(c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
c.add(Calendar.DAY_OF_MONTH, 1);
// If the saturday is the first, friday was the last day.
if (c.get(Calendar.DAY_OF_MONTH) == 1)
return true;
if(c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
c.add(Calendar.DAY_OF_MONTH, 1);
if (c.get(Calendar.DAY_OF_MONTH) == 1)
return true;
return false;
}
<code>
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Originally posted by Tom Blough:
As was previously mentioned, most ranchhands frown on posting code for solutions, but I had a few free minutes to code up the algorithm I previously presented. This is just a start, the class should really calculate the Nth working day of the month and not just the second and last. In addition, you'll need to take into account holidays for the current locale as was mentioned by Jessica.
Also, there is no need to re-invent the wheel. The Calendar class already takes care of leap years and the number of days in each month, so we let it handle those functions. That's why in my last day calculation, I set the date to the first of the subsequent month, since that is a day I know, then subtract one day from that. This automatically handles the days in each month as well as leap year. Your only worry now is holidays - the calendar object is like my employer, any day not a weekend is considered a work day ;-).
Here is the output:
[ April 21, 2004: Message edited by: Tom Blough ]
[ April 21, 2004: Message edited by: Tom Blough ]
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |