I've set up a custom migrate module which imports D5 event nodes and creates D7 nodes for them, which use a date field for the start and end dates.
I define a custom source field like so: $source_fields = array('event_date' => t('Event date in expected format')); which I then populate in prepareRow():
public function prepareRow($current_row) {
$one_hour = 60 * 60 * 1;
// Timezones: 314 = GMT+1, 487 = GMT
switch ($current_row->timezone) {
case 314:
$timezone = 'Europe/Dublin'; // imports +1 hr
$current_row->event_start = $current_row->event_start - $one_hour;
$current_row->event_end = $current_row->event_end - $one_hour;
break;
case 487:
$timezone = 'Europe/Dublin'; // imports fine.
break;
}
$date_data = array(
'from' => (string)$current_row->event_start,
'to' => (string)$current_row->event_end,
'timezone' => $timezone,
);
$current_row->event_date = drupal_json_encode($date_data);
return TRUE;
}
When I run the migration routine, this works fine without any errors and when I edit the newly created nodes I can see that the date and time are set correctly in the drop-downs. However, when viewing the node page the current date and time are always displayed. Saving the node via the UI fixes the problem.
My date field is configured as "date (iso format)" with a select widget.
When looking at the node's entry in "field_data_field_event_date" and "field_revision_field_event_date" tables I can see that the field_event_date_value/2 are both set to "2011-06-14T15:30" rather than "2011-06-14T15:30:00" (possibly because I have seconds disabled for my date field). When you save the node via the UI, this value is updated to include seconds. Similarly manually updating them (via sql update) to the correct value fixes the problem.
So really the MigrateDateFieldHandler handler should store the seconds too, even if the field is configured not to capture or display that information.
Comments
Comment #1
mikeryanFix was committed August 10 - I suppose I should have opened an issue so it was visible...
Comment #2
stella commentedawesome, thanks! I'll be sure to give it a go later today.
Comment #3
stella commentedYep, that works great thanks! Hope this fix has made it into the new date_migrate module too.
Comment #4
mikeryanYep: #1245690: Migration plugin missing seconds from date formats