Browse Source

gère l'internationalisation des dates à exclure

master
vince vince 2 years ago
parent
commit
5b93e1f3ad
1 changed files with 29 additions and 2 deletions
  1. +29
    -2
      index.php

+ 29
- 2
index.php View File

@ -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) {
}
?><!DOCTYPE html>
<html lang="fr">
<head>
@ -364,8 +391,8 @@ if (!$isConfig and $hasSupplier) {
<div class="row mb-3">
<label for="excludes" class="col-sm-2 col-form-label">Exceptions</label>
<div class="col-sm-10">
<textarea class="form-control" name="excludes" rows="5"><?php echo implode(PHP_EOL, $config[$supplier]['excludes']); ?></textarea>
<div class="form-text">Les dates à exclure. Une par ligne. Ou pas. En tous cas le format c'est celui de l'<a href="https://fr.wikipedia.org/wiki/ISO_8601" target="_blank">ISO 8601</a> : <kbd>AAAA-MM-JJ</kbd></div>
<textarea class="form-control" name="excludes" rows="5"><?php echo implode(PHP_EOL, array_map(function ($value) use ($excludesFormatter) { return $excludesFormatter->format(new \DateTimeImmutable($value, new \DateTimeZone('Europe/Paris'))); }, $config[$supplier]['excludes'])); ?></textarea>
<div class="form-text">Les dates à exclure. Une par ligne. Ou pas. En tous cas le format c'est celui de l'<a class="text-reset" href="https://unicode-org.github.io/icu/userguide/format_parse/datetime/" target="_blank">ICU</a> : <kbd><?php echo $excludesFormatter->getPattern(); ?></kbd></div>
</div>
</div>


Loading…
Cancel
Save