You are here

public function DateTimePlusTest::testDateTimezoneWithDateTimeObject 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::testDateTimezoneWithDateTimeObject()
  2. 9 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::testDateTimezoneWithDateTimeObject()

Tests DrupalDateTime with a datetime object.

File

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

Class

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

Namespace

Drupal\Tests\Component\Datetime

Code

public function testDateTimezoneWithDateTimeObject() {

  // Create a date object with another date object.
  $input = new \DateTime('now', new \DateTimeZone('Pacific/Midway'));
  $timezone = NULL;
  $expected_timezone = 'Pacific/Midway';
  $message = 'DateTimePlus uses the specified timezone if provided.';
  $date = DateTimePlus::createFromDateTime($input, $timezone);
  $timezone = $date
    ->getTimezone()
    ->getName();
  $this
    ->assertEquals($timezone, $expected_timezone, $message);
}