trait BcTimestampNormalizerUnixTestTrait
Same name in other branches
- 8.9.x core/modules/rest/tests/src/Functional/BcTimestampNormalizerUnixTestTrait.php \Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait
Trait for ResourceTestBase subclasses formatting expected timestamp data.
Hierarchy
- trait \Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait
File
-
core/
modules/ rest/ tests/ src/ Functional/ BcTimestampNormalizerUnixTestTrait.php, line 10
Namespace
Drupal\Tests\rest\FunctionalView source
trait BcTimestampNormalizerUnixTestTrait {
/**
* Formats a UNIX timestamp.
*
* @param int $timestamp
* The timestamp value to format.
*
* @return string
* The formatted RFC3339 date string.
*
* @see \Drupal\serialization\Normalizer\TimestampItemNormalizer
*/
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,
];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
BcTimestampNormalizerUnixTestTrait::formatExpectedTimestampItemValues | protected | function | Formats a UNIX timestamp. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.