You are here

function date_iso_week_range in Date 8

Same name and namespace in other branches
  1. 5 date.inc \date_iso_week_range()
  2. 6.2 date_api.module \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()

Calculates the start and end dates for an ISO week.

Parameters

int $week: The week value.

int $year: The year value.

Return value

array An array containing the start and end dates of an ISO week.

2 calls to date_iso_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 779
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 = new DrupalDateTime($year - 1 . '-12-28 00:00:00');

  // 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 = clone $min_date;
  date_modify($max_date, '+7 days');
  return array(
    $min_date,
    $max_date,
  );
}