private void getWeeklyDates ( Calendar calendar , int frequency , List < Date > dates ) { int currentDay = calendar . get ( Calendar . DAY_OF_WEEK ) ; while ( moreDates ( calendar , dates ) ) { int offset = 0 ; for ( int dayIndex = 0 ; dayIndex < 7 ; dayIndex ++ ) { if ( getWeeklyDay ( Day . getInstance ( currentDay ) ) ) { if ( offset != 0 ) { calendar . add ( Calendar . DAY_OF_YEAR , offset ) ; offset = 0 ; } if ( ! moreDates ( calendar , dates ) ) { break ; } dates . add ( calendar . getTime ( ) ) ; } ++ offset ; ++ currentDay ; if ( currentDay > 7 ) { currentDay = 1 ; } } if ( frequency > 1 ) { offset += ( 7 * ( frequency - 1 ) ) ; } calendar . add ( Calendar . DAY_OF_YEAR , offset ) ; } }
Calculate start dates for a weekly recurrence .