Skip to content
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

Open
u01jmg3 opened this issue Mar 19, 2017 · 9 comments
Open

Support ability to parse RDATE #107

u01jmg3 opened this issue Mar 19, 2017 · 9 comments

Comments

@u01jmg3
Copy link
Owner

u01jmg3 commented Mar 19, 2017

@oisact
Copy link

oisact commented Feb 9, 2019

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.

@u01jmg3
Copy link
Owner Author

u01jmg3 commented Feb 9, 2019

Happy to accept a PR

@oisact
Copy link

oisact commented Feb 10, 2019

Happy to accept a PR

This works for me and the ICS I'm importing.

Patch file (renamed .txt to allow uploading)
Enhance_the_iCal_php_library_to_support_RDATE_type_recurring_events_.txt

@u01jmg3
Copy link
Owner Author

u01jmg3 commented Feb 10, 2019

Please raise a PR. Unable to apply the patch even renaming it to *.patch.

@oisact
Copy link

oisact commented Feb 10, 2019

Please raise a PR. Unable to apply the patch even renaming it to *.patch.

remote: Permission to u01jmg3/ics-parser.git denied to oisact.
fatal: unable to access 'https://github.com/u01jmg3/ics-parser.git/': The requested URL returned error: 403

@u01jmg3
Copy link
Owner Author

u01jmg3 commented Feb 10, 2019

If you don't have write access to the repository where you'd like to create a pull request, you must create a fork, or copy, of the repository first. For more information, see "Creating a pull request from a fork" and "About forks."

@oisact
Copy link

oisact commented Feb 10, 2019

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) {

@oisact
Copy link

oisact commented Feb 10, 2019

@u01jmg3
Copy link
Owner Author

u01jmg3 commented Feb 10, 2019

Sorry, I don't have the time to jump through the hoops.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants