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()
- 8.9.x 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()
Tests the ability to override the time zone in the format method.
File
-
core/
modules/ system/ tests/ src/ Functional/ Datetime/ DrupalDateTimeTest.php, line 101
Class
- DrupalDateTimeTest
- Tests DrupalDateTime functionality.
Namespace
Drupal\Tests\system\Functional\DatetimeCode
public function testTimezoneFormat() : void {
// Create a date in UTC
$date = DrupalDateTime::createFromTimestamp(87654321, 'UTC');
// Verify that the date format method displays the default time zone.
$this->assertEquals('1972/10/11 12:25:21 UTC', $date->format('Y/m/d H:i:s e'), 'Date has default UTC time zone and correct date/time.');
// Verify that the format method can override the time zone.
$this->assertEquals('1972/10/11 08:25:21 America/New_York', $date->format('Y/m/d H:i:s e', [
'timezone' => 'America/New_York',
]), 'Date displayed overridden time zone and correct date/time');
// Verify that the date format method still displays the default time zone
// for the date object.
$this->assertEquals('1972/10/11 12:25:21 UTC', $date->format('Y/m/d H:i:s e'), '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.