From 5b93e1f3adcaa3470a94b3c7cd41d3c79247813d Mon Sep 17 00:00:00 2001 From: vince Date: Mon, 27 Dec 2021 17:29:01 +0100 Subject: [PATCH] =?UTF-8?q?g=C3=A8re=20l'internationalisation=20des=20date?= =?UTF-8?q?s=20=C3=A0=20exclure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) 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) {
- -
Les dates à exclure. Une par ligne. Ou pas. En tous cas le format c'est celui de l'ISO 8601 : AAAA-MM-JJ
+ +
Les dates à exclure. Une par ligne. Ou pas. En tous cas le format c'est celui de l'ICU : getPattern(); ?>