Not sure if this is the right place and apologies to any moderator who feels it should be moved to a different forum.
Anyway, I building a Calendar object to hold an array of Event objects (each object simply has a title, start_date, end_date).
I want to be able to call the following:
Code: Select all
// events that start on/after $start and end on/before $end
$events = $calendar->getEventsBetweenDates($start, $end);
// returns events that start or end anywhere within the specified range
// (hmm suggestions for a better method name are welcome)
$events = $calendar->getEventsOverDates($start, $end);E.g. To implement the method getEventsBetweenDates($start, $end) you can easily do the following
Code: Select all
foreach($eventArray as $evt)
{
if( ($start <= $evt->start && $evt->end <= $end)
{
$result[] = $evt;
}
}Code: Select all
foreach($eventArray as $evt)
{
if( ($start <= $evt->start && $evt->end <= $end)
|| ($evt->start <= $start && $evt->end => $end)
|| ($start => $evt->start && $evt->start <= $end)
|| ($evt->end >= $start && $evt->end <= $end))
{
$result[] = $evt;
}
}I should add that I'm using the Zend Framework, but I didn't see anything there that helps here. I checked out Zend_Search_Lucene to see if they had an in-memory implementation, but they didn't and the documentation said it was quite intensive which probably translates into overkill for this class.