function date_week_range in Date 7
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.2 date_api/date_api.module \date_week_range()
Start and end dates for a calendar week, adjusted to use the chosen first day of week for this site.
2 calls to date_week_range()
- DateAPITestCase::testDateAPI in tests/
date_api.test - date_sql_handler::complete_date in date_api/
date_api_sql.inc - Create a complete datetime value out of an incomplete array of selected values.
File
- date_api/
date_api.module, line 1426 - 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_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', 1);
$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 DateObject($year . '-01-01 00:00:00');
}
return array(
$min_date,
$max_date,
);
}