function date_week_range in Date 7.2
Same name and namespace in other branches
- 5.2 date_api.module \date_week_range()
- 6.2 date_api.module \date_week_range()
- 6 date_api.module \date_week_range()
- 7.3 date_api/date_api.module \date_week_range()
- 7 date_api/date_api.module \date_week_range()
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 A numeric array containing the start and end dates of a week.
2 calls to date_week_range()
- DateApiTestCase::testDateApi in date_api/
tests/ DateApiTestCase.test - Test date_format_date().
- date_sql_handler::complete_date in date_api/
date_api_sql.inc - Create a complete date/time value out of an incomplete array of values.
File
- date_api/
date_api.module, line 2122 - This module will make the date API available to other modules.
Code
function date_week_range($week, $year) {
if (variable_get('date_api_use_iso8601', FALSE)) {
return date_iso_week_range($week, $year);
}
$min_date = new DateObject($year . '-01-01 00:00:00');
$min_date
->setTimezone(date_default_timezone_object());
// 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, '+6 days +23 hours +59 minutes +59 seconds');
if (date_format($min_date, 'Y') != $year) {
$min_date = new DateObject($year . '-01-01 00:00:00');
}
return array(
$min_date,
$max_date,
);
}