code: private int getNextLastDayOfMonth(int day, int lastDay)
      {
          // lastDaysOfMonth = 0b1000 0011  (LSB) = Last, -6, -7
          // Shift left so that "Last" aligns with the last day of the month.
          // For example, for Jan, we want the Last bit in position 31, so we
          // shift 30-7=23 (note: 0-based last day for Jan is 30) resulting in:
          //            bits = 0b0100 0001 1000 0000 0000 0000 0000 0000  (LSB)
          int offset = lastDay - 7;
          long bits = lastDaysOfMonth << offset;
  
          if (!contains(bits, day))
          {
              long higher = higher(bits, day);
              if (higher != 0)
              {
                  return first(higher);
              }
  
              return ADVANCE_TO_NEXT_MONTH;
          }
  
          return day;
      }
docs: Returns the next day of the month after <tt>day</tt> that satisfies
  the lastDayOfMonth constraint.
  
  @param day the current 0-based day of the month
  @param lastDay the current 0-based last day of the month
  @return a value greater than or equal to <tt>day</tt>