foreach ($values as &
$item) { if (!
empty($item['value'
]) &&
$item['value'
] instanceof DrupalDateTime
) { /** @var \Drupal\Core\Datetime\DrupalDateTime $start_date */
$start_date =
$item['value'
];
if ($datetime_type === DateRangeItem::DATETIME_TYPE_ALLDAY
) { // All day fields start at midnight on the starting date, but are
// stored like datetime fields, so we need to adjust the time.
// This function is called twice, so to prevent a double conversion
// we need to explicitly set the timezone.
$start_date->
setTimeZone($user_timezone)->
setTime(0, 0, 0
);
} // Adjust the date for storage.
$item['value'
] =
$start_date->
setTimezone($storage_timezone)->
format($storage_format);
} if (!
empty($item['end_value'
]) &&
$item['end_value'
] instanceof DrupalDateTime
) { /** @var \Drupal\Core\Datetime\DrupalDateTime $end_date */
$end_date =
$item['end_value'
];
if ($datetime_type === DateRangeItem::DATETIME_TYPE_ALLDAY
) {