Issue #2911149 by quietone, Jo Fitzgerald, heddn, cogent, mikelutz: FormatDate process plugin doesn't handle zero values
parent
978c9e1cc3
commit
0b2393d89c
|
@ -82,7 +82,8 @@ use Drupal\migrate\Row;
|
|||
* @endcode
|
||||
*
|
||||
* If the source value was '2004-12-19T10:19:42-0600' the transformed value
|
||||
* would be 2004-12-19T10:19:42.
|
||||
* would be 2004-12-19T10:19:42. Set validate_format to false if your source
|
||||
* value is '0000-00-00 00:00:00'.
|
||||
*
|
||||
* @see \DateTime::createFromFormat()
|
||||
* @see \Drupal\Component\Datetime\DateTimePlus::__construct()
|
||||
|
@ -99,7 +100,7 @@ class FormatDate extends ProcessPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
if (empty($value)) {
|
||||
if (empty($value) && $value !== '0' && $value !== 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
|
@ -189,6 +189,42 @@ class FormatDateTest extends MigrateProcessTestCase {
|
|||
// converted from Australia/Sydney to America/Managua timezone.
|
||||
'expected' => '2004-12-18 17:19:42 America/Managua',
|
||||
],
|
||||
'integer_0' => [
|
||||
'configuration' => [
|
||||
'from_format' => 'U',
|
||||
'to_format' => 'Y-m-d',
|
||||
],
|
||||
'value' => 0,
|
||||
'expected' => '1970-01-01',
|
||||
],
|
||||
'string_0' => [
|
||||
'configuration' => [
|
||||
'from_format' => 'U',
|
||||
'to_format' => 'Y-m-d',
|
||||
],
|
||||
'value' => '0',
|
||||
'expected' => '1970-01-01',
|
||||
],
|
||||
'zeros' => [
|
||||
'configuration' => [
|
||||
'from_format' => 'Y-m-d H:i:s',
|
||||
'to_format' => 'Y-m-d H:i:s e',
|
||||
'settings' => ['validate_format' => FALSE],
|
||||
],
|
||||
'value' => '0000-00-00 00:00:00',
|
||||
'expected' => '-0001-11-30 00:00:00 Australia/Sydney',
|
||||
],
|
||||
'zeros_same_timezone' => [
|
||||
'configuration' => [
|
||||
'from_format' => 'Y-m-d H:i:s',
|
||||
'to_format' => 'Y-m-d H:i:s',
|
||||
'settings' => ['validate_format' => FALSE],
|
||||
'from_timezone' => 'UTC',
|
||||
'to_timezone' => 'UTC',
|
||||
],
|
||||
'value' => '0000-00-00 00:00:00',
|
||||
'expected' => '-0001-11-30 00:00:00',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue