function date_repeat_add_dates in Date 7
Same name and namespace in other branches
- 5.2 date_repeat/date_repeat_calc.inc \date_repeat_add_dates()
- 6.2 date_repeat/date_repeat_calc.inc \date_repeat_add_dates()
- 6 date_repeat/date_repeat_calc.inc \date_repeat_add_dates()
- 7.3 date_repeat/date_repeat_calc.inc \date_repeat_add_dates()
- 7.2 date_repeat/date_repeat_calc.inc \date_repeat_add_dates()
Helper function to add found date to the $dates array.
Check that the date to be added is between the start and end date and that it is not in the $exceptions, nor already in the $days array, and that it meets other criteria in the RRULE.
1 call to date_repeat_add_dates()
- _date_repeat_calc in date_repeat/
date_repeat_calc.inc - Private implementation of date_repeat_calc().
File
- date_repeat/
date_repeat_calc.inc, line 394 - Code to compute the dates that match an iCal RRULE.
Code
function date_repeat_add_dates(&$days, $current_day, $start_date, $end_date, $exceptions, $rrule) {
if (isset($rrule['COUNT']) && sizeof($days) >= $rrule['COUNT']) {
return FALSE;
}
$formatted = date_format($current_day, DATE_FORMAT_DATETIME);
if ($formatted > date_format($end_date, DATE_FORMAT_DATETIME)) {
return FALSE;
}
if ($formatted < date_format($start_date, DATE_FORMAT_DATETIME)) {
return FALSE;
}
if (in_array(date_format($current_day, 'Y-m-d'), $exceptions)) {
return FALSE;
}
if (!empty($rrule['BYDAY'])) {
$BYDAYS = $rrule['BYDAY'];
foreach ($BYDAYS as $delta => $BYDAY) {
$BYDAYS[$delta] = substr($BYDAY, -2);
}
if (!in_array(date_repeat_dow2day(date_format($current_day, 'w')), $BYDAYS)) {
return FALSE;
}
}
if (!empty($rrule['BYYEAR']) && !in_array(date_format($current_day, 'Y'), $rrule['BYYEAR'])) {
return FALSE;
}
if (!empty($rrule['BYMONTH']) && !in_array(date_format($current_day, 'n'), $rrule['BYMONTH'])) {
return FALSE;
}
if (!empty($rrule['BYMONTHDAY'])) {
// Test month days, but only if there are no negative numbers.
$test = TRUE;
$BYMONTHDAYS = array();
foreach ($rrule['BYMONTHDAY'] as $day) {
if ($day > 0) {
$BYMONTHDAYS[] = $day;
}
else {
$test = FALSE;
break;
}
}
if ($test && !empty($BYMONTHDAYS) && !in_array(date_format($current_day, 'j'), $BYMONTHDAYS)) {
return FALSE;
}
}
// Don't add a day if it is already saved so we don't throw the count off.
if (in_array($formatted, $days)) {
return TRUE;
}
else {
$days[] = $formatted;
}
}