Browse Source

tente de corriger un bug dans le calcul des date adjacentes

master
vince vince 3 years ago
parent
commit
67f42f52a3
1 changed files with 7 additions and 7 deletions
  1. +7
    -7
      index.php

+ 7
- 7
index.php View File

@ -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);


Loading…
Cancel
Save