RRule\RRule::buildNthWeekdayMask PHP Method

buildNthWeekdayMask() protected method

For example, in Jan 1998, in a MONTHLY interval, "1SU,-1SU" (first Sunday and last Sunday) would be transformed into [3=>true,24=>true] because the first Sunday of Jan 1998 is yearday 3 (counting from 0) and the last Sunday of Jan 1998 is yearday 24 (counting from 0).
protected buildNthWeekdayMask ( integer $year, integer $month, integer $day, array &$masks ) : null
$year integer
$month integer
$day integer
$masks array
return null (modifies $mask parameter)
    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;
                        }
                    }
                }
            }
        }
    }