You are here

protected function DateTimeHandlerTestBase::getUTCEquivalentOfUserNowAsTimestamp in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/datetime/tests/src/Kernel/Views/DateTimeHandlerTestBase.php \Drupal\Tests\datetime\Kernel\Views\DateTimeHandlerTestBase::getUTCEquivalentOfUserNowAsTimestamp()

Returns UTC timestamp of user's TZ 'now'.

The date field stores date_only values without conversion, considering them already as UTC. This method returns the UTC equivalent of user's 'now' as a unix timestamp, so they match using Y-m-d format.

Return value

int Unix timestamp.

4 calls to DateTimeHandlerTestBase::getUTCEquivalentOfUserNowAsTimestamp()
FilterDateTest::setUp in core/modules/datetime/tests/src/Kernel/Views/FilterDateTest.php
Create nodes with relative dates of yesterday, today, and tomorrow.
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::testDateIs in core/modules/datetime/tests/src/Kernel/Views/FilterDateTest.php
Tests date filter with date-only fields.
FilterDateTest::testDateOffsets in core/modules/datetime/tests/src/Kernel/Views/FilterDateTest.php
Tests offsets with date-only fields.

File

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

Class

DateTimeHandlerTestBase
Base class for testing datetime handlers.

Namespace

Drupal\Tests\datetime\Kernel\Views

Code

protected function getUTCEquivalentOfUserNowAsTimestamp() {
  $user_now = new DateTimePlus('now', new \DateTimeZone(date_default_timezone_get()));
  $utc_equivalent = new DateTimePlus($user_now
    ->format('Y-m-d H:i:s'), new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE));
  return $utc_equivalent
    ->getTimestamp();
}