You are here

function date_iso_week_range in Date 6.2

Same name and namespace in other branches
  1. 8 date_api/date_api.module \date_iso_week_range()
  2. 5 date.inc \date_iso_week_range()
  3. 7.3 date_api/date_api.module \date_iso_week_range()
  4. 7 date_api/date_api.module \date_iso_week_range()
  5. 7.2 date_api/date_api.module \date_iso_week_range()

Start and end dates for an ISO week.

1 call to date_iso_week_range()
date_week_range in ./date_api.module
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 1149
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_iso_week_range($week, $year) {

  // Get to the last ISO week of the previous year.
  $min_date = date_make_date($year - 1 . '-12-28 00:00:00', date_default_timezone_name());
  date_timezone_set($min_date, date_default_timezone());

  // Find the first day of the first ISO week in the year.
  date_modify($min_date, '+1 Monday');

  // Jump ahead to the desired week for the beginning of the week range.
  if ($week > 1) {
    date_modify($min_date, '+ ' . ($week - 1) . ' weeks');
  }

  // move forwards to the last day of the week
  $max_date = drupal_clone($min_date);
  date_modify($max_date, '+7 days');
  return array(
    $min_date,
    $max_date,
  );
}