private void offsetStartTimeIfNecessary(Time startTime,Time endTime,String rrule,CalendarEventModel model){
  if (rrule == null || rrule.isEmpty()) {
    return;
  }
  mEventRecurrence.parse(rrule);
  if (mEventRecurrence.freq != EventRecurrence.WEEKLY) {
    return;
  }
  if (mEventRecurrence.byday.length > mEventRecurrence.bydayCount) {
    return;
  }
  int closestWeekday=Integer.MAX_VALUE;
  int weekstart=EventRecurrence.day2TimeDay(mEventRecurrence.wkst);
  int startDay=startTime.weekDay;
  for (int i=0; i < mEventRecurrence.bydayCount; i++) {
    int day=EventRecurrence.day2TimeDay(mEventRecurrence.byday[i]);
    if (day == startDay) {
      return;
    }
    if (day < weekstart) {
      day+=7;
    }
    if (day > startDay && (day < closestWeekday || closestWeekday < startDay)) {
      closestWeekday=day;
    }
    if (closestWeekday == Integer.MAX_VALUE || closestWeekday < startDay) {
      if (day < closestWeekday) {
        closestWeekday=day;
      }
    }
  }
  if (closestWeekday < startDay) {
    closestWeekday+=7;
  }
  int daysOffset=closestWeekday - startDay;
  startTime.monthDay+=daysOffset;
  endTime.monthDay+=daysOffset;
  long newStartTime=startTime.normalize(true);
  long newEndTime=endTime.normalize(true);
  model.mStart=newStartTime;
  model.mEnd=newEndTime;
}

private void offsetStartTimeIfNecessary ( Time startTime , Time endTime , String rrule , CalendarEventModel model ) { if ( rrule == null || rrule . isEmpty ( ) ) { return ; } mEventRecurrence . parse ( rrule ) ; if ( mEventRecurrence . freq != EventRecurrence . WEEKLY ) { return ; } if ( mEventRecurrence . byday . length > mEventRecurrence . bydayCount ) { return ; } int closestWeekday = Integer . MAX_VALUE ; int weekstart = EventRecurrence . day2TimeDay ( mEventRecurrence . wkst ) ; int startDay = startTime . weekDay ; for ( int i = 0 ; i < mEventRecurrence . bydayCount ; i ++ ) { int day = EventRecurrence . day2TimeDay ( mEventRecurrence . byday [ i ] ) ; if ( day == startDay ) { return ; } if ( day < weekstart ) { day += 7 ; } if ( day > startDay && ( day < closestWeekday || closestWeekday < startDay ) ) { closestWeekday = day ; } if ( closestWeekday == Integer . MAX_VALUE || closestWeekday < startDay ) { if ( day < closestWeekday ) { closestWeekday = day ; } } } if ( closestWeekday < startDay ) { closestWeekday += 7 ; } int daysOffset = closestWeekday - startDay ; startTime . monthDay += daysOffset ; endTime . monthDay += daysOffset ; long newStartTime = startTime . normalize ( true ) ; long newEndTime = endTime . normalize ( true ) ; model . mStart = newStartTime ; model . mEnd = newEndTime ; }
if the recurrence rule is such that the event start date doesn ' t actually fall in one of the recurrences , then push the start date up to the first actual instance of the event .
