SmartDateNormalizer.php in Smart Date 3.1.x
File
src/Normalizer/SmartDateNormalizer.php
View source
<?php
namespace Drupal\smart_date\Normalizer;
use Drupal\hal\Normalizer\TimestampItemNormalizer;
use Drupal\smart_date\Plugin\Field\FieldType\SmartDateItem;
use DateTimeZone;
use DateTime;
class SmartDateNormalizer extends TimestampItemNormalizer {
protected $supportedInterfaceOrClass = SmartDateItem::class;
public function denormalize($data, $class, $format = NULL, array $context = []) {
$field = parent::denormalize($data, $class, $format, $context);
$timezone = new DateTimeZone('UTC');
$date = DateTime::createFromFormat($data['format'], $data['end_value'], $timezone);
$field
->get('end_value')
->setValue($date
->getTimestamp());
return $field;
}
}