function DateTimePlusTest::testDateTimezoneWithDateTimeObject

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::testDateTimezoneWithDateTimeObject()
  2. 10 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 297

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);
}

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