private void toCorrectDateWithDay ( Calendar date , WeekOfMonth week ) { date . set ( Calendar . DAY_OF_MONTH , 1 ) ; int daysToFirstWeekDayMatch = ( ( m_weekDay . toInt ( ) + I_CmsSerialDateValue . NUM_OF_WEEKDAYS ) - ( date . get ( Calendar . DAY_OF_WEEK ) ) ) % I_CmsSerialDateValue . NUM_OF_WEEKDAYS ; date . add ( Calendar . DAY_OF_MONTH , daysToFirstWeekDayMatch ) ; int wouldBeDayOfMonth = date . get ( Calendar . DAY_OF_MONTH ) + ( ( week . ordinal ( ) ) * I_CmsSerialDateValue . NUM_OF_WEEKDAYS ) ; if ( wouldBeDayOfMonth > date . getActualMaximum ( Calendar . DAY_OF_MONTH ) ) { date . set ( Calendar . DAY_OF_MONTH , wouldBeDayOfMonth - I_CmsSerialDateValue . NUM_OF_WEEKDAYS ) ; } else { date . set ( Calendar . DAY_OF_MONTH , wouldBeDayOfMonth ) ; } }
Sets the day of the month that matches the condition i . e . the day of month of the 2nd Saturday . If the day does not exist in the current month the last possible date is set i . e . instead of the fifth Saturday the fourth is chosen .