code: private void getMonthlyRelativeDates(Calendar calendar, int frequency, List<Date> dates)
     {
        long startDate = calendar.getTimeInMillis();
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        int dayNumber = NumberHelper.getInt(m_dayNumber);
  
        while (moreDates(calendar, dates))
        {
           if (dayNumber > 4)
           {
              setCalendarToLastRelativeDay(calendar);
           }
           else
           {
              setCalendarToOrdinalRelativeDay(calendar, dayNumber);
           }
  
           if (calendar.getTimeInMillis() > startDate)
           {
              dates.add(calendar.getTime());
              if (!moreDates(calendar, dates))
              {
                 break;
              }
           }
           calendar.set(Calendar.DAY_OF_MONTH, 1);
           calendar.add(Calendar.MONTH, frequency);
        }
     }
docs: Calculate start dates for a monthly relative recurrence.
  
  @param calendar current date
  @param frequency frequency
  @param dates array of start dates