diff --git a/src/Plugin/jsonapi/FieldEnhancer/DateTimeFromStringEnhancer.php b/src/Plugin/jsonapi/FieldEnhancer/DateTimeFromStringEnhancer.php index 2378f79a87f84eab2788ce38cd01746a8510b015..b5105ff9d17ad40bc5804cbea6e6efd818c15161 100644 --- a/src/Plugin/jsonapi/FieldEnhancer/DateTimeFromStringEnhancer.php +++ b/src/Plugin/jsonapi/FieldEnhancer/DateTimeFromStringEnhancer.php @@ -19,6 +19,20 @@ class DateTimeFromStringEnhancer extends DateTimeEnhancerBase { * {@inheritdoc} */ public function postProcess($value) { + if (is_array($value)) { + return array_map([$this, 'processSingleValue'], $value); + } + + return $this->processSingleValue($value); + } + + /** + * Process a single value + * + * @param $value + * @return string + */ + protected function processSingleValue($value) { $storage_timezone = new \DateTimezone(DATETIME_STORAGE_TIMEZONE); $date = new \DateTime($value, $storage_timezone); @@ -34,6 +48,20 @@ class DateTimeFromStringEnhancer extends DateTimeEnhancerBase { * {@inheritdoc} */ public function prepareForInput($value) { + if (is_array($value)) { + return array_map([$this, 'prepareSingleValue'], $value); + } + + return $this->prepareSingleValue($value); + } + + /** + * Prepare a single value for input. + * + * @param $value + * @return string + */ + protected function prepareSingleValue($value) { $date = new \DateTime($value); // Adjust the date for storage.