|
|
@ -32,15 +32,20 @@ function generateUrl($supplier = null, $event = null) { |
|
|
|
} |
|
|
|
|
|
|
|
function findNext($start, $frequency, $excludes = [], $maxIterations = 1000, $direction = +1) { |
|
|
|
$now = new \DateTime('now'); |
|
|
|
$current = clone $start; |
|
|
|
$frequency = \DateInterval::createFromDateString($frequency); |
|
|
|
do { |
|
|
|
while ( |
|
|
|
($current->getTimestamp() < $now->getTimestamp()) |
|
|
|
and ($maxIterations-- > 0) |
|
|
|
) { |
|
|
|
if ($direction === abs($direction)) $current->add($frequency); |
|
|
|
else $current->sub($frequency); |
|
|
|
if ($direction === abs($direction)) { |
|
|
|
while ( |
|
|
|
($current->getTimestamp() < $now->getTimestamp()) |
|
|
|
and ($maxIterations-- > 0) |
|
|
|
) $current->add($frequency); |
|
|
|
} else { |
|
|
|
while ( |
|
|
|
($current->getTimestamp() > $now->getTimestamp()) |
|
|
|
and ($maxIterations-- > 0) |
|
|
|
) $current->sub($frequency); |
|
|
|
} |
|
|
|
$nextEvent = $current->format('Y-m-d'); |
|
|
|
} while ( |
|
|
@ -162,7 +167,6 @@ if (!$isConfig and $hasSupplier) { |
|
|
|
$start = new \DateTime($config[$supplier]['start']); |
|
|
|
if (!$hasEvent) { |
|
|
|
|
|
|
|
$now = new \DateTime('now'); |
|
|
|
$next = findNext($start, $config[$supplier]['frequency'], $config[$supplier]['excludes']); |
|
|
|
$nextEvent = $next->format('Y-m-d'); |
|
|
|
header('Location: ' . generateUrl($supplier, $nextEvent)); |
|
|
|