// DrupalDateTime object at this point. We need to convert it back to the
// storage timezone and format.
$datetime_type =
$this->
getFieldSetting('datetime_type'
);
if ($datetime_type === DateTimeItem::DATETIME_TYPE_DATE
) { $storage_format = DateTimeItemInterface::DATE_STORAGE_FORMAT;
} else { $storage_format = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
} $storage_timezone =
new \
DateTimezone(DateTimeItemInterface::STORAGE_TIMEZONE
);
foreach ($values as &
$item) { if (!
empty($item['value'
]) &&
$item['value'
] instanceof DrupalDateTime
) { /** @var \Drupal\Core\Datetime\DrupalDateTime $date */
$date =
$item['value'
];
// Adjust the date for storage.
$item['value'
] =
$date->
setTimezone($storage_timezone)->
format($storage_format);
} } return $values;
}