You are here

public function DateTimePlusTest::testDefaultDateTime in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::testDefaultDateTime()
  2. 9 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::testDefaultDateTime()

Tests setting the default time for date-only objects.

File

core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php, line 856

Class

DateTimePlusTest
@coversDefaultClass \Drupal\Component\Datetime\DateTimePlus @group Datetime

Namespace

Drupal\Tests\Component\Datetime

Code

public function testDefaultDateTime() {
  $utc = new \DateTimeZone('UTC');
  $date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '2017-05-23 22:58:00', $utc);
  $this
    ->assertEquals('22:58:00', $date
    ->format('H:i:s'));
  $date
    ->setDefaultDateTime();
  $this
    ->assertEquals('12:00:00', $date
    ->format('H:i:s'));
}