function DateHelperTest::testDaysInMonth

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

@covers ::daysInMonth

File

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

Class

DateHelperTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Datetime%21DateHelper.php/class/DateHelper/11.x" title="Defines Gregorian Calendar date values." class="local">\Drupal\Core\Datetime\DateHelper</a> @group Datetime

Namespace

Drupal\Tests\Core\Datetime

Code

public function testDaysInMonth() : void {
    // @todo Consider deprecating passing NULL in
    //   https://www.drupal.org/project/drupal/issues/3299788
    // 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::daysInMonth());
    $this->assertNotNull(DateHelper::daysInMonth(FALSE));
    $this->assertNotNull(DateHelper::daysInMonth(''));
    // Pass nothing and expect to get NULL.
    $this->assertNull(DateHelper::daysInMonth(0));
    $this->assertNull(DateHelper::daysInMonth('0'));
    $value = '2022-12-31 00:00:00';
    $dateString = DateHelper::daysInMonth($value);
    $this->assertEquals('31', $dateString);
    $value = '2020-11-30 00:00:00';
    $dateString = DateHelper::daysInMonth($value);
    $this->assertEquals('30', $dateString);
}

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