You are here

protected function BcTimestampNormalizerUnixTestTrait::formatExpectedTimestampItemValues in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/rest/tests/src/Functional/BcTimestampNormalizerUnixTestTrait.php \Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait::formatExpectedTimestampItemValues()

Formats a UNIX timestamp.

Parameters

int $timestamp: The timestamp value to format.

Return value

string The formatted RFC3339 date string.

See also

\Drupal\serialization\Normalizer\TimestampItemNormalizer

File

core/modules/rest/tests/src/Functional/BcTimestampNormalizerUnixTestTrait.php, line 23

Class

BcTimestampNormalizerUnixTestTrait
Trait for ResourceTestBase subclasses formatting expected timestamp data.

Namespace

Drupal\Tests\rest\Functional

Code

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

  // Per \Drupal\Core\TypedData\Plugin\DataType\Timestamp::getDateTime(), they
  // default to string representations in the UTC timezone.
  $date
    ->setTimezone(new \DateTimeZone('UTC'));

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