function DateTimePlusTest::testDateTimezoneWithDateTimeObject

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::testDateTimezoneWithDateTimeObject()
  2. 8.9.x core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::testDateTimezoneWithDateTimeObject()
  3. 11.x core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::testDateTimezoneWithDateTimeObject()

Tests that DrupalDateTime can detect the correct timezone to use.

But only when the DrupalDateTime is constructed from a datetime object.

File

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

Class

DateTimePlusTest
@coversDefaultClass \Drupal\Component\Datetime\DateTimePlus[[api-linebreak]] @group Datetime

Namespace

Drupal\Tests\Component\Datetime

Code

public function testDateTimezoneWithDateTimeObject() : void {
  // 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);
}

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