Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDK1.3 calendar problem

 
Kevin P Smith
Ranch Hand
Posts: 362
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I was just wondering if anyone knew of a problem with Java version 1.3 calendar?

The reason i ask is that I have a small class which calculates the number of
working days (excluding bank holidays, as I can't work a way round them)
between to dates.

However I have noticed that for some dats it's calculating the days right and
others it seems a day out.

Example:

08/06/2005 to 10/06/2005 = 1 day, WRONG,
07/06/2005 to 10/06/2005 = 2 days, WRONG,
06/06/2005 to 08/06/2005 = 2 days, RIGHT,
07/06/2005 to 08/06/2005 = 1 day, RIGHT,
27/05/2005 to 01/06/2005 = 4 days, WRONG!


Sample code:
=====================================================================
for (long l=StartDate.getTime();l<EndDate.getTime();l=l+86400000) {
day = newCal.get(Calendar.DAY_OF_WEEK);
if ((day>1) && (day<7)) {
numdays++;
}
newCal.add(Calendar.DATE,1);
}
retStr = new Integer(numdays).toString();
=====================================================================

Any help, greatly recieved... Cheers

K.
 
Frank Ertl
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

looking at your code-example I see that you change your Calendar-object newCal inside the for-loop. I think that's the reason, because changing the DATE-field has effect on the DAY_OF_WEEK.
Try to change this and I think it'll work correct.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic