function DateHelperTest::testDaysInYear

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php \Drupal\Tests\Core\Datetime\DateHelperTest::testDaysInYear()
  2. 9 core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php \Drupal\Tests\Core\Datetime\DateHelperTest::testDaysInYear()

Tests days in year.

@legacy-covers ::daysInYear

File

core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php, line 204

Class

DateHelperTest
Tests Drupal\Core\Datetime\DateHelper.

Namespace

Drupal\Tests\Core\Datetime

Code

public function testDaysInYear() : void {
  // Passing NULL, FALSE, or an empty string should default to now. Just
  // check these are NOT null to avoid copying the implementation here.
  $this->assertNotNull(DateHelper::daysInYear());
  $this->assertNotNull(DateHelper::daysInYear(FALSE));
  $this->assertNotNull(DateHelper::daysInYear(''));
  // Pass nothing and expect to get NULL.
  $this->assertNull(DateHelper::daysInYear(0));
  $this->assertNull(DateHelper::daysInYear('0'));
  $value = '2022-12-31 00:00:00';
  $dateString = DateHelper::daysInYear($value);
  $this->assertEquals('365', $dateString);
  // 2020 is a leap year.
  $value = '2020-11-30 00:00:00';
  $dateString = DateHelper::daysInYear($value);
  $this->assertEquals('366', $dateString);
}

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