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

eventsFromRange should allow arbitrary range #1

Open
GoogleCodeExporter opened this issue Mar 29, 2015 · 0 comments
Open

eventsFromRange should allow arbitrary range #1

GoogleCodeExporter opened this issue Mar 29, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

To allow an arbitrary range to be selected using the eventsFromRange method I 
altered the code to the following, bool start and end are still accepted and 
should give same result as before (i.e. shouldn't break existing 
implementations)


/**
 * Returns false when the current calendar has no events in range, else the
 * events.
 * 
 * Note that this function makes use of a UNIX timestamp. This might be a 
 * problem on January the 29th, 2038.
 * See http://en.wikipedia.org/wiki/Unix_time#Representing_the_number
 *
 * @param {boolean} or {time} $rangeStart Either true or false or unix timestamp
 * @param {boolean} or {time} $rangeEnd   Either true or false or unix timestamp
 *
 * @return {mixed}
 */
public function eventsFromRange($rangeStart = false, $rangeEnd = false) 
{
    $events = $this->sortEventsWithOrder($this->events(), SORT_ASC);

    if (!$events) {
        return false;
    }

    $extendedEvents = array();

    if ($rangeStart === true) {
        $rangeStart = time();
    } else if ($rangeStart === false) {
        $rangeStart = 0;
    }

    if ($rangeEnd === true or ($rangeEnd <= $rangeStart && $rangeStart <= time())) {
        $rangeEnd = time();
    } else if ($rangeEnd === false or $rangeEnd <= $rangeStart) {
        $rangeEnd = strtotime('2038-01-18');
    }

    // loop through all events by adding two new elements
    foreach ($events as $anEvent) {
        $dtStart = $this->iCalDateToUnixTimestamp($anEvent['DTSTART']);
        $dtEnd = $this->iCalDateToUnixTimestamp($anEvent['DTEND']);
        if ($dtEnd >= $rangeStart && $dtStart <= $rangeEnd) $extendedEvents[] = $anEvent;
    }

    return $extendedEvents;
}



Original issue reported on code.google.com by maw.des...@gmail.com on 29 Jan 2012 at 9:09

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

1 participant