code: private static void advance(Calendar cal, int field, int nextField, long haystack, int needle)
      {
          long higher = higher(haystack, needle);
          if (higher != 0)
          {
              cal.set(field, first(higher));
          }
          else
          {
              cal.set(field, first(haystack));
              cal.add(nextField, 1);
          }
      }
docs: Moves the value of the specified field forward in time to satisfy
  constraints of the specified bitmask. If a position higher than
  needle is found in haystack, then that higher position is set as the
  value in field. Otherwise, the lowest value in haystack is set as the
  value in field, and the value in nextField is incremented.
  
  <p>For example, if field=Calendar.SECOND, haystack is {30, 40, 50},
  and needle is 35, then the seconds field will be set to 40, and the
  minutes field will be unchanged. However, if haystack={10, 20, 30},
  then the value in the seconds field will be set to 10, and the value of
  the minutes field will be incremented.
  
  @param cal the current time
  @param field a field from <tt>java.util.Calendar</tt>
  @param field the next coarser field after <tt>field</tt>; for example,
  if field=Calendar.SECOND, nextField=Calendar.MINUTE
  @param haystack the bitmask
  @param needle the current position in the bitmask; only higher