diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc index 31b78c0..4d32c5a 100644 --- a/plugins/FeedsParser.inc +++ b/plugins/FeedsParser.inc @@ -456,6 +456,7 @@ class FeedsDateTimeElement extends FeedsElement { * The name of the field to build. */ public function buildDateField($entity, $field_name) { + $all_day = $this->isAllDay(); $info = field_info_field($field_name); $oldfield = FeedsDateTimeElement::readDateField($entity, $field_name); @@ -490,6 +491,23 @@ class FeedsDateTimeElement extends FeedsElement { } $db_tz = new DateTimeZone($db_tz); + $to_tz = new DateTimeZone($to_tz); + if ($all_day) { + // We force the timezone to the field's timezone, then add hour + // granularity so that the db tz is set correctly below. After + // which we have to remove the hour granularity so that subsequent + // mappings to this field don't acquire incorrect hour granularity + // in the merge() above. + if ($use_start) { + $use_start->setTimezone($to_tz, TRUE); + $use_start->addGranularity('hour'); + } + if ($use_end) { + $use_end->setTimezone($to_tz, TRUE); + $use_end->addGranularity('hour'); + } + } + if (!isset($entity->{$field_name})) { $entity->{$field_name} = array('und' => array()); } @@ -497,6 +515,9 @@ class FeedsDateTimeElement extends FeedsElement { $entity->{$field_name}['und'][0]['timezone'] = $use_start->getTimezone()->getName(); $entity->{$field_name}['und'][0]['offset'] = $use_start->getOffset(); $use_start->setTimezone($db_tz); + if ($all_day) { + $use_start->removeGranularity('hour'); + } $entity->{$field_name}['und'][0]['date'] = $use_start; /** * @todo the date_type_format line could be simplified based upon a patch @@ -510,10 +531,20 @@ class FeedsDateTimeElement extends FeedsElement { // Don't ever use end to set timezone (for now) $entity->{$field_name}['und'][0]['offset2'] = $use_end->getOffset(); $use_end->setTimezone($db_tz); + if ($all_day) { + $use_end->removeGranularity('hour'); + } $entity->{$field_name}['und'][0]['date2'] = $use_end; $entity->{$field_name}['und'][0]['value2'] = $use_end->format(date_type_format($info['type'])); } } + + /** + * Wrapper for date_api function. + */ + public function isAllDay() { + return date_is_all_day($this->start->format(DATE_FORMAT_DATETIME), $this->end->format(DATE_FORMAT_DATETIME)); + } }