You are here

public function DateTimeNormalizer::normalize in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/serialization/src/Normalizer/DateTimeNormalizer.php \Drupal\serialization\Normalizer\DateTimeNormalizer::normalize()
1 call to DateTimeNormalizer::normalize()
DateTimeIso8601Normalizer::normalize in core/modules/serialization/src/Normalizer/DateTimeIso8601Normalizer.php
Normalizes an object into a set of arrays/scalars.
1 method overrides DateTimeNormalizer::normalize()
DateTimeIso8601Normalizer::normalize in core/modules/serialization/src/Normalizer/DateTimeIso8601Normalizer.php
Normalizes an object into a set of arrays/scalars.

File

core/modules/serialization/src/Normalizer/DateTimeNormalizer.php, line 57

Class

DateTimeNormalizer
Converts values for datetime objects to RFC3339 and from common formats.

Namespace

Drupal\serialization\Normalizer

Code

public function normalize($datetime, $format = NULL, array $context = []) {
  assert($datetime instanceof DateTimeInterface);
  $drupal_date_time = $datetime
    ->getDateTime();
  if ($drupal_date_time === NULL) {
    return $drupal_date_time;
  }
  return $drupal_date_time
    ->setTimezone($this
    ->getNormalizationTimezone())
    ->format(\DateTime::RFC3339);
}