class TimestampNormalizer
Same name in other branches
- 8.9.x core/modules/serialization/src/Normalizer/TimestampNormalizer.php \Drupal\serialization\Normalizer\TimestampNormalizer
- 10 core/modules/serialization/src/Normalizer/TimestampNormalizer.php \Drupal\serialization\Normalizer\TimestampNormalizer
- 11.x core/modules/serialization/src/Normalizer/TimestampNormalizer.php \Drupal\serialization\Normalizer\TimestampNormalizer
Converts values for the Timestamp data type to and from common formats.
@internal
Note that \Drupal\Core\TypedData\Plugin\DataType\Timestamp::getDateTime() explicitly sets a default timezone of UTC. This ensures the string representation generated by DateTimeNormalizer::normalize() is also in UTC.
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, \Drupal\serialization\Normalizer\CacheableNormalizerInterface, \Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\serialization\Normalizer\DateTimeNormalizer extends \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
- class \Drupal\serialization\Normalizer\TimestampNormalizer extends \Drupal\serialization\Normalizer\DateTimeNormalizer
- class \Drupal\serialization\Normalizer\DateTimeNormalizer extends \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
Expanded class hierarchy of TimestampNormalizer
1 file declares its use of TimestampNormalizer
- TimestampNormalizerTest.php in core/
modules/ serialization/ tests/ src/ Unit/ Normalizer/ TimestampNormalizerTest.php
1 string reference to 'TimestampNormalizer'
- serialization.services.yml in core/
modules/ serialization/ serialization.services.yml - core/modules/serialization/serialization.services.yml
1 service uses TimestampNormalizer
- serializer.normalizer.timestamp in core/
modules/ serialization/ serialization.services.yml - Drupal\serialization\Normalizer\TimestampNormalizer
File
-
core/
modules/ serialization/ src/ Normalizer/ TimestampNormalizer.php, line 16
Namespace
Drupal\serialization\NormalizerView source
class TimestampNormalizer extends DateTimeNormalizer {
/**
* {@inheritdoc}
*/
protected $allowedFormats = [
'UNIX timestamp' => 'U',
'ISO 8601' => \DateTime::ISO8601,
'RFC 3339' => \DateTime::RFC3339,
];
/**
* {@inheritdoc}
*/
protected $supportedInterfaceOrClass = Timestamp::class;
/**
* {@inheritdoc}
*/
protected function getNormalizationTimezone() {
return new \DateTimeZone('UTC');
}
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = []) {
$denormalized = parent::denormalize($data, $class, $format, $context);
return $denormalized->getTimestamp();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY | constant | Name of key for bubbling cacheability metadata via serialization context. | |||
DateTimeNormalizer::$systemDateConfig | protected | property | The system's date configuration. | ||
DateTimeNormalizer::hasCacheableSupportsMethod | public | function | Overrides NormalizerBase::hasCacheableSupportsMethod | ||
DateTimeNormalizer::normalize | public | function | 1 | ||
DateTimeNormalizer::__construct | public | function | Constructs a new DateTimeNormalizer instance. | ||
NormalizerBase::$format | protected | property | List of formats which supports (de-)normalization. | 3 | |
NormalizerBase::addCacheableDependency | protected | function | Adds cacheability if applicable. | ||
NormalizerBase::checkFormat | protected | function | Checks if the provided format is supported by this normalizer. | 1 | |
NormalizerBase::supportsDenormalization | public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() | 1 | |
NormalizerBase::supportsNormalization | public | function | 1 | ||
TimestampNormalizer::$allowedFormats | protected | property | Allowed datetime formats for the denormalizer. | Overrides DateTimeNormalizer::$allowedFormats | |
TimestampNormalizer::$supportedInterfaceOrClass | protected | property | The interface or class that this Normalizer supports. | Overrides DateTimeNormalizer::$supportedInterfaceOrClass | |
TimestampNormalizer::denormalize | public | function | Overrides DateTimeNormalizer::denormalize | ||
TimestampNormalizer::getNormalizationTimezone | protected | function | Gets the timezone to be used during normalization. | Overrides DateTimeNormalizer::getNormalizationTimezone |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.