Browse Source

corrige un bug

master
vince vince 2 years ago
parent
commit
439290f1df
1 changed files with 11 additions and 7 deletions
  1. +11
    -7
      index.php

+ 11
- 7
index.php View File

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


Loading…
Cancel
Save