function TimestampFormatterWithTimeDiffViewsTest::getRowData

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/FunctionalJavascriptTests/Core/Field/TimestampFormatterWithTimeDiffViewsTest.php \Drupal\FunctionalJavascriptTests\Core\Field\TimestampFormatterWithTimeDiffViewsTest::getRowData()

Provides data for view rows.

Return value

array[] A list of row data.

1 call to TimestampFormatterWithTimeDiffViewsTest::getRowData()
TimestampFormatterWithTimeDiffViewsTest::testTimestampFormatterWithTimeDiff in core/tests/Drupal/FunctionalJavascriptTests/Core/Field/TimestampFormatterWithTimeDiffViewsTest.php
Tests the timestamp formatter used with time difference setting in views.

File

core/tests/Drupal/FunctionalJavascriptTests/Core/Field/TimestampFormatterWithTimeDiffViewsTest.php, line 81

Class

TimestampFormatterWithTimeDiffViewsTest
Tests the timestamp formatter used with time difference setting in views.

Namespace

Drupal\FunctionalJavascriptTests\Core\Field

Code

protected function getRowData() : array {
  $now = \Drupal::time()->getRequestTime();
  return [
    // One year ago.
[
      'pattern' => '1 year ago',
      'timestamp' => $now - 60 * 60 * 24 * 365,
    ],
    // One month ago.
[
      'pattern' => '1 month ago',
      'timestamp' => $now - 60 * 60 * 24 * 30,
    ],
    // One week ago.
[
      'pattern' => '1 week ago',
      'timestamp' => $now - 60 * 60 * 24 * 7,
    ],
    // One day ago.
[
      'pattern' => '1 day ago',
      'timestamp' => $now - 60 * 60 * 24,
    ],
    // One hour ago.
[
      'pattern' => '1 hour ago',
      'timestamp' => $now - 60 * 60,
    ],
    // One minute ago.
[
      'pattern' => '\\d+ minute[s]?(?: \\d+ second[s]?)? ago',
      'timestamp' => $now - 60,
    ],
    // One minute hence.
[
      'pattern' => '\\d+ second[s]?[ hence]?',
      'timestamp' => $now + 60,
    ],
    // One hour hence.
[
      'pattern' => '59 minutes \\d+ second[s]? hence',
      'timestamp' => $now + 60 * 60,
    ],
    // One day hence.
[
      'pattern' => '23 hours 59 minutes hence',
      'timestamp' => $now + 60 * 60 * 24,
    ],
    // One week hence.
[
      'pattern' => '6 days 23 hours hence',
      'timestamp' => $now + 60 * 60 * 24 * 7,
    ],
    // A little more than 1 year hence (one year + 1 hour).
[
      'pattern' => '1 year hence',
      'timestamp' => $now + 60 * 60 * 24 * 365 + 60 * 60,
    ],
    // Right now.
[
      'pattern' => '\\d+ second[s]?[ ago]?',
      'timestamp' => $now,
    ],
  ];
}

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