function DateTest::providerTestFormatInterval

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

Provides some test data for the format interval test.

File

core/tests/Drupal/Tests/Core/Datetime/DateTest.php, line 119

Class

DateTest
@coversDefaultClass \Drupal\Core\Datetime\DateFormatter @group Datetime

Namespace

Drupal\Tests\Core\Datetime

Code

public function providerTestFormatInterval() {
    $data = [
        // Checks for basic seconds.
[
            1,
            1,
            '1 sec',
        ],
        [
            1,
            2,
            '1 sec',
        ],
        [
            2,
            1,
            '2 sec',
        ],
        [
            2,
            2,
            '2 sec',
        ],
        // Checks for minutes with seconds.
[
            61,
            1,
            '1 min',
        ],
        [
            61,
            2,
            '1 min 1 sec',
        ],
        [
            62,
            2,
            '1 min 2 sec',
        ],
        [
            121,
            1,
            '2 min',
        ],
        [
            121,
            2,
            '2 min 1 sec',
        ],
        // Check for hours with minutes and seconds.
[
            3601,
            1,
            '1 hour',
        ],
        [
            3601,
            2,
            '1 hour',
        ],
        // Check for higher units.
[
            86401,
            1,
            '1 day',
        ],
        [
            604800,
            1,
            '1 week',
        ],
        [
            2592000 * 2,
            1,
            '2 months',
        ],
        [
            31536000 * 2,
            1,
            '2 years',
        ],
        // Check for a complicated one with months weeks and days.
[
            2592000 * 2 + 604800 * 3 + 86400 * 4,
            3,
            '2 months 3 weeks 4 days',
        ],
        // Check for the langcode.
[
            61,
            1,
            '1 min',
            'xxx-lolspeak',
        ],
        // Check with an unspecified granularity.
[
            61,
            NULL,
            '1 min 1 sec',
        ],
    ];
    return $data;
}

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