title: Help with java calendar logic
body: <p>I am working with the Java Calendar class to do the following:</p>
  
  <ol>
  <li>Set a start date</li>
  <li>Set an end date</li>
  <li>Any date within that range is a "valid" date</li>
  </ol>
  
  <p>I have this somewhat working, and somewhat not. Please see the code below:</p>
  
  <pre><code>    nowCalendar.set(Calendar.DATE, nowCalendar.get(Calendar.DATE) + offset);
      int nowDay = nowCalendar.get(Calendar.DATE);
  
      Calendar futureCalendar = Calendar.getInstance();
      futureCalendar.set(Calendar.DATE, nowDay + days);
  
      Date now = nowCalendar.getTime();
      Date endTime = futureCalendar.getTime();
  
      long now_ms = now.getTime();
      long endTime_ms = endTime.getTime();
  
      for (; now_ms &lt; endTime_ms; now_ms += MILLIS_IN_DAY) {
          valid_days.addElement(new Date(now_ms));
          System.out.println("VALID DAY: " + new Date(now_ms));
      }
  </code></pre>
  
  <p>Basically, I set a "NOW" calendar and a "FUTURE" calendar, and then I compare the two calendars to find the valid days.  On my calendar, valid days will be shaded white and invalid days will be shaded gray. You will notice two variables:</p>
  
  <pre><code>    offset = three days after the current selected date
      days = the number of valid days from the current selected date
  </code></pre>
  
  <p>This works...EXCEPT when the current selected date is the last day of the month, or two days prior (three all together). I think that its the offset that is definitely screwing it up, but the logic works everywhere else.  Any ideas? </p>