• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GregorianCalendar leap year issue

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Ranch Hand
Posts: 227
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot,

for your quick response Aditya,
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic