|
|
@ -31,19 +31,19 @@ function generateUrl($supplier = null, $event = null) { |
|
|
|
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'); |
|
|
|
$current = clone $start; |
|
|
|
$frequency = \DateInterval::createFromDateString($frequency); |
|
|
|
do { |
|
|
|
if ($direction === abs($direction)) { |
|
|
|
while ( |
|
|
|
($current->getTimestamp() < $now->getTimestamp()) |
|
|
|
(!$vsNow or ($current->getTimestamp() < $now->getTimestamp())) |
|
|
|
and ($maxIterations-- > 0) |
|
|
|
) $current->add($frequency); |
|
|
|
} else { |
|
|
|
while ( |
|
|
|
($current->getTimestamp() > $now->getTimestamp()) |
|
|
|
(!$vsNow or ($current->getTimestamp() > $now->getTimestamp())) |
|
|
|
and ($maxIterations-- > 0) |
|
|
|
) $current->sub($frequency); |
|
|
|
} |
|
|
@ -55,8 +55,8 @@ function findNext($start, $frequency, $excludes = [], $maxIterations = 1000, $di |
|
|
|
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'); |
|
|
@ -173,11 +173,11 @@ if (!$isConfig and $hasSupplier) { |
|
|
|
die(); |
|
|
|
} else { |
|
|
|
$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'); |
|
|
|
if (false and !array_key_exists($previousEvent, $data[$supplier])) |
|
|
|
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'); |
|
|
|
if (false and !array_key_exists($nextEvent, $data[$supplier])) |
|
|
|
unset($nextEvent); |
|
|
|