public function testTimespansWithSameStart() { try { $this->timeline->add(array('start' => strtotime('2009-02-13 23:31:30GMT'), 'end' => strtotime('2009-02-13 23:31:31GMT'))); $this->timeline->add(array('start' => strtotime('2009-02-13 23:31:30GMT'), 'end' => strtotime('2009-02-14 00:00:00GMT'))); $this->timeline->add(array('start' => strtotime('2009-02-13 23:31:30GMT'), 'end' => strtotime('2009-02-13 23:45:00GMT'))); } catch (Exception $e) { self::assertTrue(false, 'adding two equal exceptions won\'t throw an error.'); return; } self::assertSame(1, $this->timeline->count(), 'only one exception stored if there was a different one with same start.'); $current = $this->timeline->current(); self::assertSame(strtotime('2009-02-14 00:00:00GMT'), $current['end'], 'end of the longest event was stored'); }
/** * drop all events that are blocked by an exception * * some words on how it works: * * Basically the idea here is to check every event if it overlaps an exception. * * To make this algorithm a bit more efficant, these prerequisits are met: * - the events are ordered by their start-date (no duplicate start dates), * - the exceptions by their start-date (no duplicate start dates) * * So if we find, that the end-date of an exception is before the current start-date * it is before the start-date of ALL remaining events and we'll just drop it. * * * @param Tx_CzSimpleCal_Recurrance_Timeline_Events $events * @param Tx_CzSimpleCal_Recurrance_Timeline_Exception $exceptions * @return Tx_CzSimpleCal_Recurrance_Timeline_Events */ protected function dropExceptionalEvents($events, $exceptions) { foreach ($events as $eventKey => $event) { if (!$exceptions->hasData()) { break; } // $exceptions->rewind(); foreach ($exceptions as $exceptionKey => $exception) { if ($exception['end'] <= $eventKey) { //if: end of exception is before start of event -> delete it as it won't affect any more of the events $exceptions->unsetCurrent(); } elseif ($event['end'] < $exceptionKey || $event['end'] == $exceptionKey && $event['start'] != $event['end']) { //if: end of event is before start of exception or // end of event matches start of exception and the event is not zero length // -> none of the following exception will affect this event break; } else { // else: match -> delete this event $events->unsetCurrent(); break; } } } return $events; }
protected function setExceptionData($data) { foreach ($data as $timespan) { $this->exceptions->add($timespan); } }