TimestampNormalizer.php in Drupal 8
File
core/modules/serialization/src/Normalizer/TimestampNormalizer.php
View source
<?php
namespace Drupal\serialization\Normalizer;
use Drupal\Core\TypedData\Plugin\DataType\Timestamp;
class TimestampNormalizer extends DateTimeNormalizer {
protected $allowedFormats = [
'UNIX timestamp' => 'U',
'ISO 8601' => \DateTime::ISO8601,
'RFC 3339' => \DateTime::RFC3339,
];
protected $supportedInterfaceOrClass = Timestamp::class;
protected function getNormalizationTimezone() {
return new \DateTimeZone('UTC');
}
public function denormalize($data, $class, $format = NULL, array $context = []) {
$denormalized = parent::denormalize($data, $class, $format, $context);
return $denormalized
->getTimestamp();
}
}