diff --git a/core/modules/datetime/src/Tests/DateTestBase.php b/core/modules/datetime/src/Tests/DateTestBase.php index 5c476a0..07e1d0e 100644 --- a/core/modules/datetime/src/Tests/DateTestBase.php +++ b/core/modules/datetime/src/Tests/DateTestBase.php @@ -196,9 +196,8 @@ protected function setSiteTimezone($timezone) { */ protected function massageTestDate($date) { if ($this->field->getSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) { - // Mirror what \Drupal\datetime\DateTimeComputed::getValue() does to - // date-only items. - $date->setTime(12, 0, 0); + // Set the default time for date-only items. + DateTimeItem::setDefaultDateTime($date); } } diff --git a/core/modules/datetime/tests/src/Functional/DateTestBase.php b/core/modules/datetime/tests/src/Functional/DateTestBase.php index 369e793..d440ec9 100644 --- a/core/modules/datetime/tests/src/Functional/DateTestBase.php +++ b/core/modules/datetime/tests/src/Functional/DateTestBase.php @@ -181,4 +181,20 @@ protected function setSiteTimezone($timezone) { ->save(); } + /** + * Massages test date values. + * + * If a date object is generated directly by a test, then it needs to be + * adjusted to behave like the computed date from the item. + * + * @param \Drupal\Core\Datetime\DrupalDateTime $date + * A date object directly generated by the test. + */ + protected function massageTestDate($date) { + if ($this->field->getSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) { + // Set the default time for date-only items. + DateTimeItem::setDefaultDateTime($date); + } + } + }