When you try to migrate a year-only date field, the migration differs exactly a month and one day. This is because strtotime(), used in Migrate API, cannot handle a string like 2012-00-00, which is what Date sends to Migrate if the month and day is empty. The fix is simple; just add a fake month and day to the year.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BarisW’s picture

Status: Active » Needs review

Here's a patch. I'd wanted to add a test too, but the Date Migration tests seems to be broken?

Fatal error: Class 'Migrate' not found in date_migrate.test on line 54

BarisW’s picture

vijaycs85’s picture

Status: Needs review » Needs work
Issue tags: +sprint, +Needs tests

Thanks for the patch @BarisW, but assuming 4 character value as year seems more specific and might introduce some other regressions.

pdesai’s picture

Using Drupal Migrate UI to migrate from Drupal 6 to Drupal 7 (same server). Have a content type with a date field for year and it imports except 1996 would show up as 1995 in Drupal 7. I have tried to set the Timezone to "America/New_York" which is the site's time zone on both sites. I also tried leaving the timezone field blank, but same issue of being off by one year.

I applied the above patch but still no luck. Any idea what is configured incorrectly?

pdesai’s picture

I was able to fix the issue by adding the following to the patch:

if (strlen($to) == 4) {
	$to .= '-01-01';
}
$from = str_replace('-00-00T00:00:00', '-01-01T00:00:00', $from);
$to = str_replace('-00-00T00:00:00', '-01-01T00:00:00', $to);
mortona2k’s picture

This patch combines the two approaches above. The first will check for 4 digit year values (2014) and append '-01-01' to them. The second will take iso date values that only have a year such as 2014-00-00T00:00:00 and set it to 2014-01-01T00:00:00.

There may be a better way to handle the dates, but this seems to work.

mortona2k’s picture

Status: Needs work » Needs review
Chris Matthews’s picture

The 3 year old patch in #6 to date.migrate.inc still applies cleanly to 7.x-2.x-dev. Would anyone be able/willing to review/test this patch?