diff --git a/index.php b/index.php index 97367c6..08ccef2 100644 --- a/index.php +++ b/index.php @@ -37,19 +37,27 @@ function findNext($start, $frequency, $excludes = [], $vsNow = true, $maxIterati $frequency = \DateInterval::createFromDateString($frequency); do { if ($direction === abs($direction)) { - while ( - (!$vsNow or ($current->getTimestamp() < $now->getTimestamp())) - and ($maxIterations-- > 0) - ) $current->add($frequency); + if (!$vsNow and ($maxIterations-- > 0)) { + $current->add($frequency); + } else { + while ( + ($current->getTimestamp() < $now->getTimestamp()) + and ($maxIterations-- > 0) + ) $current->add($frequency); + } } else { - while ( - (!$vsNow or ($current->getTimestamp() > $now->getTimestamp())) - and ($maxIterations-- > 0) - ) $current->sub($frequency); + if (!$vsNow and ($maxIterations-- > 0)) { + $current->sub($frequency); + } else { + while ( + ($current->getTimestamp() > $now->getTimestamp()) + and ($maxIterations-- > 0) + ) $current->sub($frequency); + } } $nextEvent = $current->format('Y-m-d'); } while ( - !in_array($nextEvent, $excludes) + in_array($nextEvent, $excludes) and ($maxIterations > 0) ); return $current;