• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Calendar.roll() questions

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all. I've got a question / problem using Calendar.roll(). It's probably just me understanding how things work (usually is), but before I code a workaround, I want to make sure I'm doing this right. What I'm trying to do is take an input date, then advance it by a certain number of months.
For example:

Here's the output, based on the current date of 2002-03-26:

But what I REALLY want to see is this:

..where the year is also incremented by adding one month each time once January is reached.
My question is, will I have to explicitly code for this: check to see if we're currently up to December, then increment the month AND year?
Thanks,
Rick <><
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you check the API for roll(), you will find that it explicitly states that larger fields will not be changed. (I.e. the year will remain constant while rolling months.) Try using add() instead.
 
Rick Crawford
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome! Works like a champ!
Thanks for the help,
Rick <><
 
reply
    Bookmark Topic Watch Topic
  • New Topic