You are here

protected function DateTimeEnhancer::doUndoTransform in JSON:API Extras 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/jsonapi/FieldEnhancer/DateTimeEnhancer.php \Drupal\jsonapi_extras\Plugin\jsonapi\FieldEnhancer\DateTimeEnhancer::doUndoTransform()

File

src/Plugin/jsonapi/FieldEnhancer/DateTimeEnhancer.php, line 24

Class

DateTimeEnhancer
Perform additional manipulations to timestamp fields.

Namespace

Drupal\jsonapi_extras\Plugin\jsonapi\FieldEnhancer

Code

protected function doUndoTransform($data, Context $context) {
  $date = new \DateTime();
  $date
    ->setTimestamp(is_int($data) ? $data : (new DrupalDateTime($data))
    ->getTimestamp());
  $configuration = $this
    ->getConfiguration();
  return $date
    ->format($configuration['dateTimeFormat']);
}