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. 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()

Test that DrupalDateTime can detect the right timezone to use when constructed from a datetime object.

File

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

Class

DateTimePlusTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Component%21Datetime%21DateTimePlus.php/class/DateTimePlus/8.9.x" title="Wraps DateTime()." class="local">\Drupal\Component\Datetime\DateTimePlus</a> @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.