function DateHelperTest::testDayOfWeek

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

@covers ::dayOfWeek

File

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

Class

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

Namespace

Drupal\Tests\Core\Datetime

Code

public function testDayOfWeek() : 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::dayOfWeek());
    $this->assertNotNull(DateHelper::dayOfWeek(FALSE));
    $this->assertNotNull(DateHelper::dayOfWeek(''));
    // Pass nothing and expect to get NULL.
    $this->assertNull(DateHelper::dayOfWeek(0));
    $this->assertNull(DateHelper::dayOfWeek('0'));
    // December 31st 2022 is a Saturday.
    $value = '2022-12-31 00:00:00';
    $dateString = DateHelper::dayOfWeek($value);
    $this->assertEquals('6', $dateString);
    // November 30th 2020 is a Monday.
    $value = '2020-11-30 00:00:00';
    $dateString = DateHelper::dayOfWeek($value);
    $this->assertEquals('1', $dateString);
}

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