Issue #3095195 by jofitz, Wim Leers, heddn: Drupal 7 date fields configured to not collect the hour/minute/second granularities can have "00" MM or DD attributes

merge-requests/2419/head
webchick 2019-12-20 17:24:07 -08:00
parent 347624ad75
commit 92a0b41fa2
2 changed files with 23 additions and 0 deletions

View File

@ -127,6 +127,13 @@ class FormatDate extends ProcessPluginBase {
}
$settings = isset($this->configuration['settings']) ? $this->configuration['settings'] : [];
// Older versions of Drupal where omitting certain granularities (also known
// as "collected date attributes") resulted in invalid timestamps getting
// stored.
if ($fromFormat === 'Y-m-d\TH:i:s') {
$value = str_replace(['-00-00T', '-00T'], ['-01-01T', '-01T'], $value);
}
// Attempts to transform the supplied date using the defined input format.
// DateTimePlus::createFromFormat can throw exceptions, so we need to
// explicitly check for problems.

View File

@ -229,6 +229,22 @@ class FormatDateTest extends MigrateProcessTestCase {
'value' => '0000-00-00 00:00:00',
'expected' => '-0001-11-30 00:00:00',
],
'collected_date_attributes_day' => [
'configuration' => [
'from_format' => 'Y-m-d\TH:i:s',
'to_format' => 'Y-m-d\TH:i:s',
],
'value' => '2012-01-00T00:00:00',
'expected' => '2012-01-01T00:00:00',
],
'collected_date_attributes_month' => [
'configuration' => [
'from_format' => 'Y-m-d\TH:i:s',
'to_format' => 'Y-m-d\TH:i:s',
],
'value' => '2012-00-00T00:00:00',
'expected' => '2012-01-01T00:00:00',
],
];
}