You are here

public function DateTimeFromStringEnhancer::postProcess in JSON:API Extras 8

Apply the last transformations to the output value of a single field.

Parameters

mixed $value: The value to be processed after being prepared for output.

Return value

mixed The value after being post processed.

Overrides DateTimeEnhancerBase::postProcess

File

src/Plugin/jsonapi/FieldEnhancer/DateTimeFromStringEnhancer.php, line 21

Class

DateTimeFromStringEnhancer
Perform additional manipulations to datetime fields.

Namespace

Drupal\jsonapi_extras\Plugin\jsonapi\FieldEnhancer

Code

public function postProcess($value) {
  $storage_timezone = new \DateTimezone(DATETIME_STORAGE_TIMEZONE);
  $date = new \DateTime($value, $storage_timezone);
  $configuration = $this
    ->getConfiguration();
  $output_timezone = new \DateTimezone(drupal_get_user_timezone());
  $date
    ->setTimezone($output_timezone);
  return $date
    ->format($configuration['dateTimeFormat']);
}