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. 11.x 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 169

Class

DateHelperTest
@coversDefaultClass \Drupal\Core\Datetime\DateHelper[[api-linebreak]] @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.