You are here

public function DateTimePlusTest::providerTestDateDiff in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::providerTestDateDiff()
  2. 10 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::providerTestDateDiff()

Provides data for date tests.

Return value

array An array of arrays, each containing the input parameters for DateTimePlusTest::testDateDiff().

See also

DateTimePlusTest::testDateDiff()

File

core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php, line 648

Class

DateTimePlusTest
@coversDefaultClass \Drupal\Component\Datetime\DateTimePlus @group Datetime

Namespace

Drupal\Tests\Component\Datetime

Code

public function providerTestDateDiff() {
  $empty_interval = new \DateInterval('PT0S');
  $positive_19_hours = new \DateInterval('PT19H');
  $positive_18_hours = new \DateInterval('PT18H');
  $positive_1_hour = new \DateInterval('PT1H');
  $negative_1_hour = new \DateInterval('PT1H');
  $negative_1_hour->invert = 1;
  return [
    // There should be a 19 hour time interval between
    // new years in Sydney and new years in LA in year 2000.
    [
      'input2' => DateTimePlus::createFromFormat('Y-m-d H:i:s', '2000-01-01 00:00:00', new \DateTimeZone('Australia/Sydney')),
      'input1' => DateTimePlus::createFromFormat('Y-m-d H:i:s', '2000-01-01 00:00:00', new \DateTimeZone('America/Los_Angeles')),
      'absolute' => FALSE,
      'expected' => $positive_19_hours,
    ],
    // In 1970 Sydney did not observe daylight savings time
    // So there is only a 18 hour time interval.
    [
      'input2' => DateTimePlus::createFromFormat('Y-m-d H:i:s', '1970-01-01 00:00:00', new \DateTimeZone('Australia/Sydney')),
      'input1' => DateTimePlus::createFromFormat('Y-m-d H:i:s', '1970-01-01 00:00:00', new \DateTimeZone('America/Los_Angeles')),
      'absolute' => FALSE,
      'expected' => $positive_18_hours,
    ],
    [
      'input1' => DateTimePlus::createFromFormat('U', 3600, new \DateTimeZone('America/Los_Angeles')),
      'input2' => DateTimePlus::createFromFormat('U', 0, new \DateTimeZone('UTC')),
      'absolute' => FALSE,
      'expected' => $negative_1_hour,
    ],
    [
      'input1' => DateTimePlus::createFromFormat('U', 3600),
      'input2' => DateTimePlus::createFromFormat('U', 0),
      'absolute' => FALSE,
      'expected' => $negative_1_hour,
    ],
    [
      'input1' => DateTimePlus::createFromFormat('U', 3600),
      'input2' => \DateTime::createFromFormat('U', 0),
      'absolute' => FALSE,
      'expected' => $negative_1_hour,
    ],
    [
      'input1' => DateTimePlus::createFromFormat('U', 3600),
      'input2' => DateTimePlus::createFromFormat('U', 0),
      'absolute' => TRUE,
      'expected' => $positive_1_hour,
    ],
    [
      'input1' => DateTimePlus::createFromFormat('U', 3600),
      'input2' => \DateTime::createFromFormat('U', 0),
      'absolute' => TRUE,
      'expected' => $positive_1_hour,
    ],
    [
      'input1' => DateTimePlus::createFromFormat('U', 0),
      'input2' => DateTimePlus::createFromFormat('U', 0),
      'absolute' => FALSE,
      'expected' => $empty_interval,
    ],
  ];
}