You are here

public function DateTest::providerTestFormatDiff in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::providerTestFormatDiff()
  2. 10 core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::providerTestFormatDiff()

Data provider for testformatDiff().

File

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

Class

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

Namespace

Drupal\Tests\Core\Datetime

Code

public function providerTestFormatDiff() {

  // This is the fixed request time in the test.
  $request_time = $this
    ->createTimestamp('2013-12-11 10:09:08');
  $granularity_3 = [
    'granularity' => 3,
  ];
  $granularity_4 = [
    'granularity' => 4,
  ];
  $langcode_en = [
    'langcode' => 'en',
  ];
  $langcode_lolspeak = [
    'langcode' => 'xxx-lolspeak',
  ];
  $non_strict = [
    'strict' => FALSE,
  ];
  $data = [
    // Checks for equal timestamps.
    [
      '0 seconds',
      0,
      $request_time,
      $request_time,
    ],
    // Checks for seconds only.
    [
      '1 second',
      1,
      $this
        ->createTimestamp('2013-12-11 10:09:07'),
      $request_time,
    ],
    [
      '1 second',
      1,
      $this
        ->createTimestamp('2013-12-11 10:09:07'),
      $request_time,
    ],
    [
      '1 second',
      1,
      $this
        ->createTimestamp('2013-12-11 10:09:07'),
      $request_time,
      $granularity_3 + $langcode_en,
    ],
    [
      '1 second',
      1,
      $this
        ->createTimestamp('2013-12-11 10:09:07'),
      $request_time,
      $granularity_4 + $langcode_lolspeak,
    ],
    [
      '2 seconds',
      1,
      $this
        ->createTimestamp('2013-12-11 10:09:06'),
      $request_time,
    ],
    [
      '59 seconds',
      1,
      $this
        ->createTimestamp('2013-12-11 10:08:09'),
      $request_time,
    ],
    [
      '59 seconds',
      1,
      $this
        ->createTimestamp('2013-12-11 10:08:09'),
      $request_time,
    ],
    // Checks for minutes and possibly seconds.
    [
      '1 minute',
      60,
      $this
        ->createTimestamp('2013-12-11 10:08:08'),
      $request_time,
    ],
    [
      '1 minute',
      60,
      $this
        ->createTimestamp('2013-12-11 10:08:08'),
      $request_time,
    ],
    [
      '1 minute 1 second',
      1,
      $this
        ->createTimestamp('2013-12-11 10:08:07'),
      $request_time,
    ],
    [
      '1 minute 59 seconds',
      1,
      $this
        ->createTimestamp('2013-12-11 10:07:09'),
      $request_time,
    ],
    [
      '2 minutes',
      60,
      $this
        ->createTimestamp('2013-12-11 10:07:08'),
      $request_time,
    ],
    [
      '2 minutes 1 second',
      1,
      $this
        ->createTimestamp('2013-12-11 10:07:07'),
      $request_time,
    ],
    [
      '2 minutes 2 seconds',
      1,
      $this
        ->createTimestamp('2013-12-11 10:07:06'),
      $request_time,
    ],
    [
      '2 minutes 2 seconds',
      1,
      $this
        ->createTimestamp('2013-12-11 10:07:06'),
      $request_time,
      $granularity_3,
    ],
    [
      '2 minutes 2 seconds',
      1,
      $this
        ->createTimestamp('2013-12-11 10:07:06'),
      $request_time,
      $granularity_4,
    ],
    [
      '30 minutes',
      60,
      $this
        ->createTimestamp('2013-12-11 09:39:08'),
      $request_time,
    ],
    [
      '59 minutes 59 seconds',
      1,
      $this
        ->createTimestamp('2013-12-11 09:09:09'),
      $request_time,
    ],
    [
      '59 minutes 59 seconds',
      1,
      $this
        ->createTimestamp('2013-12-11 09:09:09'),
      $request_time,
    ],
    // Checks for hours and possibly minutes or seconds.
    [
      '1 hour',
      3600,
      $this
        ->createTimestamp('2013-12-11 09:09:08'),
      $request_time,
    ],
    [
      '1 hour',
      3600,
      $this
        ->createTimestamp('2013-12-11 09:09:08'),
      $request_time,
    ],
    [
      '1 hour',
      3600,
      $this
        ->createTimestamp('2013-12-11 09:09:07'),
      $request_time,
    ],
    [
      '1 hour',
      3600,
      $this
        ->createTimestamp('2013-12-11 09:09:06'),
      $request_time,
    ],
    [
      '1 hour 1 minute',
      60,
      $this
        ->createTimestamp('2013-12-11 09:08:08'),
      $request_time,
    ],
    [
      '1 hour 1 minute 1 second',
      1,
      $this
        ->createTimestamp('2013-12-11 09:08:07'),
      $request_time,
      $granularity_3,
    ],
    [
      '1 hour 1 minute 2 seconds',
      1,
      $this
        ->createTimestamp('2013-12-11 09:08:06'),
      $request_time,
      $granularity_4,
    ],
    [
      '1 hour 30 minutes',
      60,
      $this
        ->createTimestamp('2013-12-11 08:39:08'),
      $request_time,
    ],
    [
      '2 hours',
      3600,
      $this
        ->createTimestamp('2013-12-11 08:09:08'),
      $request_time,
    ],
    [
      '23 hours 59 minutes',
      60,
      $this
        ->createTimestamp('2013-12-10 10:10:08'),
      $request_time,
    ],
    // Checks for days and possibly hours, minutes or seconds.
    [
      '1 day',
      86400,
      $this
        ->createTimestamp('2013-12-10 10:09:08'),
      $request_time,
    ],
    [
      '1 day',
      86400,
      $this
        ->createTimestamp('2013-12-10 10:09:07'),
      $request_time,
    ],
    [
      '1 day 1 hour',
      3600,
      $this
        ->createTimestamp('2013-12-10 09:09:08'),
      $request_time,
    ],
    [
      '1 day 1 hour 1 minute',
      60,
      $this
        ->createTimestamp('2013-12-10 09:08:07'),
      $request_time,
      $granularity_3 + $langcode_en,
    ],
    [
      '1 day 1 hour 1 minute 1 second',
      1,
      $this
        ->createTimestamp('2013-12-10 09:08:07'),
      $request_time,
      $granularity_4 + $langcode_lolspeak,
    ],
    [
      '1 day 2 hours 2 minutes 2 seconds',
      1,
      $this
        ->createTimestamp('2013-12-10 08:07:06'),
      $request_time,
      $granularity_4,
    ],
    [
      '2 days',
      86400,
      $this
        ->createTimestamp('2013-12-09 10:09:08'),
      $request_time,
    ],
    [
      '2 days',
      86400,
      $this
        ->createTimestamp('2013-12-09 10:07:08'),
      $request_time,
    ],
    [
      '2 days 2 hours',
      3600,
      $this
        ->createTimestamp('2013-12-09 08:09:08'),
      $request_time,
    ],
    [
      '2 days 2 hours 2 minutes',
      60,
      $this
        ->createTimestamp('2013-12-09 08:07:06'),
      $request_time,
      $granularity_3 + $langcode_en,
    ],
    [
      '2 days 2 hours 2 minutes 2 seconds',
      1,
      $this
        ->createTimestamp('2013-12-09 08:07:06'),
      $request_time,
      $granularity_4 + $langcode_lolspeak,
    ],
    // Checks for weeks and possibly days, hours, minutes or seconds.
    [
      '1 week',
      7 * 86400,
      $this
        ->createTimestamp('2013-12-04 10:09:08'),
      $request_time,
    ],
    [
      '1 week 1 day',
      86400,
      $this
        ->createTimestamp('2013-12-03 10:09:08'),
      $request_time,
    ],
    [
      '2 weeks',
      7 * 86400,
      $this
        ->createTimestamp('2013-11-27 10:09:08'),
      $request_time,
    ],
    [
      '2 weeks 2 days',
      86400,
      $this
        ->createTimestamp('2013-11-25 08:07:08'),
      $request_time,
    ],
    [
      '2 weeks 2 days 2 hours 2 minutes',
      60,
      $this
        ->createTimestamp('2013-11-25 08:07:08'),
      $request_time,
      $granularity_4,
    ],
    [
      '4 weeks',
      7 * 86400,
      $this
        ->createTimestamp('2013-11-13 10:09:08'),
      $request_time,
    ],
    [
      '4 weeks 1 day',
      86400,
      $this
        ->createTimestamp('2013-11-12 10:09:08'),
      $request_time,
    ],
    // Checks for months and possibly days, hours, minutes or seconds.
    [
      '1 month',
      30 * 86400,
      $this
        ->createTimestamp('2013-11-11 10:09:08'),
      $request_time,
    ],
    [
      '1 month',
      30 * 86400,
      $this
        ->createTimestamp('2013-11-11 10:09:07'),
      $request_time,
    ],
    [
      '1 month',
      30 * 86400,
      $this
        ->createTimestamp('2013-11-11 09:09:08'),
      $request_time,
    ],
    [
      '1 month',
      30 * 86400,
      $this
        ->createTimestamp('2013-11-11 09:08:07'),
      $request_time,
      $granularity_3,
    ],
    [
      '1 month',
      30 * 86400,
      $this
        ->createTimestamp('2013-11-11 09:08:07'),
      $request_time,
      $granularity_4,
    ],
    [
      '1 month 4 weeks',
      7 * 86400,
      $this
        ->createTimestamp('2013-10-13 10:09:08'),
      $request_time,
    ],
    [
      '1 month 4 weeks 1 day',
      86400,
      $this
        ->createTimestamp('2013-10-13 10:09:08'),
      $request_time,
      $granularity_3,
    ],
    [
      '1 month 4 weeks',
      7 * 86400,
      $this
        ->createTimestamp('2013-10-12 10:09:08'),
      $request_time,
    ],
    [
      '1 month 4 weeks 2 days',
      86400,
      $this
        ->createTimestamp('2013-10-12 10:09:08'),
      $request_time,
      $granularity_3,
    ],
    [
      '2 months',
      30 * 86400,
      $this
        ->createTimestamp('2013-10-11 10:09:08'),
      $request_time,
    ],
    [
      '2 months',
      30 * 86400,
      $this
        ->createTimestamp('2013-10-10 10:09:08'),
      $request_time,
    ],
    [
      '2 months',
      30 * 86400,
      $this
        ->createTimestamp('2013-10-09 08:07:06'),
      $request_time,
    ],
    [
      '2 months',
      30 * 86400,
      $this
        ->createTimestamp('2013-10-09 08:07:06'),
      $request_time,
      $granularity_3,
    ],
    [
      '2 months',
      30 * 86400,
      $this
        ->createTimestamp('2013-10-09 08:07:06'),
      $request_time,
      $granularity_4,
    ],
    [
      '6 months',
      30 * 86400,
      $this
        ->createTimestamp('2013-06-09 10:09:08'),
      $request_time,
    ],
    [
      '11 months',
      30 * 86400,
      $this
        ->createTimestamp('2013-01-11 07:09:08'),
      $request_time,
    ],
    [
      '11 months 4 weeks',
      7 * 86400,
      $this
        ->createTimestamp('2012-12-12 10:09:08'),
      $request_time,
    ],
    [
      '11 months 4 weeks 2 days',
      86400,
      $this
        ->createTimestamp('2012-12-12 10:09:08'),
      $request_time,
      $granularity_3,
    ],
    // Checks for years and possibly months, days, hours, minutes or seconds.
    [
      '1 year',
      365 * 86400,
      $this
        ->createTimestamp('2012-12-11 10:09:08'),
      $request_time,
    ],
    [
      '1 year',
      365 * 86400,
      $this
        ->createTimestamp('2012-12-11 10:08:08'),
      $request_time,
    ],
    [
      '1 year',
      365 * 86400,
      $this
        ->createTimestamp('2012-12-10 10:09:08'),
      $request_time,
    ],
    [
      '2 years',
      365 * 86400,
      $this
        ->createTimestamp('2011-12-11 10:09:08'),
      $request_time,
    ],
    [
      '2 years',
      365 * 86400,
      $this
        ->createTimestamp('2011-12-11 10:07:08'),
      $request_time,
    ],
    [
      '2 years',
      365 * 86400,
      $this
        ->createTimestamp('2011-12-09 10:09:08'),
      $request_time,
    ],
    [
      '2 years 2 months',
      30 * 86400,
      $this
        ->createTimestamp('2011-10-09 08:07:06'),
      $request_time,
      $granularity_3,
    ],
    [
      '2 years 2 months',
      30 * 86400,
      $this
        ->createTimestamp('2011-10-09 08:07:06'),
      $request_time,
      $granularity_4,
    ],
    [
      '10 years',
      365 * 86400,
      $this
        ->createTimestamp('2003-12-11 10:09:08'),
      $request_time,
    ],
    [
      '100 years',
      365 * 86400,
      $this
        ->createTimestamp('1913-12-11 10:09:08'),
      $request_time,
    ],
    // Checks the non-strict option vs. strict (default).
    [
      '1 second',
      1,
      $this
        ->createTimestamp('2013-12-11 10:09:08'),
      $this
        ->createTimestamp('2013-12-11 10:09:07'),
      $non_strict,
    ],
    [
      '0 seconds',
      0,
      $this
        ->createTimestamp('2013-12-11 10:09:08'),
      $this
        ->createTimestamp('2013-12-11 10:09:07'),
    ],
    // Checks granularity limit.
    [
      '2 years 3 months 1 week',
      7 * 86400,
      $this
        ->createTimestamp('2011-08-30 11:15:57'),
      $request_time,
      $granularity_3,
    ],
  ];
  return $data;
}