private void setCalendarToOrdinalRelativeDay ( Calendar calendar , int dayNumber ) { int currentDayOfWeek = calendar . get ( Calendar . DAY_OF_WEEK ) ; int requiredDayOfWeek = getDayOfWeek ( ) . getValue ( ) ; int dayOfWeekOffset = 0 ; if ( requiredDayOfWeek > currentDayOfWeek ) { dayOfWeekOffset = requiredDayOfWeek - currentDayOfWeek ; } else { if ( requiredDayOfWeek < currentDayOfWeek ) { dayOfWeekOffset = 7 - ( currentDayOfWeek - requiredDayOfWeek ) ; } } if ( dayOfWeekOffset != 0 ) { calendar . add ( Calendar . DAY_OF_YEAR , dayOfWeekOffset ) ; } if ( dayNumber > 1 ) { calendar . add ( Calendar . DAY_OF_YEAR , ( 7 * ( dayNumber - 1 ) ) ) ; } }
Moves a calendar to the nth named day of the month .