|
@ -31,19 +31,19 @@ function generateUrl($supplier = null, $event = null) { |
|
|
return sprintf('%s/%s/%s', $requestUrl, $supplier, $event); |
|
|
return sprintf('%s/%s/%s', $requestUrl, $supplier, $event); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function findNext($start, $frequency, $excludes = [], $maxIterations = 1000, $direction = +1) { |
|
|
|
|
|
|
|
|
function findNext($start, $frequency, $excludes = [], $vsNow = true, $maxIterations = 1000, $direction = +1) { |
|
|
$now = new \DateTime('now'); |
|
|
$now = new \DateTime('now'); |
|
|
$current = clone $start; |
|
|
$current = clone $start; |
|
|
$frequency = \DateInterval::createFromDateString($frequency); |
|
|
$frequency = \DateInterval::createFromDateString($frequency); |
|
|
do { |
|
|
do { |
|
|
if ($direction === abs($direction)) { |
|
|
if ($direction === abs($direction)) { |
|
|
while ( |
|
|
while ( |
|
|
($current->getTimestamp() < $now->getTimestamp()) |
|
|
|
|
|
|
|
|
(!$vsNow or ($current->getTimestamp() < $now->getTimestamp())) |
|
|
and ($maxIterations-- > 0) |
|
|
and ($maxIterations-- > 0) |
|
|
) $current->add($frequency); |
|
|
) $current->add($frequency); |
|
|
} else { |
|
|
} else { |
|
|
while ( |
|
|
while ( |
|
|
($current->getTimestamp() > $now->getTimestamp()) |
|
|
|
|
|
|
|
|
(!$vsNow or ($current->getTimestamp() > $now->getTimestamp())) |
|
|
and ($maxIterations-- > 0) |
|
|
and ($maxIterations-- > 0) |
|
|
) $current->sub($frequency); |
|
|
) $current->sub($frequency); |
|
|
} |
|
|
} |
|
@ -55,8 +55,8 @@ function findNext($start, $frequency, $excludes = [], $maxIterations = 1000, $di |
|
|
return $current; |
|
|
return $current; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function findPrevious($start, $frequency, $excludes = [], $maxIterations = 1000) { |
|
|
|
|
|
return findNext($start, $frequency, $excludes, $maxIterations, -1); |
|
|
|
|
|
|
|
|
function findPrevious($start, $frequency, $excludes = [], $nsNow = true, $maxIterations = 1000) { |
|
|
|
|
|
return findNext($start, $frequency, $excludes, $vsNow, $maxIterations, -1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
define('CONFIG_FILE', __DIR__ . DIRECTORY_SEPARATOR . 'config.php'); |
|
|
define('CONFIG_FILE', __DIR__ . DIRECTORY_SEPARATOR . 'config.php'); |
|
@ -173,11 +173,11 @@ if (!$isConfig and $hasSupplier) { |
|
|
die(); |
|
|
die(); |
|
|
} else { |
|
|
} else { |
|
|
$current = new \DateTimeImmutable($event); |
|
|
$current = new \DateTimeImmutable($event); |
|
|
$previous = findPrevious($current, $config[$supplier]['frequency'], $config[$supplier]['excludes']); |
|
|
|
|
|
|
|
|
$previous = findPrevious($current, $config[$supplier]['frequency'], $config[$supplier]['excludes'], false); |
|
|
$previousEvent = $previous->format('Y-m-d'); |
|
|
$previousEvent = $previous->format('Y-m-d'); |
|
|
if (false and !array_key_exists($previousEvent, $data[$supplier])) |
|
|
if (false and !array_key_exists($previousEvent, $data[$supplier])) |
|
|
unset($previousEvent); |
|
|
unset($previousEvent); |
|
|
$next = findNext($current, $config[$supplier]['frequency'], $config[$supplier]['excludes']); |
|
|
|
|
|
|
|
|
$next = findNext($current, $config[$supplier]['frequency'], $config[$supplier]['excludes'], false); |
|
|
$nextEvent = $next->format('Y-m-d'); |
|
|
$nextEvent = $next->format('Y-m-d'); |
|
|
if (false and !array_key_exists($nextEvent, $data[$supplier])) |
|
|
if (false and !array_key_exists($nextEvent, $data[$supplier])) |
|
|
unset($nextEvent); |
|
|
unset($nextEvent); |
|
|