function DateHelperTest::testDaysInYear

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

@covers ::daysInYear

File

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

Class

DateHelperTest
@coversDefaultClass \Drupal\Core\Datetime\DateHelper @group Datetime

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.