Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

weird java dates!!!!

 
Romit Bose
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hiiii all,
Greetings!
I am facing a really weird problem with java Dates. it goes like this: We need to write a function to which we need to pass a java.util.date and we want to get back the due date, which is the day that is after 3 working days if the input time is before 4 PM, and 4 days if it is after 4 PM.to do this we first created a GregorianCalendar instance and added days to it, one at a time, and checked whether this day is a weekend or not. next we checked with the database to see whether this is a company holiday or not. if it passes these tests, then it is a working day. going by this rule, we found out the resultant date. this seems to be working fine as long as the last day "down the calculation lane" is not a sunday. Its only when its a sunday,that the Gregorian Calendar starts behaving creepy....for example if the starting date is 19th august, then the resultant day is shown to be Monday, August 24th,with some valid time,if we set the timezone properly.now, if you just look into any common Paper (may also be plastic :-) ) calendar you will that 24th is Sunday, not Monday!!! i am attaching the codes below, where th function called is TPlus3.
Please rescue us!!!
Thanks In Advance!!!

 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well apparently, in 3908, August 24th is a Monday

I guess this has something to do with Date.setYear. According to its documentation, this will add 1900 to the year before adding it. It's also quite deprecated; you should use a Calendar to create it.
 
Romit Bose
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Rob!
And lots and lots of Thanks! bull's Eye, the problem was with date.setYear(). now we have replaced that with Calendar.set().
Thanks once again for your help, buddy!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic