function DateTimeHandlerTestBase::getRelativeDateValuesFromTimestamp

Same name and namespace in other branches
  1. 9 core/modules/datetime/tests/src/Kernel/Views/DateTimeHandlerTestBase.php \Drupal\Tests\datetime\Kernel\Views\DateTimeHandlerTestBase::getRelativeDateValuesFromTimestamp()
  2. 10 core/modules/datetime/tests/src/Kernel/Views/DateTimeHandlerTestBase.php \Drupal\Tests\datetime\Kernel\Views\DateTimeHandlerTestBase::getRelativeDateValuesFromTimestamp()
  3. 11.x core/modules/datetime/tests/src/Kernel/Views/DateTimeHandlerTestBase.php \Drupal\Tests\datetime\Kernel\Views\DateTimeHandlerTestBase::getRelativeDateValuesFromTimestamp()

Returns an array formatted date_only values relative to timestamp.

Parameters

int $timestamp: Unix Timestamp used as 'today'.

Return value

array An array of DateTimeItemInterface::DATE_STORAGE_FORMAT date values. In order tomorrow, today and yesterday.

4 calls to DateTimeHandlerTestBase::getRelativeDateValuesFromTimestamp()
FilterDateTest::setUp in core/modules/datetime_range/tests/src/Kernel/Views/FilterDateTest.php
Create nodes with relative date range of: yesterday - today, today - today, and today - tomorrow.
FilterDateTest::setUp in core/modules/datetime/tests/src/Kernel/Views/FilterDateTest.php
Create nodes with relative dates of yesterday, today, and tomorrow.
FilterDateTest::testDateIs in core/modules/datetime/tests/src/Kernel/Views/FilterDateTest.php
Test date filter with date-only fields.
FilterDateTest::testDateOffsets in core/modules/datetime/tests/src/Kernel/Views/FilterDateTest.php
Test offsets with date-only fields.

File

core/modules/datetime/tests/src/Kernel/Views/DateTimeHandlerTestBase.php, line 130

Class

DateTimeHandlerTestBase
Base class for testing datetime handlers.

Namespace

Drupal\Tests\datetime\Kernel\Views

Code

protected function getRelativeDateValuesFromTimestamp($timestamp) {
    return [
        // Tomorrow.
\Drupal::service('date.formatter')->format($timestamp + 86400, 'custom', DateTimeItemInterface::DATE_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE),
        // Today.
\Drupal::service('date.formatter')->format($timestamp, 'custom', DateTimeItemInterface::DATE_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE),
        // Yesterday.
\Drupal::service('date.formatter')->format($timestamp - 86400, 'custom', DateTimeItemInterface::DATE_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE),
    ];
}

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