function date_repeat_set_month_day in Date 6
Same name and namespace in other branches
- 5.2 date_repeat/date_repeat_calc.inc \date_repeat_set_month_day()
- 6.2 date_repeat/date_repeat_calc.inc \date_repeat_set_month_day()
- 7.3 date_repeat/date_repeat_calc.inc \date_repeat_set_month_day()
- 7 date_repeat/date_repeat_calc.inc \date_repeat_set_month_day()
- 7.2 date_repeat/date_repeat_calc.inc \date_repeat_set_month_day()
Set a date object to a specific day of the month.
Example, date_set_month_day($date, '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.
1 call to date_repeat_set_month_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 421 - Code to compute the dates that match an iCal RRULE.
Code
function date_repeat_set_month_day($date_in, $day, $count = 1, $direction = '+') {
if (is_object($date_in)) {
// Reset to the start of the month.
// We should be able to do this with date_date_set(), but
// for some reason the date occasionally gets confused if run
// through this function multiple times. It seems to work
// reliably if we create a new object each time.
$datetime = date_format($date_in, DATE_FORMAT_DATETIME);
$datetime = substr_replace($datetime, '01', 8, 2);
$date = date_make_date($datetime, 'UTC');
if ($direction == '-') {
// For negative search, start from the end of the month.
date_modify($date, '+1 month');
}
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($date, '-1 day');
}
if (empty($day)) {
$day = 'days';
}
date_modify($date, $direction . $count . ' ' . $day);
}
return $date;
}