function DateTimePlusTest::providerTestDateTimezone

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::providerTestDateTimezone()
  2. 10 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::providerTestDateTimezone()
  3. 11.x core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::providerTestDateTimezone()

Provides data for testDateTimezone.

Return value

array An array of arrays, each containing:

  • 'date' - Date string or object for DateTimePlus.
  • 'timezone' - Timezone string for DateTimePlus.
  • 'expected' - Expected return from DateTimePlus::getTimezone()::getName().
  • 'message' - Message to display on test failure.

See also

testDateTimezone

File

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

Class

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

Namespace

Drupal\Tests\Component\Datetime

Code

public function providerTestDateTimezone() {
    // Use a common date for most of the tests.
    $date_string = '2007-01-31 21:00:00';
    // Detect the system timezone.
    $system_timezone = date_default_timezone_get();
    return [
        // Create a date object with an unspecified timezone, which should
        // end up using the system timezone.
[
            $date_string,
            NULL,
            $system_timezone,
            'DateTimePlus uses the system timezone when there is no site timezone.',
        ],
        // Create a date object with a specified timezone name.
[
            $date_string,
            'America/Yellowknife',
            'America/Yellowknife',
            'DateTimePlus uses the specified timezone if provided.',
        ],
        // Create a date object with a timezone object.
[
            $date_string,
            new \DateTimeZone('Australia/Canberra'),
            'Australia/Canberra',
            'DateTimePlus uses the specified timezone if provided.',
        ],
        // Create a date object with another date object.
[
            new DateTimePlus('now', 'Pacific/Midway'),
            NULL,
            'Pacific/Midway',
            'DateTimePlus uses the specified timezone if provided.',
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.