From 439290f1dfc70ae2316f7a35006a60114c83930e Mon Sep 17 00:00:00 2001 From: vince Date: Fri, 24 Dec 2021 17:43:35 +0100 Subject: [PATCH] corrige un bug --- index.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index abf6104..2373eb2 100644 --- a/index.php +++ b/index.php @@ -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));