diff --git a/core/modules/datetime/src/DateTimeComputed.php b/core/modules/datetime/src/DateTimeComputed.php index d6f5e5a..f0ba5f1 100644 --- a/core/modules/datetime/src/DateTimeComputed.php +++ b/core/modules/datetime/src/DateTimeComputed.php @@ -3,11 +3,11 @@ namespace Drupal\datetime; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem; +use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\TypedData\DataDefinitionInterface; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\Core\TypedData\TypedData; -use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; /** * A computed property for dates of date time field items. @@ -47,13 +47,14 @@ public function getValue() { $value = $item->{($this->definition->getSetting('date source'))}; $datetime_type = $item->getFieldDefinition()->getSetting('datetime_type'); - if ($item->getFieldDefinition()->getSetting('datetime_type') === 'date') { + if ($item->getFieldDefinition()->getSetting('datetime_type') === DateTimeItem::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); + // Strip off an explicit time zone offset from the format and replace + // with the time zone offset placeholder to allow the string to be parsed + // properly. + $storage_format = preg_replace('/\\\+\d\d\:\d\d$/', 'P', DateTimeItemInterface::DATETIME_STORAGE_FORMAT); } try { diff --git a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItemInterface.php b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItemInterface.php index 7171233..ae0343e 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+00:00'; + const 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/tests/src/Kernel/DateTimeItemTest.php b/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php index 75f892a..dc145b1 100644 --- a/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php +++ b/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php @@ -69,7 +69,7 @@ public function testDateTime() { // Verify entity creation. $entity = EntityTest::create(); - $value = '2014-01-01T20:00:00'; + $value = '2014-01-01T20:00:00+00:00'; $entity->field_datetime = $value; $entity->name->value = $this->randomMachineName(); $this->entityValidateAndSave($entity); @@ -84,7 +84,7 @@ public function testDateTime() { $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); // Verify changing the date value. - $new_value = '2016-11-04T00:21:00'; + $new_value = '2016-11-04T00:21:00+00:00'; $entity->field_datetime->value = $new_value; $this->assertEqual($entity->field_datetime->value, $new_value); $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); @@ -164,7 +164,7 @@ public function testSetValue() { // Test DateTimeItem::setValue() using string. $entity = EntityTest::create(); - $value = '2014-01-01T20:00:00'; + $value = '2014-01-01T20:00:00+00:00'; $entity->get('field_datetime')->set(0, $value); $this->entityValidateAndSave($entity); // Load the entity and ensure the field was saved correctly. @@ -175,7 +175,7 @@ public function testSetValue() { // Test DateTimeItem::setValue() using property array. $entity = EntityTest::create(); - $value = '2014-01-01T20:00:00'; + $value = '2014-01-01T20:00:00+00:00'; $entity->set('field_datetime', $value); $this->entityValidateAndSave($entity); // Load the entity and ensure the field was saved correctly. @@ -220,7 +220,7 @@ public function testSetValueProperty() { $this->fieldStorage->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATETIME); $this->fieldStorage->save(); $entity = EntityTest::create(); - $value = '2014-01-01T20:00:00'; + $value = '2014-01-01T20:00:00+00:00'; $entity->set('field_datetime', $value); $this->entityValidateAndSave($entity); @@ -269,10 +269,10 @@ public function datetimeValidationProvider() { return [ // Valid ISO 8601 dates, but unsupported by DateTimeItem. ['2014-01-01T20:00:00Z'], - ['2014-01-01T20:00:00+04:00'], ['2014-01-01T20:00:00+0400'], ['2014-01-01T20:00:00+04'], ['2014-01-01T20:00:00.123'], + ['2014-01-01T20:00:00'], ['2014-01-01T200000'], ['2014-01-01T2000'], ['2014-01-01T20'],