You are here

function date_week_range in Date 6

Same name and namespace in other branches
  1. 5.2 date_api.module \date_week_range()
  2. 6.2 date_api.module \date_week_range()
  3. 7.3 date_api/date_api.module \date_week_range()
  4. 7 date_api/date_api.module \date_week_range()
  5. 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.

File

./date_api.module, line 806
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) {
  $min_date = date_make_date($view->year . '-01-01 00:00:00', date_default_timezone_name());
  date_timezone_set($min_date, date_default_timezone());

  // 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 = drupal_clone($min_date);
  date_modify($max_date, '+7 days');
  if (date_format($min_date, 'Y') != $year) {
    $min_date = date_make_date($year . '-01-01 00:00:00', date_default_timezone());
  }
  return array(
    $min_date,
    $max_date,
  );
}