private function getNthDayOfMonth($curdate, $day_of_week, $week_of_month, $next_month_of_year) { $nextdate = $this->advanceDate($curdate, $next_month_of_year, 1); // advance to correct month $nextdate = TribeDateUtils::getFirstDayOfWeekInMonth($nextdate, $day_of_week); if ($week_of_month == -1) { // LAST WEEK $nextdate = TribeDateUtils::getLastDayOfWeekInMonth($nextdate, $day_of_week); return $nextdate; } else { $maybe_date = strtotime(date(DateSeriesRules::DATE_FORMAT, $nextdate) . " + " . ($week_of_month - 1) . " weeks"); // if this doesn't exist, then try next month while (date('n', $maybe_date) != date('n', $nextdate)) { // advance again $next_month_of_year = $this->getNextMonthOfYear(date('n', $nextdate)); $nextdate = $this->advanceDate($nextdate, $next_month_of_year); $nextdate = TribeDateUtils::getFirstDayOfWeekInMonth($curdate, $day_of_week); $maybe_date = strtotime(date(DateSeriesRules::DATE_FORMAT, $nextdate) . " + " . ($week_of_month - 1) . " weeks"); } return $maybe_date; } }