You are here

function DrupalDateTimeTest::testTimezoneFormat in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Datetime/DrupalDateTimeTest.php \Drupal\system\Tests\Datetime\DrupalDateTimeTest::testTimezoneFormat()

Tests the ability to override the time zone in the format method.

File

core/modules/system/src/Tests/Datetime/DrupalDateTimeTest.php, line 109
Contains \Drupal\system\Tests\Datetime\DrupalDateTimeTest.

Class

DrupalDateTimeTest
Tests DrupalDateTime functionality.

Namespace

Drupal\system\Tests\Datetime

Code

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', array(
    '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');
}