OK,
I gave the weekend adjustment thing some thought. What if we included the following methods? (NOTE: javadoc, patches, and unit tests will be provided later if we go with this idea.)
Thoughts? sean
public static int[] SATURDAY_SUNDAY = {Calendar.SATURDAY, Calendar.SUNDAY};
public static Date adjustUntilNot(Date originalDate, int dayOfWeek, int increment) {
int[] dateArray = {dayOfWeek};
return adjustUntilNot(originalDate, dateArray, increment);
}
public static Date adjustUntilNot(Date originalDate, int[] daysOfWeek, int increment) {
Date adjustedDate = originalDate;
Calendar calendar = new GregorianCalendar();
while (fallsOn(adjustedDate, daysOfWeek)) {
calendar.add(Calendar.DATE, increment);
adjustedDate = calendar.getTime();
}return adjustedDate; }
public static boolean fallsOn(Date date, int dayToCheck) {
int[] daysToCheck = {dayToCheck};
return fallsOn(date, daysToCheck);
} public static boolean fallsOn(Date date, int[] daysToCheck) {
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); for (int i=0; i < daysToCheck.length; i++) {
if (dayOfWeek == daysToCheck[i]) {
return true;
}
}return false; }
----- Original Message ----- From: "Stephen Colebourne" <[EMAIL PROTECTED]>
To: "Jakarta Commons Developers List" <[EMAIL PROTECTED]>
Sent: Sunday, September 12, 2004 10:06 AM
Subject: Re: [lang] Enhancement proposal for DateUtils
Its a point for debate really. It might be OK to define SatSun weekends as a
default, but an API should probably be framed to allow the avoidance of any
day of week combination. And that can get to be a tricky API to define.
Stephen
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
