Skip to content

Instantly share code, notes, and snippets.

@glennpratt
Created May 11, 2010 17:52
Show Gist options
  • Save glennpratt/397602 to your computer and use it in GitHub Desktop.
Save glennpratt/397602 to your computer and use it in GitHub Desktop.
<?php
/**
* Migrate CCK date start with optional duration to date start and date end.
*/
function _apci_aldt_migrate_group_dep_migrate_event_date(&$source_node, &$target_node) {
$target_node->field_date = array();
$duration = $source_node->field_duration[0]['value'];
foreach ($source_node->field_start_date as $source_date) {
// Convert duration [(string) minutes] to end date.
if ($duration) {
$end_date = date_make_date(
$source_date['value']
);
date_modify($end_date, '+'. $duration . ' minutes');
$source_date['value2'] = date_format(
$end_date,
date_type_format(DATE_ISO) //This probably shouldn't be hard coded.
);
}
// Else, set end time = start time.
else {
$source_date['value2'] = $source_date['value'];
}
$target_node->field_date[] = $source_date;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment