Skip to content
Snippets Groups Projects
Unverified Commit 0b2393d8 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2911149 by quietone, Jo Fitzgerald, heddn, cogent, mikelutz: FormatDate...

Issue #2911149 by quietone, Jo Fitzgerald, heddn, cogent, mikelutz: FormatDate process plugin doesn't handle zero values
parent 978c9e1c
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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()
......@@ -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 @@ 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',
],
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment