diff --git a/core/modules/datetime/src/DateTimeComputed.php b/core/modules/datetime/src/DateTimeComputed.php index cf7ad01..1e0882b 100644 --- a/core/modules/datetime/src/DateTimeComputed.php +++ b/core/modules/datetime/src/DateTimeComputed.php @@ -2,6 +2,7 @@ namespace Drupal\datetime; +use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\TypedData\DataDefinitionInterface; use Drupal\Core\TypedData\TypedDataInterface; @@ -18,7 +19,7 @@ class DateTimeComputed extends TypedData { /** * Cached computed date. * - * @var \Drupal\Core\Datetime\DrupalDateTime|null + * @var \DateTime|null */ protected $date = NULL; @@ -45,12 +46,20 @@ public function getValue($langcode = NULL) { $value = $item->{($this->definition->getSetting('date source'))}; $datetime_type = $item->getFieldDefinition()->getSetting('datetime_type'); - $storage_format = $datetime_type === 'date' ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT; + $storage_format = $datetime_type === DateTimeItem::DATETIME_TYPE_DATE ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT; try { $date = DrupalDateTime::createFromFormat($storage_format, $value, DATETIME_STORAGE_TIMEZONE); if ($date instanceof DrupalDateTime && !$date->hasErrors()) { $this->date = $date; - if ($datetime_type === 'date') { + // If the format did not include an explicit time portion, then the + // time will be set from the current time instead. For consistency, we + // we the time to 12:00:00 UTC. This is use so that the local date + // portion is the same, across nearly all time zones. + // @see datetime_date_default_time() + // @see http://php.net/manual/en/datetime.createfromformat.php + // @todo Update comment and/or code when per the chosen solution in + // https://www.drupal.org/node/2830094 + if ($datetime_type === DateTimeItem::DATETIME_TYPE_DATE) { $this->date->setTime(12, 0, 0); } }