diff --git a/index.php b/index.php index af64378..54d21d2 100644 --- a/index.php +++ b/index.php @@ -78,6 +78,8 @@ $action = (isset($_REQUEST['action']) and preg_match(ACTION_REGEX, $_REQUEST['ac $supplier = array_key_exists('supplier', $_REQUEST) ? $_REQUEST['supplier'] : $requestSupplier; $hasSupplier = is_string($supplier) and preg_match(SUPPLIER_REGEX, $supplier); +$excludesFormatter = new \IntlDateFormatter('fr_FR.UTF8', \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, 'Europe/Paris'); + if ($hasSupplier) { if (!isset($config[$supplier])) @@ -141,6 +143,30 @@ if ($hasSupplier) { $config[$supplier][$key] = array_map('trim', $config[$supplier][$key]); } + + $config[$supplier]['excludes'] = array_filter( + array_map( + function ($value) use ($excludesFormatter) { + if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) + return $value; + + $timestamp = $excludesFormatter->parse($value, $offset); + + if ($timestamp !== false) + return (new \DateTimeImmutable('@' . $timestamp, new \DateTimeZone('Europe/Paris')))->format('Y-m-d'); + + try { + return (new \DateTimeImmutable($value, new \DateTimeZone('Europe/Paris')))->format('Y-m-d'); + } catch (\Exception $exception) { + return null; + } + }, + $config[$supplier]['excludes'] + ), + function ($value) { + return !is_null($value); + } + ); } $isConfig = false; @@ -264,6 +290,7 @@ if (!$isConfig and $hasSupplier) { } + ?>
@@ -364,8 +391,8 @@ if (!$isConfig and $hasSupplier) {