code: private void setCalendarToLastRelativeDay(Calendar calendar)
     {
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        int currentDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        int requiredDayOfWeek = getDayOfWeek().getValue();
        int dayOfWeekOffset = 0;
  
        if (currentDayOfWeek > requiredDayOfWeek)
        {
           dayOfWeekOffset = requiredDayOfWeek - currentDayOfWeek;
        }
        else
        {
           if (currentDayOfWeek < requiredDayOfWeek)
           {
              dayOfWeekOffset = -7 + (requiredDayOfWeek - currentDayOfWeek);
           }
        }
  
        if (dayOfWeekOffset != 0)
        {
           calendar.add(Calendar.DAY_OF_YEAR, dayOfWeekOffset);
        }
     }
docs: Moves a calendar to the last named day of the month.
  
  @param calendar current date