function date_repeat_set_year_day in Date 6
Same name and namespace in other branches
- 5.2 date_repeat/date_repeat_calc.inc \date_repeat_set_year_day()
- 6.2 date_repeat/date_repeat_calc.inc \date_repeat_set_year_day()
- 7.3 date_repeat/date_repeat_calc.inc \date_repeat_set_year_day()
- 7 date_repeat/date_repeat_calc.inc \date_repeat_set_year_day()
- 7.2 date_repeat/date_repeat_calc.inc \date_repeat_set_year_day()
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 date_repeat_set_year_day()
- _date_repeat_calc in date_repeat/
date_repeat_calc.inc - Private implementation of date_repeat_calc().
File
- date_repeat/
date_repeat_calc.inc, line 457 - Code to compute the dates that match an iCal RRULE.
Code
function date_repeat_set_year_day($date_in, $day, $count = 1, $direction = '+') {
if (is_object($date_in)) {
// Reset to the start of the month.
// See note above.
$datetime = date_format($date_in, DATE_FORMAT_DATETIME);
$datetime = substr_replace($datetime, '01-01', 5, 5);
$date = date_make_date($datetime, 'UTC');
if ($direction == '-') {
// For negative search, start from the end of the year.
date_modify($date, '+1 year');
}
else {
// For positive search, back up one day to get outside the
// current year, so we can catch the first of the year.
date_modify($date, '-1 day');
}
if (empty($day)) {
$day = 'days';
}
date_modify($date, $direction . $count . ' ' . $day);
}
return $date;
}