diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index 245d0c4..a925706 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -27,7 +27,7 @@ * * @see https://www.drupal.org/node/2912980 */ -const DATETIME_DATETIME_STORAGE_FORMAT = 'Y-m-d\TH:i:s'; +const DATETIME_DATETIME_STORAGE_FORMAT = 'Y-m-d\TH:i:s+00:00'; /** * Defines the format that dates should be stored in. diff --git a/core/modules/datetime/src/DateTimeComputed.php b/core/modules/datetime/src/DateTimeComputed.php index 16f664b..d6f5e5a 100644 --- a/core/modules/datetime/src/DateTimeComputed.php +++ b/core/modules/datetime/src/DateTimeComputed.php @@ -47,7 +47,15 @@ public function getValue() { $value = $item->{($this->definition->getSetting('date source'))}; $datetime_type = $item->getFieldDefinition()->getSetting('datetime_type'); - $storage_format = $datetime_type === DateTimeItem::DATETIME_TYPE_DATE ? DateTimeItemInterface::DATE_STORAGE_FORMAT : DateTimeItemInterface::DATETIME_STORAGE_FORMAT; + if ($item->getFieldDefinition()->getSetting('datetime_type') === 'date') { + $storage_format = DateTimeItemInterface::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 = preg_replace('/\+\d\d\:\d\d$/', 'P', DateTimeItemInterface::DATETIME_STORAGE_FORMAT); + } + try { $date = DrupalDateTime::createFromFormat($storage_format, $value, DateTimeItemInterface::STORAGE_TIMEZONE); if ($date instanceof DrupalDateTime && !$date->hasErrors()) { diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php index a6680f6..1d41688 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php @@ -227,7 +227,7 @@ protected function buildDate(DrupalDateTime $date) { */ protected function buildDateWithIsoAttribute(DrupalDateTime $date) { // Create the ISO date in Universal Time. - $iso_date = $date->format("Y-m-d\TH:i:s") . 'Z'; + $iso_date = $date->format("Y-m-d\TH:i:sP", ['timezone' => 'UTC']); $this->setTimeZone($date); diff --git a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php index 3264069..6528192 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php +++ b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php @@ -69,7 +69,7 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) 'value' => [ 'description' => 'The date value.', 'type' => 'varchar', - 'length' => 20, + 'length' => 25, ], ], 'indexes' => [ diff --git a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItemInterface.php b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItemInterface.php index a9231c6..7171233 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItemInterface.php +++ b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItemInterface.php @@ -15,7 +15,7 @@ /** * Defines the format that date and time should be stored in. */ - const DATETIME_STORAGE_FORMAT = 'Y-m-d\TH:i:s'; + const DATETIME_STORAGE_FORMAT = 'Y-m-d\TH:i:s+00:00'; /** * Defines the format that dates should be stored in.