• Post Reply Bookmark Topic Watch Topic
  • New Topic

GregorianCalendar leap year issue  RSS feed

 
Pandu Rangam
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,
While working with GregorianCalendar, I found that when feb 28th 2008 or feb 29th 2008 are incremented by 1 yr are giving the same output. i.e. 28th feb 2009, When I tried the same functionality in javascript it is giving as 28th feb and 1st march respectively.
which approach to increment date by year is correct.



 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Your intended functionality is provided by method Calendar.roll(int, int), and not Calendar.add(int, int). Please go through the JavaDoc for the two methods carefully.

For now, changing code

to

will do the trick.

Regards,

- Aditya Jha
 
Pandu Rangam
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot,

for your quick response Aditya,
 
Bob Good
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the business requirements what should be done here.

I would suggest in most cases Feb 29 + 1 year should be Feb 28.
But it depends on the requirements.

Ask yourself in this business case, what makes sense?

At least the java add versus roll methods give you a choice.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!