You are here

public function DateTimePlusTest::providerTestDates in Drupal 10

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

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 317

Class

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

Namespace

Drupal\Tests\Component\Datetime

Code

public function providerTestDates() {
  $dates = [
    // String input.
    // Create date object from datetime string.
    [
      '2009-03-07 10:30',
      'America/Chicago',
      '2009-03-07T10:30:00-06:00',
    ],
    // Same during daylight savings time.
    [
      '2009-06-07 10:30',
      'America/Chicago',
      '2009-06-07T10:30:00-05:00',
    ],
    // Create date object from date string.
    [
      '2009-03-07',
      'America/Chicago',
      '2009-03-07T00:00:00-06:00',
    ],
    // Same during daylight savings time.
    [
      '2009-06-07',
      'America/Chicago',
      '2009-06-07T00:00:00-05:00',
    ],
    // Create date object from date string.
    [
      '2009-03-07 10:30',
      'Australia/Canberra',
      '2009-03-07T10:30:00+11:00',
    ],
    // Same during daylight savings time.
    [
      '2009-06-07 10:30',
      'Australia/Canberra',
      '2009-06-07T10:30:00+10: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[] = [
      '1883-11-19 10:30',
      'America/Chicago',
      '1883-11-19T10:30:00-06:00',
    ];

    // Create a date object in the far future.
    $dates[] = [
      '2345-01-02 02:04',
      'UTC',
      '2345-01-02T02:04:00+00:00',
    ];
  }
  return $dates;
}