code: static int dayNumToDate(DayOfWeek dow0, int nDays, int weekNum, DayOfWeek dow, int d0, int nDaysInMonth) {
  		//if dow is wednesday, then this is the date of the first wednesday
  		int firstDateOfGivenDow = 1 + ((7 + dow.getCalendarConstant() - dow0.getCalendarConstant()) % 7);
  
  		int date;
  		if (weekNum > 0) {
  			date = ((weekNum - 1) * 7) + firstDateOfGivenDow - d0;
  		} else { //count weeks from end of month
  			//calculate last day of the given dow
  			//since nDays <= 366, this should be > nDays
  			int lastDateOfGivenDow = firstDateOfGivenDow + (7 * 54);
  			lastDateOfGivenDow -= 7 * ((lastDateOfGivenDow - nDays + 6) / 7);
  			date = lastDateOfGivenDow + 7 * (weekNum + 1) - d0;
  		}
  		return (date <= 0 || date > nDaysInMonth) ? 0 : date;
  	}
docs: Given a weekday number, such as {@code -1SU}, this method calculates the
  day of the month that it falls on. The weekday number may be refer to a
  week in the current month in some contexts, or a week in the current year
  in other contexts.
  @param dow0 the day of week of the first day in the current year/month
  @param nDays the number of days in the current year/month (must be one of
  the following values [28,29,30,31,365,366])
  @param weekNum the weekday number (for example, the -1 in {@code -1SU})
  @param dow the day of the week (for example, the SU in {@code -1SU})
  @param d0 the number of days between the first day of the current
  year/month and the current month
  @param nDaysInMonth the number of days in the current month
  @return the day of the month, or 0 if no such day exists