function date_calendar_week_range in Date 8
Calculates the start and end dates for a calendar week.
The dates are adjusted to use the chosen first day of week for this site.
Parameters
int $week: The week value.
int $year: The year value.
Return value
array An array containing the start and end dates of a week.
2 calls to date_calendar_week_range()
- DateAPITest::testDateAPI in date_api/
lib/ Drupal/ date_api/ Tests/ DateAPITest.php - @todo.
- DateSqlHandler::complete_date in date_api/
lib/ Drupal/ date_api/ DateSqlHandler.php - Create a complete datetime value out of an incomplete array of selected values.
File
- date_api/
date_api.module, line 746 - This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.
Code
function date_calendar_week_range($week, $year) {
$min_date = new DrupalDateTime($year . '-01-01 00:00:00');
// Move to the right week.
date_modify($min_date, '+' . strval(7 * ($week - 1)) . ' days');
// Move backwards to the first day of the week.
$first_day = variable_get('date_first_day', 0);
$day_wday = date_format($min_date, 'w');
date_modify($min_date, '-' . strval((7 + $day_wday - $first_day) % 7) . ' days');
// Move forwards to the last day of the week.
$max_date = clone $min_date;
date_modify($max_date, '+7 days');
if (date_format($min_date, 'Y') != $year) {
$min_date = new DrupalDateTime($year . '-01-01 00:00:00');
}
return array(
$min_date,
$max_date,
);
}