diff --git a/core/modules/datetime/datetime.install b/core/modules/datetime/datetime.install new file mode 100644 index 0000000..09dd22a --- /dev/null +++ b/core/modules/datetime/datetime.install @@ -0,0 +1,25 @@ +format("Y-m-d\TH:i:s") . 'Z'; + $iso_date = $date->format("Y-m-d\TH:i:sP", array('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 f07d564..1de9601 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php +++ b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php @@ -68,7 +68,7 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) 'value' => array( 'description' => 'The date value.', 'type' => 'varchar', - 'length' => 20, + 'length' => 25, ), ), 'indexes' => array( diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/src/Tests/DateTimeFieldTest.php index bd9e3af..0f7d570 100644 --- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php @@ -162,7 +162,7 @@ function testDateField() { case 'format_type': // Verify that a date is displayed. $expected = format_date($date->getTimestamp(), $new_value); - $expected_iso = format_date($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); + $expected_iso = format_date($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:sP', 'UTC'); $this->renderTestEntity($id); $this->assertFieldByXPath('//time[@datetime="' . $expected_iso . '"]', $expected, SafeMarkup::format('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', array('%value' => $new_value, '%expected' => $expected, '%expected_iso' => $expected_iso))); break; @@ -292,7 +292,7 @@ function testDatetimeField() { case 'format_type': // Verify that a date is displayed. $expected = format_date($date->getTimestamp(), $new_value); - $expected_iso = format_date($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); + $expected_iso = format_date($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:sP', 'UTC'); $this->renderTestEntity($id); $this->assertFieldByXPath('//time[@datetime="' . $expected_iso . '"]', $expected, SafeMarkup::format('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', array('%value' => $new_value, '%expected' => $expected, '%expected_iso' => $expected_iso))); break; diff --git a/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php b/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php index bba2c33..7f015fd 100644 --- a/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php +++ b/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\datetime\Kernel; +use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemInterface; use Drupal\entity_test\Entity\EntityTest; @@ -50,7 +51,7 @@ protected function setUp() { public function testDateTimeItem() { // Verify entity creation. $entity = EntityTest::create(); - $value = '2014-01-01T20:00:00Z'; + $value = '2014-01-01T20:00:00+00:00'; $entity->field_datetime = $value; $entity->name->value = $this->randomMachineName(); $entity->save(); @@ -85,7 +86,7 @@ public function testDateTimeItem() { public function testSetValue() { // Test DateTimeItem::setValue() using string. $entity = EntityTest::create(); - $value = '2014-01-01T20:00:00Z'; + $value = '2014-01-01T20:00:00+00:00'; $entity->get('field_datetime')->set(0, $value); $entity->save(); // Load the entity and ensure the field was saved correctly. @@ -110,7 +111,7 @@ public function testSetValue() { public function testSetValueProperty() { // Test Date::setValue(). $entity = EntityTest::create(); - $value = '2014-01-01T20:00:00Z'; + $value = '2014-01-01T20:00:00+00:00'; $entity->set('field_datetime', $value); $entity->save(); @@ -120,4 +121,22 @@ public function testSetValueProperty() { $this->assertEqual($entity->field_datetime[0]->value, $value, '"Value" property can be set directly.'); } + /** + * Tests setting the value with setDateTime() + */ + public function testSetDateTime() { + $entity = EntityTest::create(); + $value = '2014-01-01T20:00:00+00:00'; + // 'c' isn't a valid format string per http://php.net/manual/en/datetime.createfromformat.php + // so build the format string from the parts. + $datetime = DrupalDateTime::createFromFormat('Y-m-d\TH:i:sP', $value); + $date_item = $entity->get('field_datetime')->appendItem(); + $date_item->get('value')->setDateTime($datetime); + $entity->save(); + + $id = $entity->id(); + $entity = entity_load('entity_test', $id); + $this->assertEqual($entity->field_datetime[0]->value, $value, '"Value" property can be set from DrupalDateTime object.'); + } + } diff --git a/core/modules/rdf/tests/src/Kernel/Field/DateTimeFieldRdfaTest.php b/core/modules/rdf/tests/src/Kernel/Field/DateTimeFieldRdfaTest.php index 012b57d..31cd298 100644 --- a/core/modules/rdf/tests/src/Kernel/Field/DateTimeFieldRdfaTest.php +++ b/core/modules/rdf/tests/src/Kernel/Field/DateTimeFieldRdfaTest.php @@ -21,7 +21,7 @@ class DateTimeFieldRdfaTest extends FieldRdfaTestBase { * * @var string */ - protected $testValue = '2014-01-28T06:01:01'; + protected $testValue = '2014-01-28T06:01:01+00:00'; /** * {@inheritdoc} @@ -48,6 +48,6 @@ protected function setUp() { * Tests the default formatter. */ public function testDefaultFormatter() { - $this->assertFormatterRdfa(array('type' => 'datetime_default'), 'http://schema.org/dateCreated', array('value' => $this->testValue . 'Z', 'type' => 'literal', 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime')); + $this->assertFormatterRdfa(array('type' => 'datetime_default'), 'http://schema.org/dateCreated', array('value' => $this->testValue, 'type' => 'literal', 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime')); } }