In my Migration from Joomla to Drupal the format_date plugin failed.

  created:
    -
      plugin: format_date
      from_format: 'Y-m-d TH:i:s'
      to_format: 'Y-m-d\TH:i:s'
      source: created

With the error "Format date plugin could not transform '2012-02-26 11:25:38' using the format 'Y-m-d TH:i:s' for destination 'created'. Error: The date cannot be created from a format."

  created:
    -
      plugin: format_date
      from_format: 'Y-m-d TH:i:s'
      to_format: 'Y-m-d\TH:i:s'
    -
      plugin: date_format_alter
      source: created

If I add strtotime to in a date_format_alter process plugin it works.

class DateFormatAlter extends ProcessPluginBase {
    public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
      $unixTimestamp = strtotime($value);
      return $unixTimestamp;
    }
}

Comments

jeffwpetersen created an issue. See original summary.

jeffwpetersen’s picture

Issue summary: View changes
jeffwpetersen’s picture

Issue summary: View changes
quietone’s picture

jeffwpetersen, glad you found a workaround.

I am sure the problem here is that the to format should either escape the 'T' character or not have it at all, it should be either 'Y-m-d\TH:i:s' or 'Y-m-d H:i:s'.

Can you provide a sample of the failing data to determine if my assumption above is correct?

jeffwpetersen’s picture

The format in the joomla database is 2012-02-26 11:25:38 the table format is datetime.

quietone’s picture

Thanks, that confirms what I was thinking in #4.

If the source data format is '2012-02-26 11:25:38' then the from_format should be `Y-m-d H:i:s` instead of 'Y-m-d TH:i:s', which is shown in the IS.

The plugin should be this:

  created:
    -
      plugin: format_date
      from_format: 'Y-m-d H:i:s'
      to_format: 'Y-m-d\TH:i:s'
      source: created

@jeffwpetersen, can you test this change?

Version: 8.7.7 » 8.7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.7.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

@jeffwpetersen, has this been resolved?

More information about this issue was asked for in #6, 7 months ago.

Since we need more information to move forward with this issue, I am keeping the status at Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

benjifisher’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)