private void setFittingWeekDay ( Calendar date ) { date . set ( Calendar . DAY_OF_MONTH , 1 ) ; int weekDayFirst = date . get ( Calendar . DAY_OF_WEEK ) ; int firstFittingWeekDay = ( ( ( m_weekDay . toInt ( ) + I_CmsSerialDateValue . NUM_OF_WEEKDAYS ) - weekDayFirst ) % I_CmsSerialDateValue . NUM_OF_WEEKDAYS ) + 1 ; int fittingWeekDay = firstFittingWeekDay + ( I_CmsSerialDateValue . NUM_OF_WEEKDAYS * m_weekOfMonth . ordinal ( ) ) ; if ( fittingWeekDay > date . getActualMaximum ( Calendar . DAY_OF_MONTH ) ) { fittingWeekDay -= I_CmsSerialDateValue . NUM_OF_WEEKDAYS ; } date . set ( Calendar . DAY_OF_MONTH , fittingWeekDay ) ; }
Adjusts the day in the provided month that it fits the specified week day . If there s no match for that provided month the next possible month is checked .