function DateTimePlusTest::testDateTimezoneWithDateTimeObject
Same name in other branches
- 9 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::testDateTimezoneWithDateTimeObject()
- 10 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::testDateTimezoneWithDateTimeObject()
- 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 \Drupal\Component\Datetime\DateTimePlus @group Datetime
Namespace
Drupal\Tests\Component\DatetimeCode
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.