You are here

public function DateTimePlusTest::providerTestDateArrays 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::providerTestDateArrays()
  2. 10 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::providerTestDateArrays()

Provides data for date tests.

Return value

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

See also

DateTimePlusTest::testDates()

File

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

Class

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

Namespace

Drupal\Tests\Component\Datetime

Code

public function providerTestDateArrays() {
  $dates = [
    // Array input.
    // Create date object from date array, date only.
    [
      [
        'year' => 2010,
        'month' => 2,
        'day' => 28,
      ],
      'America/Chicago',
      '2010-02-28T00:00:00-06:00',
    ],
    // Create date object from date array with hour.
    [
      [
        'year' => 2010,
        'month' => 2,
        'day' => 28,
        'hour' => 10,
      ],
      'America/Chicago',
      '2010-02-28T10:00:00-06:00',
    ],
    // Create date object from date array, date only.
    [
      [
        'year' => 2010,
        'month' => 2,
        'day' => 28,
      ],
      'Europe/Berlin',
      '2010-02-28T00:00:00+01:00',
    ],
    // Create date object from date array with hour.
    [
      [
        'year' => 2010,
        'month' => 2,
        'day' => 28,
        'hour' => 10,
      ],
      'Europe/Berlin',
      '2010-02-28T10:00:00+01:00',
    ],
  ];

  // On 32-bit systems, timestamps are limited to 1901-2038.
  if (PHP_INT_SIZE > 4) {

    // Create a date object in the distant past.
    // @see https://www.drupal.org/node/2795489#comment-12127088
    // Note that this date is after the United States standardized its
    // timezones.
    $dates[] = [
      [
        'year' => 1883,
        'month' => 11,
        'day' => 19,
      ],
      'America/Chicago',
      '1883-11-19T00:00:00-06:00',
    ];

    // Create a date object in the far future.
    $dates[] = [
      [
        'year' => 2345,
        'month' => 1,
        'day' => 2,
      ],
      'UTC',
      '2345-01-02T00:00:00+00:00',
    ];
  }
  return $dates;
}