-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ability to parse RDATE #107
Comments
The lack of this functionality is preventing the library from working correctly for me. Parsing RDATE should be very straightforward (much more so than other already supported methods of handling recurring events) as it is simply indicates additional DTSTART values for the event. |
Happy to accept a PR |
This works for me and the ICS I'm importing. Patch file (renamed .txt to allow uploading) |
Please raise a PR. Unable to apply the patch even renaming it to |
remote: Permission to u01jmg3/ics-parser.git denied to oisact. |
|
Sorry, I don't have the time to jump through the hoops. Here it is if you want it... one solid block of code: if (isset($anEvent['RDATE'])) {
$isAllDayEvent = (strlen($anEvent['DTSTART_array'][1]) === 8) ? true : false;
$initialStart = new \DateTime($anEvent['DTSTART_array'][1]);
$initialStartTimeZoneName = $initialStart->getTimezone()->getName();
if (isset($anEvent['DTEND'])) {
$initialEnd = new \DateTime($anEvent['DTEND_array'][1]);
$initialEndTimeZoneName = $initialEnd->getTimezone()->getName();
} else {
$initialEndTimeZoneName = $initialStartTimeZoneName;
}
// Get Start timestamp
$startTimestamp = $initialStart->getTimestamp();
if (isset($anEvent['DTEND'])) {
$endTimestamp = $initialEnd->getTimestamp();
} elseif (isset($anEvent['DURATION'])) {
$duration = end($anEvent['DURATION_array']);
$endTimestamp = $this->parseDuration($anEvent['DTSTART'], $duration);
} else {
$endTimestamp = $startTimestamp;
}
$eventTimestampOffset = $endTimestamp - $startTimestamp;
for ($i = 1; $i < count($anEvent['RDATE_array']); $i+=2) {
$date = $anEvent['RDATE_array'][$i];
if (strtotime($date) == $startTimestamp) {
//This RDATE is the same as the primary event
continue;
}
if (isset($anEvent['RDATE_array'][$i - 1]['TZID'])) {
$date = sprintf(self::ICAL_DATE_TIME_TEMPLATE, $anEvent['RDATE_array'][$i - 1]['TZID']) . $date;
}
$newEvent = $anEvent;
// Tag as generated by a recurrence rule
$newEvent['RRULE_array'][2] = self::RECURRENCE_EVENT;
$newEvent['DTSTART'] = $anEvent['RDATE_array'][$i];
$newEvent['DTSTART_array']= [
0 => $anEvent['RDATE_array'][$i - 1],
1 => $anEvent['RDATE_array'][$i],
2 => $this->iCalDateToUnixTimestamp($date, false, false),
3 => $date
];
$newEvent['DTEND_array'] = $newEvent['DTSTART_array'];
$newEvent['DTEND_array'][2] += $eventTimestampOffset;
$newEvent['DTEND'] = date(
self::DATE_TIME_FORMAT,
$newEvent['DTEND_array'][2]
) . ($isAllDayEvent || ($initialEndTimeZoneName === 'Z') ? 'Z' : '');
$newEvent['DTEND_array'][1] = $newEvent['DTEND'];
$newEvent = $this->processEventIcalDateTime($newEvent);
$recurrenceEvents[] = $newEvent;
$this->eventCount++;
}
$allRecurrenceEvents = array_merge($allRecurrenceEvents, $recurrenceEvents);
$recurrenceEvents = array(); // Reset
} Which immediately follows: protected function processRecurrences()
{
$events = (isset($this->cal['VEVENT'])) ? $this->cal['VEVENT'] : array();
$recurrenceEvents = array();
$allRecurrenceEvents = array();
if (empty($events)) {
return false;
}
foreach ($events as $anEvent) { |
The data I'm importing is coming from here: https://smythchamber.org/?plugin=all-in-one-event-calendar&controller=ai1ec_exporter_controller&action=export_events&no_html=true |
Pull requests are the standard method of contributing to open source software on GitHub. If you want to continue/begin contributing to any project on GitHub I would suggest getting up to speed with how this method works. Forking a repo can be done in seconds. Instead I will have to copy and paste your code which I'm sure you will agree is not an ideal way of incorporating changes to a repo. |
RDATE
EXDATE
which is already supportedThe text was updated successfully, but these errors were encountered: