function weekdays_days_in_date_range in Weekdays field 7
Computes dates corresponding to the weekdays in a given date range.
Parameters
DateObject $start:
DateObject $end:
array $weekdays array of weekdays in iCal format.:
array $include dates to include, in DATE_FORMAT_DATE format.:
array $exclude dates to exclude, in DATE_FORMAT_DATE format.:
Return value
array array of dates in DATE_FORMAT_DATE format.
1 call to weekdays_days_in_date_range()
- weekdays_date_restrictions_allowed_values_page_callback in modules/
weekdays_date_restrictions/ weekdays_date_restrictions.module - Implements allowed_values_page_callback callback.
File
- ./
weekdays.module, line 263
Code
function weekdays_days_in_date_range(DateObject $start, DateObject $end, array $weekdays, array $include = array(), array $exclude = array()) {
// It may happen that week day of $start is not part of $weekdays.
// In that case we need to increase $start until it matches a weekday.
// This is a workaround to https://drupal.org/node/1365516
$dow = array_keys(date_repeat_dow_day_options(TRUE));
$wday = $dow[date_day_of_week($start)];
while (!in_array($wday, $weekdays) && $start < $end) {
$start
->modify('+1 day');
$wday = $dow[date_day_of_week($start)];
}
if (!empty($weekdays)) {
$rrule = 'RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=' . implode(',', $weekdays) . ';';
$dates = date_repeat_calc($rrule, (string) $start, (string) $end);
}
else {
$dates = array();
}
// Strip hours from dates.
foreach ($dates as $date) {
$date = substr($date, 0, 10);
if (!in_array($date, $exclude)) {
$include[] = $date;
}
}
return $include;
}