diff --git a/src/Feeds/Item/IcalItem.php b/src/Feeds/Item/IcalItem.php index 186c4f56b15cb6872d31e05f277758a79ed599e6..db310b66a34d70a8ebaace0ca0464234f36298fb 100644 --- a/src/Feeds/Item/IcalItem.php +++ b/src/Feeds/Item/IcalItem.php @@ -12,19 +12,33 @@ use Drupal\feeds\Feeds\Item\BaseItem; class IcalItem extends BaseItem { /** - * The start date and time for the event. + * The start date and time for the event as unix timestamp. * * @var mixed */ protected $dtstart; /** - * The end date and time for the event. + * The end date and time for the event as unix timestamp. * * @var mixed */ protected $dtend; + /** + * The start date as timezone format. + * + * @var mixed + */ + protected $dtstart_timezone; + + /** + * The end date as timezone format. + * + * @var mixed + */ + protected $dtend_timezone; + /** * The raw string value of the start date and time from the feed. * diff --git a/src/Feeds/Parser/IcalParser.php b/src/Feeds/Parser/IcalParser.php index e171fbf70f6437467f7cfdaf7e7eb78371f7258d..d148368c1f1664a08c30553501d26485f487e670 100644 --- a/src/Feeds/Parser/IcalParser.php +++ b/src/Feeds/Parser/IcalParser.php @@ -76,7 +76,7 @@ class IcalParser extends PluginBase implements ParserInterface { // Get all events. $events = $ical->events(); } - + foreach ($events as $eventIndex => $event) { // Create item to return for processing. @@ -89,15 +89,18 @@ class IcalParser extends PluginBase implements ParserInterface { // Check to see if we have a timezone. if (!empty($event->dtstart_array[0]) && !empty($event->dtstart_array[0]['TZID'])) { // Use format: 2019-07-29T06:50:00Europe/Amsterdam - $itemObject->set($eventProperty, $event->dtstart_array[1].$event->dtstart_array[0]['TZID']); + $itemObject->set('dtstart_timezone', $event->dtstart_array[1].$event->dtstart_array[0]['TZID']); } else { - // Just use the unix_timestamp. - $itemObject->set($eventProperty, $event->dtstart_array[2]); + // Just use the raw value. + $itemObject->set('dtstart_timezone', $eventPropertyValue); } // Save the original value in the raw source field. $itemObject->set('dtstart_raw', $eventPropertyValue); + + // Save the timestamp for sites that rely on it. + $itemObject->set($eventProperty, $event->dtstart_array[2]); break; case 'dtend': @@ -105,15 +108,18 @@ class IcalParser extends PluginBase implements ParserInterface { // Check to see if we have a timezone. if (!empty($event->dtend_array[0]) && !empty($event->dtend_array[0]['TZID'])) { // Use format: 2019-07-29T06:50:00Europe/Amsterdam - $itemObject->set($eventProperty, $event->dtend_array[1].$event->dtend_array[0]['TZID']); + $itemObject->set('dtend_timezone', $event->dtend_array[1].$event->dtend_array[0]['TZID']); } else { - // Just use the unix_timestamp. - $itemObject->set($eventProperty, $event->dtend_array[2]); + // Just use the raw value. + $itemObject->set('dtend_timezone', $eventPropertyValue); } // Save the original value in the raw source field. $itemObject->set('dtend_raw', $eventPropertyValue); + + // Save the timestamp for sites that rely on it. + $itemObject->set($eventProperty, $event->dtend_array[2]); } break; @@ -125,7 +131,7 @@ class IcalParser extends PluginBase implements ParserInterface { } // Use a timestamp here that's what Drupal expects. $itemObject->set($eventProperty, strtotime($eventPropertyValue)); - + // Save the original value in the raw source field. $itemObject->set('last_modified_raw', $eventPropertyValue); break; @@ -171,6 +177,12 @@ class IcalParser extends PluginBase implements ParserInterface { 'dtend' => [ 'label' => $this->t('DTEND (unix timestamp)'), ], + 'dtstart_timezone' => [ + 'label' => $this->t('DTSTART (Timezone format)'), + ], + 'dtend_timezone' => [ + 'label' => $this->t('DTEND (Timezone format)'), + ], 'dtstart_raw' => [ 'label' => $this->t('DTSTART RAW (string format from source)'), ],