You are here

protected function TimeStampItemNormalizerTrait::processNormalizedValues in Drupal 8

Processes normalized timestamp values to add a formatted date and format.

Parameters

array $normalized: The normalized field data to process.

Return value

array The processed data.

File

core/modules/serialization/src/Normalizer/TimeStampItemNormalizerTrait.php, line 44

Class

TimeStampItemNormalizerTrait
A trait for TimestampItem normalization functionality.

Namespace

Drupal\serialization\Normalizer

Code

protected function processNormalizedValues(array $normalized) {

  // Use a RFC 3339 timestamp with the time zone set to UTC to replace the
  // timestamp value.
  $date = new \DateTime();
  $date
    ->setTimestamp($normalized['value']);
  $date
    ->setTimezone(new \DateTimeZone('UTC'));
  $normalized['value'] = $date
    ->format(\DateTime::RFC3339);

  // 'format' is not a property on TimestampItem fields. This is present to
  // assist consumers of this data.
  $normalized['format'] = \DateTime::RFC3339;
  return $normalized;
}