1 system.test DateTimeFunctionalTest::testTimeZoneHandling()

Test time zones and DST handling.

File

core/modules/system/tests/system.test, line 1371
Tests for system.module.

Class

DateTimeFunctionalTest
Tests generic date and time handling capabilities of Backdrop.

Code

function testTimeZoneHandling() {
  // Setup date/time settings for Honolulu time.
  $config = config('system.date')
    ->set('default_timezone', 'Pacific/Honolulu')
    ->set('user_configurable_timezones', 0)
    ->set('formats.medium.pattern', 'Y-m-d H:i:s O')
    ->save();

  // Create some nodes with different authored-on dates.
  $date1 = '2007-01-31 21:00:00 -1000';
  $date2 = '2007-07-31 21:00:00 -1000';
  $node1 = $this->backdropCreateNode(array('created' => strtotime($date1), 'type' => 'post'));
  $node2 = $this->backdropCreateNode(array('created' => strtotime($date2), 'type' => 'post'));

  // Confirm date format and time zone.
  $this->backdropGet("node/$node1->nid");
  $this->assertText('2007-01-31 21:00:00 -1000', 'Date should be identical, with GMT offset of -10 hours.');
  $this->backdropGet("node/$node2->nid");
  $this->assertText('2007-07-31 21:00:00 -1000', 'Date should be identical, with GMT offset of -10 hours.');

  // Set time zone to Los Angeles time.
  $config->set('default_timezone', 'America/Los_Angeles')->save();

  // Confirm date format and time zone.
  $this->backdropGet("node/$node1->nid");
  $this->assertText('2007-01-31 23:00:00 -0800', 'Date should be two hours ahead, with GMT offset of -8 hours.');
  $this->backdropGet("node/$node2->nid");
  $this->assertText('2007-08-01 00:00:00 -0700', 'Date should be three hours ahead, with GMT offset of -7 hours.');
}