function DateTimePlusTest::providerTestDateTimezone

Same name and namespace in other branches
  1. 9 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 498

Class

DateTimePlusTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Component%21Datetime%21DateTimePlus.php/class/DateTimePlus/8.9.x" title="Wraps DateTime()." class="local">\Drupal\Component\Datetime\DateTimePlus</a> @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.