Unverified Commit 5837e8d4 authored by ndobromirov's avatar ndobromirov Committed by Mateu Aguiló Bosch

Issue #2953227 by ndobromirov, vtcore, e0ipso: Date Time enhancer does not...

Issue #2953227 by ndobromirov, vtcore, e0ipso: Date Time enhancer does not work with Date range fields
parent cc4a2e10
......@@ -20,28 +20,63 @@ class DateTimeFromStringEnhancer extends DateTimeEnhancerBase {
* {@inheritdoc}
*/
protected function doUndoTransform($data, Context $context) {
$storage_timezone = new \DateTimezone(DATETIME_STORAGE_TIMEZONE);
$date = new \DateTime($data, $storage_timezone);
$configuration = $this->getConfiguration();
$output_timezone = new \DateTimezone(drupal_get_user_timezone());
$date->setTimezone($output_timezone);
$reformat = function ($input) use ($configuration) {
$storage_timezone = new \DateTimezone(DATETIME_STORAGE_TIMEZONE);
$date = new \DateTime($input, $storage_timezone);
$output_timezone = new \DateTimezone(drupal_get_user_timezone());
$date->setTimezone($output_timezone);
$output = $date->format($configuration['dateTimeFormat']);
return $output;
};
return $date->format($configuration['dateTimeFormat']);
$result = is_array($data) ? array_map($reformat, $data) : $reformat($data);
return $result;
}
/**
* {@inheritdoc}
*/
protected function doTransform($data, Context $context) {
$date = new \DateTime($data);
$reformat = function ($input) {
$date = new \DateTime($input);
// Adjust the date for storage.
$storage_timezone = new \DateTimezone(DATETIME_STORAGE_TIMEZONE);
$date->setTimezone($storage_timezone);
$output = $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
return $output;
};
// Adjust the date for storage.
$storage_timezone = new \DateTimezone(DATETIME_STORAGE_TIMEZONE);
$date->setTimezone($storage_timezone);
$result = is_array($data) ? array_map($reformat, $data) : $reformat($data);
return $result;
}
/**
* {@inheritdoc}
*/
public function getOutputJsonSchema() {
$baseType = parent::getOutputJsonSchema();
return $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
return [
"anyOf" => [
$baseType,
["type" => "array", "items" => $baseType],
[
"type" => "object",
"properties" => [
"value" => $baseType,
"end_value" => $baseType,
],
],
],
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment