Commit 54f21f47 authored by Robert Rollins's avatar Robert Rollins

First draft fix for [#1905482].

parent 0d108cc1
......@@ -192,15 +192,17 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$start->setTimezone(new dateTimezone($date_field['timezone']));
$end->setTimezone(new dateTimezone($date_field['timezone']));
$start_formatted = $start->format(DATE_FORMAT_DATETIME);
$end_formatted = $end->format(DATE_FORMAT_DATETIME);
$all_day = date_is_all_day($start_formatted, $end_formatted, date_granularity_precision($date_info['granularity']));
// Check if the start and end dates indicate that this is an All Day event.
$all_day = date_is_all_day(
date_format($start, DATE_FORMAT_DATETIME),
date_format($end, DATE_FORMAT_DATETIME),
date_granularity_precision($date_info['granularity'])
);
// According to RFC 2445 (clarified in RFC 5545) the DTEND value is
// non-inclusive. When it is a DATE rather than a DATETIME, this means
// that we should add one day to its value.
if ($all_day) {
// According to RFC 2445 (clarified in RFC 5545) the DTEND value is
// non-inclusive. When dealing with All Day values, they're DATEs rather
// than DATETIMEs, so we need to add a day to conform to RFC.
$end->modify("+1 day");
}
......
......@@ -122,41 +122,51 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
$vevent = $vcalendar->newComponent('vevent');
// Get the start date as an array.
$rendered_date = $row['start']->toArray();
if ($row['all_day']) {
$rendered_date['hour'] = FALSE;
$rendered_date['minute'] = FALSE;
$rendered_date['second'] = FALSE;
}
$start = $row['start']->toArray();
$timezone = $row['start']->getTimezone()->getName();
$timezones[$timezone] = $timezone;
$vevent->setDtstart(
$rendered_date['year'],
$rendered_date['month'],
$rendered_date['day'],
$rendered_date['hour'],
$rendered_date['minute'],
$rendered_date['second'],
$timezone);
if ($row['all_day']) {
// All day events need to be specified as DATE, rather than DATE-TIME, or they get interpretted wrong.
$vevent->setDtstart($start['year'], $start['month'], $start['day'],
FALSE, FALSE, FALSE, FALSE, array('VALUE' => 'DATE'));
}
else {
$vevent->setDtstart(
$start['year'],
$start['month'],
$start['day'],
$start['hour'],
$start['minute'],
$start['second'],
$timezone);
}
// Keep a copy of the start date, as it's useful later.
$rendered_start = $rendered_date + array('tz' => $row['start']->getTimezone());
// Add the Timezone info to the start date, for use later.
$start['tz'] = $row['start']->getTimezone();
// Only add the end date if there is one.
if (!empty($row['end'])) {
$rendered_date = $row['end']->toArray();
$end = $row['end']->toArray();
$timezone = $row['start']->getTimezone()->getName();
$timezones[$timezone] = $timezone;
$vevent->setDtend(
$rendered_date['year'],
$rendered_date['month'],
$rendered_date['day'],
$rendered_date['hour'],
$rendered_date['minute'],
$rendered_date['second'],
$timezone);
// Keep a copy of the start date, as it's useful later.
$rendered_end = $rendered_date + array('tz' => $row['end']->getTimezone());
if ($row['all_day']) {
$vevent->setDtend($end['year'], $end['month'], $end['day'],
FALSE, FALSE, FALSE, FALSE, array('VALUE' => 'DATE'));
}
else {
$vevent->setDtend(
$end['year'],
$end['month'],
$end['day'],
$end['hour'],
$end['minute'],
$end['second'],
$timezone);
}
// Keep a copy of the end date, as it's useful later.
$end['tz'] = $row['end']->getTimezone();
}
$vevent->setProperty('uid', $row['uid']);
$vevent->setProperty('summary', $row['summary']);
......@@ -174,17 +184,17 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
$exdates = array();
foreach ($exceptions as $exception) {
$except = date_ical_date($exception, 'UTC');
date_timezone_set($except, $rendered_start['tz']);
$rendered_date = $except->toArray();
date_timezone_set($except, $start['tz']);
$exception_array = $except->toArray();
$exdates[] = array(
'year' => $rendered_date['year'],
'month' => $rendered_date['month'],
'day' => $rendered_date['day'],
'year' => $exception_array['year'],
'month' => $exception_array['month'],
'day' => $exception_array['day'],
// Use the time information from the start date.
'hour' => $rendered_start['hour'],
'min' => $rendered_start['minute'],
'second' => $rendered_start['second'],
'tz' => $rendered_start['tz']->getName(),
'hour' => $start['hour'],
'min' => $start['minute'],
'second' => $start['second'],
'tz' => $start['tz']->getName(),
);
}
// Add those exclusions as 'EXDATE's.
......@@ -195,31 +205,31 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
$add_dates = array();
foreach ($additions as $addition) {
$add = date_ical_date($addition, 'UTC');
date_timezone_set($add, $rendered_start['tz']);
$rendered_date = $add->toArray();
date_timezone_set($add, $start['tz']);
$addition_array = $add->toArray();
$add_date = array(
'year' => $rendered_date['year'],
'month' => $rendered_date['month'],
'day' => $rendered_date['day'],
'year' => $addition_array['year'],
'month' => $addition_array['month'],
'day' => $addition_array['day'],
// Use the time information from the start date.
'hour' => $rendered_start['hour'],
'min' => $rendered_start['minute'],
'second' => $rendered_start['second'],
'tz' => $rendered_start['tz']->getName(),
'hour' => $start['hour'],
'min' => $start['minute'],
'second' => $start['second'],
'tz' => $start['tz']->getName(),
);
// If there was an end date specified, use that too.
if (!empty($row['end'])) {
$add_date = array($add_date);
$add_date[] = array(
'year' => $rendered_date['year'],
'month' => $rendered_date['month'],
'day' => $rendered_date['day'],
'year' => $addition_array['year'],
'month' => $addition_array['month'],
'day' => $addition_array['day'],
// Use the time information from the end date.
'hour' => $rendered_end['hour'],
'min' => $rendered_end['minute'],
'second' => $rendered_end['second'],
'tz' => $rendered_end['tz']->getName(),
'hour' => $end['hour'],
'min' => $end['minute'],
'second' => $end['second'],
'tz' => $end['tz']->getName(),
);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment