protected function DateRRuleCalc::set_month_day in Date 8
Set a date object to a specific day of the month.
Example, set_month_day('Sunday', 2, '-') will reset $date to the second to last Sunday in the month. If $day is empty, will set to the number of days from the beginning or end of the month.
2 calls to DateRRuleCalc::set_month_day()
- DateRRuleCalc::get_bymonthday_results in date_repeat/
lib/ Drupal/ date_repeat/ DateRRuleCalc.php - Processing for BYMONTHDAY values.
- DateRRuleCalc::get_relative_bydays in date_repeat/
lib/ Drupal/ date_repeat/ DateRRuleCalc.php - Get results for relative BYDAY values.
File
- date_repeat/
lib/ Drupal/ date_repeat/ DateRRuleCalc.php, line 715 - Code to compute the dates that match an iCal RRULE.
Class
Namespace
Drupal\date_repeatCode
protected function set_month_day($day, $count = 1, $direction = '+') {
$time = $this->time_string;
$current_month = $this->current_day
->format('n');
// Create a clone and reset.
$date = clone $this->current_day;
if ($direction == '-') {
// For negative search, start from just outside the end
// of the month, so we can catch the last day of the month.
$date
->modify("first day of next month {$time}");
}
else {
// For positive search, back up one day to get outside the
// current month, so we can catch the first of the month.
$date
->modify("last day of last month {$time}");
}
if (empty($day)) {
$date
->modify("{$direction} {$count} days {$time}");
}
else {
// Use the English text for order, like First Sunday
// instead of +1 Sunday to overcome PHP5 bug, (see #369020).
$order = self::$date_order;
$step = $count <= 5 ? $order[$direction . $count] : $direction . $count;
$date
->modify("{$step} {$day} {$time}");
}
// If that takes us outside the current month, don't go there,
// only reset the date if it's in the current month.
if ($date
->format('n') == $current_month) {
$this->current_day = $date;
return TRUE;
}
else {
return FALSE;
}
}