protected function DateRRuleCalc::get_byday_results in Date 8
Processing for BYDAY values.
More complex searches for day names and criteria like '-1SU' or '2TU,2TH', require that we interate through the whole time period checking each day selected in BYDAY.
1 call to DateRRuleCalc::get_byday_results()
- DateRRuleCalc::compute in date_repeat/
lib/ Drupal/ date_repeat/ DateRRuleCalc.php
File
- date_repeat/
lib/ Drupal/ date_repeat/ DateRRuleCalc.php, line 395 - Code to compute the dates that match an iCal RRULE.
Class
Namespace
Drupal\date_repeatCode
protected function get_byday_results() {
// Create helper array to pull day names out of iCal day strings.
$day_names = self::$day_names;
$this->days_of_week = array_keys($day_names);
// Parse out information about the BYDAYs and separate them
// depending on whether they have directional parameters
// like -1SU or 2TH.
$week_days = array();
// Find the right first day of the week to use, iCal rules say
// Monday should be used if none is specified.
$week_start_rule = !empty($this->rrule['WKST']) ? trim($this->rrule['WKST']) : 'MO';
$this->week_start_day = $day_names[$week_start_rule];
// Make sure the week days array is sorted into week order,
// we use the $ordered_keys to get the right values into the key
// and force the array to that order. Needed later when we
// iterate through each week looking for days so we don't
// jump to the next week when we hit a day out of order.
$ordered = date_repeat_days_ordered($week_start_rule);
$ordered_keys = array_flip($ordered);
foreach ($this->rrule['BYDAY'] as $day) {
preg_match("@(-)?([0-9]+)?([SU|MO|TU|WE|TH|FR|SA]{2})@", trim($day), $regs);
if (!empty($regs[2])) {
// Convert parameters into full day name, count, and direction.
$relative_days[] = array(
'day' => $day_names[$regs[3]],
'direction' => !empty($regs[1]) ? $regs[1] : '+',
'direction_count' => $regs[2],
);
}
else {
$week_days[$ordered_keys[$regs[3]]] = $day_names[$regs[3]];
}
}
ksort($week_days);
// Get BYDAYs with parameters like -1SU (last Sun) or
// 2TH (second Thur).
if (!empty($relative_days) && in_array($this->rrule['FREQ'], array(
'MONTHLY',
'YEARLY',
))) {
$this
->get_relative_bydays($relative_days);
}
// Get BYDAYs without parameters,like TU,TH (every
// Tues and Thur).
if (!empty($week_days) && in_array($this->rrule['FREQ'], array(
'MONTHLY',
'WEEKLY',
'YEARLY',
))) {
$this
->get_absolute_bydays($week_days);
}
}