When\When::getNextOccurrence PHP Method

getNextOccurrence() public method

public getNextOccurrence ( $occurDate, $strictly_after = true )
    public function getNextOccurrence($occurDate, $strictly_after = true)
    {
        self::prepareDateElements(false);
        if (!$strictly_after) {
            if ($this->occursOn($occurDate) && $this->occursAt($occurDate)) {
                return $occurDate;
            }
        }
        // Set an arbitrary end date, taking the 400Y advice from elsewhere in this module.
        // TODO: do this in smaller chunks so we don't get a bunch of unneeded occurrences
        $endDate = clone $occurDate;
        $endDate->add(new \DateInterval('P400Y'));
        $candidates = $this->getOccurrencesBetween($occurDate, $endDate, 2);
        foreach ($candidates as $candidate) {
            if (!$strictly_after) {
                return $candidate;
            } elseif ($candidate > $occurDate) {
                return $candidate;
            }
        }
        return false;
    }

Usage Example

Example #1
0
 function testGetNextOccurrenceFromLastOccurence()
 {
     $r = new When();
     $r->startDate(new DateTime("19970902T090000"))->rrule("FREQ=WEEKLY")->until(new DateTime("19971104T090000"));
     $result = $r->getNextOccurrence(new DateTime("19971104T090000"));
     $this->assertFalse($result);
 }