You are here

protected function NormalizerTestBase::formatExpectedTimestampItemValues in Replication 8.2

Formats a UNIX timestamp.

This is copied from \Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait in Drupal 8.4.x.

Depending on the 'bc_timestamp_normalizer_unix' setting. The return will be an RFC3339 date string or the same timestamp that was passed in.

Parameters

int $timestamp: The timestamp value to format.

Return value

string|int The formatted RFC3339 date string or UNIX timestamp.

See also

\Drupal\serialization\Normalizer\TimestampItemNormalizer

4 calls to NormalizerTestBase::formatExpectedTimestampItemValues()
ContentEntityNormalizerTest::testNormalizer in tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php
EntityReferenceItemNormalizerTest::testUserReferenceFieldNormalization in tests/src/Unit/Normalizer/EntityReferenceItemNormalizerTest.php
Tests normalization of entity reference fields that reference users.
FileEntityNormalizerTest::testNormalizer in tests/src/Unit/Normalizer/FileEntityNormalizerTest.php
Tests using entity fields of the file field type.
LinkItemNormalizerTest::testLinkFieldNormalization in tests/src/Unit/Normalizer/LinkItemNormalizerTest.php
Tests field link normalization.

File

tests/src/Unit/Normalizer/NormalizerTestBase.php, line 89

Class

NormalizerTestBase

Namespace

Drupal\Tests\replication\Unit\Normalizer

Code

protected function formatExpectedTimestampItemValues($timestamp) {
  $date = new \DateTime();
  $date
    ->setTimestamp($timestamp);
  $date
    ->setTimezone(new \DateTimeZone('UTC'));

  // Format is also added to the expected return values.
  return [
    'value' => $date
      ->format(\DateTime::RFC3339),
    'format' => \DateTime::RFC3339,
  ];
}