Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#6 | date-year-only-fails-2175749-6.patch | 701 bytes | mortona2k |
Comments
Comment #1
BarisW CreditAttribution: BarisW commentedHere's a patch. I'd wanted to add a test too, but the Date Migration tests seems to be broken?
Comment #2
BarisW CreditAttribution: BarisW commentedComment #3
vijaycs85Thanks for the patch @BarisW, but assuming 4 character value as year seems more specific and might introduce some other regressions.
Comment #4
pdesai CreditAttribution: pdesai commentedUsing 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?
Comment #5
pdesai CreditAttribution: pdesai commentedI was able to fix the issue by adding the following to the patch:
Comment #6
mortona2k CreditAttribution: mortona2k commentedThis 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.
Comment #7
mortona2k CreditAttribution: mortona2k commentedComment #8
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 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?