You are here

public static function CalendarHelper::isoWeeksInYear in Calendar 8

Identifies the number of ISO weeks in a year for a date.

December 28 is always in the last ISO week of the year.

Parameters

mixed $date: (optional) The current date object, or a date string. Defaults to NULL.

Return value

int The number of ISO weeks in a year.

Throws

\Exception

1 call to CalendarHelper::isoWeeksInYear()
CalendarHelper::difference in src/CalendarHelper.php
Computes difference between two days using a given measure.

File

src/CalendarHelper.php, line 227

Class

CalendarHelper
Defines Gregorian Calendar date values.

Namespace

Drupal\calendar

Code

public static function isoWeeksInYear($date = NULL) {
  if (empty($date)) {
    $date = new \DateTime();
  }
  elseif (!is_object($date)) {
    $date = new \DateTime($date);
  }
  if (is_object($date)) {
    date_date_set($date, $date
      ->format('Y'), 12, 28);
    return $date
      ->format('W');
  }
  return NULL;
}