protected function DateRRuleCalc::set_year_day in Date 8
Set a date object to a specific day of the year.
Example, date_set_year_day($date, 'Sunday', 2, '-') will reset $date to the second to last Sunday in the year. If $day is empty, will set to the number of days from the beginning or end of the year.
1 call to DateRRuleCalc::set_year_day()
- 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 763 - Code to compute the dates that match an iCal RRULE.
Class
Namespace
Drupal\date_repeatCode
protected function set_year_day($day, $count = 1, $direction = '+') {
$time = $this->time_string;
$current_year = $this->current_day
->format('Y');
// Create a clone and reset.
$date = clone $this->current_day;
if ($direction == '-') {
// For negative search, start from the end of the year.
// It is important to set year before month for some reason.
$date
->modify("next year January 1 {$time}");
}
else {
// For positive search, back up one day to get outside the
// current year, so we can catch the first of the year.
// It is important to set year before month for some reason.
$date
->modify("last year December 31 {$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 year, don't go there.
if ($date
->format('Y') == $current_year) {
$this->current_day = $date;
return TRUE;
}
else {
return FALSE;
}
}