Loading core/modules/migrate/src/Plugin/migrate/process/FormatDate.php +3 −2 Original line number Diff line number Diff line Loading @@ -82,7 +82,8 @@ * @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() Loading @@ -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 ''; } Loading core/modules/migrate/tests/src/Unit/process/FormatDateTest.php +36 −0 Original line number Diff line number Diff line Loading @@ -189,6 +189,42 @@ public function datesDataProvider() { // 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 Loading
core/modules/migrate/src/Plugin/migrate/process/FormatDate.php +3 −2 Original line number Diff line number Diff line Loading @@ -82,7 +82,8 @@ * @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() Loading @@ -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 ''; } Loading
core/modules/migrate/tests/src/Unit/process/FormatDateTest.php +36 −0 Original line number Diff line number Diff line Loading @@ -189,6 +189,42 @@ public function datesDataProvider() { // 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