protected function buildNthWeekdayMask($year, $month, $day, array &$masks)
{
$masks['yearday_is_nth_weekday'] = array();
if ($this->byweekday_nth) {
$ranges = array();
if ($this->freq == self::YEARLY) {
if ($this->bymonth) {
foreach ($this->bymonth as $bymonth) {
$ranges[] = array($masks['last_day_of_month'][$bymonth - 1], $masks['last_day_of_month'][$bymonth] - 1);
}
} else {
$ranges = array(array(0, $masks['year_len'] - 1));
}
} elseif ($this->freq == self::MONTHLY) {
$ranges[] = array($masks['last_day_of_month'][$month - 1], $masks['last_day_of_month'][$month] - 1);
}
if ($ranges) {
// Weekly frequency won't get here, so we may not
// care about cross-year weekly periods.
foreach ($ranges as $tmp) {
list($first, $last) = $tmp;
foreach ($this->byweekday_nth as $tmp) {
list($weekday, $nth) = $tmp;
if ($nth < 0) {
$i = $last + ($nth + 1) * 7;
$i = $i - pymod($masks['yearday_to_weekday'][$i] - $weekday, 7);
} else {
$i = $first + ($nth - 1) * 7;
$i = $i + (7 - $masks['yearday_to_weekday'][$i] + $weekday) % 7;
}
if ($i >= $first && $i <= $last) {
$masks['yearday_is_nth_weekday'][$i] = true;
}
}
}
}
}
}