function DrupalDateTimeTest::testTimezoneFormat
Same name in other branches
- 9 core/modules/system/tests/src/Functional/Datetime/DrupalDateTimeTest.php \Drupal\Tests\system\Functional\Datetime\DrupalDateTimeTest::testTimezoneFormat()
- 10 core/modules/system/tests/src/Functional/Datetime/DrupalDateTimeTest.php \Drupal\Tests\system\Functional\Datetime\DrupalDateTimeTest::testTimezoneFormat()
- 11.x core/modules/system/tests/src/Functional/Datetime/DrupalDateTimeTest.php \Drupal\Tests\system\Functional\Datetime\DrupalDateTimeTest::testTimezoneFormat()
Tests the ability to override the time zone in the format method.
File
-
core/
modules/ system/ tests/ src/ Functional/ Datetime/ DrupalDateTimeTest.php, line 109
Class
- DrupalDateTimeTest
- Tests DrupalDateTime functionality.
Namespace
Drupal\Tests\system\Functional\DatetimeCode
public function testTimezoneFormat() {
// Create a date in UTC
$date = DrupalDateTime::createFromTimestamp(87654321, 'UTC');
// Verify that the date format method displays the default time zone.
$this->assertEqual($date->format('Y/m/d H:i:s e'), '1972/10/11 12:25:21 UTC', 'Date has default UTC time zone and correct date/time.');
// Verify that the format method can override the time zone.
$this->assertEqual($date->format('Y/m/d H:i:s e', [
'timezone' => 'America/New_York',
]), '1972/10/11 08:25:21 America/New_York', 'Date displayed overidden time zone and correct date/time');
// Verify that the date format method still displays the default time zone
// for the date object.
$this->assertEqual($date->format('Y/m/d H:i:s e'), '1972/10/11 12:25:21 UTC', 'Date still has default UTC time zone and correct date/time');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.