diff --git a/core/modules/datetime/src/DateTimeComputed.php b/core/modules/datetime/src/DateTimeComputed.php index 6939994..b6a1212 100644 --- a/core/modules/datetime/src/DateTimeComputed.php +++ b/core/modules/datetime/src/DateTimeComputed.php @@ -43,7 +43,16 @@ public function getValue($langcode = NULL) { $item = $this->getParent(); $value = $item->{($this->definition->getSetting('date source'))}; - $storage_format = $item->getFieldDefinition()->getSetting('datetime_type') == 'date' ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT; + if ($item->getFieldDefinition()->getSetting('datetime_type') == 'date') { + $storage_format = DATETIME_DATE_STORAGE_FORMAT; + } + else { + // Strip off an explicit time from the format and replace with the + // time zone placeholder to allow the string to be parsed properly. + $storage_format = DATETIME_DATETIME_STORAGE_FORMAT; + $storage_format = preg_replace('/\+\d\d\:\d\d$/', 'P', $storage_format); + } + try { $date = DrupalDateTime::createFromFormat($storage_format, $value, DATETIME_STORAGE_TIMEZONE); if ($date instanceof DrupalDateTime && !$date->hasErrors()) {