static int dayNumToDate(Weekday dow0, int nDays, int weekNum,
                            Weekday dow, int d0, int nDaysInMonth) {
        // if dow is wednesday, then this is the date of the first wednesday
        int firstDateOfGivenDow = 1 + ((7 + dow.javaDayNum - dow0.javaDayNum) % 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;
        }
        if (date <= 0 || date > nDaysInMonth) {
            return 0;
        }
        return date;
    }
static int dayNumToDate ( Weekday dow0 , int nDays , int weekNum , Weekday dow , int d0 , int nDaysInMonth ) { int firstDateOfGivenDow = 1 + ( ( 7 + dow . javaDayNum - dow0 . javaDayNum ) % 7 ) ; int date ; if ( weekNum > 0 ) { date = ( ( weekNum - 1 ) * 7 ) + firstDateOfGivenDow - d0 ; } else { int lastDateOfGivenDow = firstDateOfGivenDow + ( 7 * 54 ) ; lastDateOfGivenDow -= 7 * ( ( lastDateOfGivenDow - nDays + 6 ) / 7 ) ; date = lastDateOfGivenDow + 7 * ( weekNum + 1 ) - d0 ; } if ( date <= 0 || date > nDaysInMonth ) { return 0 ; } return date ; }
given a weekday number, such as -1SU, returns 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.
In [28,29,30,31,365,366].
@param weekNum -1SU in the example above.
@param d0 the number of days between the 1st day of the current
year/month and the current month.
@param nDaysInMonth the number of days in the current month.
@return 0 indicates no such day