function DateHelper::daysInYear

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Datetime/DateHelper.php \Drupal\Core\Datetime\DateHelper::daysInYear()
  2. 8.9.x core/lib/Drupal/Core/Datetime/DateHelper.php \Drupal\Core\Datetime\DateHelper::daysInYear()
  3. 10 core/lib/Drupal/Core/Datetime/DateHelper.php \Drupal\Core\Datetime\DateHelper::daysInYear()

Identifies the number of days in a year for a date.

Parameters

mixed $date: (optional) A DrupalDateTime object or a date string. Defaults to NULL, which means to use the current date.

Return value

int|null The number of days in the year, or null if the $date has errors.

1 call to DateHelper::daysInYear()
DateHelperTest::testDaysInYear in core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php
@covers ::daysInYear

File

core/lib/Drupal/Core/Datetime/DateHelper.php, line 477

Class

DateHelper
Defines Gregorian Calendar date values.

Namespace

Drupal\Core\Datetime

Code

public static function daysInYear($date = NULL) {
    $date = $date ?? 'now';
    if (!$date instanceof DrupalDateTime) {
        $date = new DrupalDateTime($date);
    }
    if (!$date->hasErrors()) {
        if ($date->format('L')) {
            return 366;
        }
        else {
            return 365;
        }
    }
    return NULL;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.