From 4a9800225e2b0b2baf05faf7601c1fb4ab31227b Mon Sep 17 00:00:00 2001 From: vince Date: Mon, 31 Jan 2022 20:13:57 +0100 Subject: [PATCH] =?UTF-8?q?affiche=20les=20dates=20pass=C3=A9es=20en=20rou?= =?UTF-8?q?ge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index f837102..16c5af6 100644 --- a/index.php +++ b/index.php @@ -25,6 +25,12 @@ if (preg_match(REQUEST_REGEX, $requestUrl, $match)) { $requestEvent = null; } +function isInPast($event) { + $now = new \DateTimeImmutable('now'); + $then = new \DateTimeImmutable($event); + return $then->getTimestamp() < $now->getTimestamp(); +} + function ago($value) { $now = new \DateTimeImmutable('now 00:00:00'); $value = (clone $value)->setTime(0, 0, 0); @@ -122,7 +128,7 @@ if ($hasSupplier) { $config[$supplier] = array_merge( [ 'title' => '', - 'subtitle' => '%date% (%ago%)', + 'subtitle' => '%date% (%ago%)', 'description' => '', 'choices' => [], 'start' => 'now 00:00:00', @@ -322,6 +328,7 @@ if (!$isConfig and !$supplierIsNew and $hasSupplier) { $date = (new \IntlDateFormatter('fr_FR.UTF8', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE, 'Europe/Paris'))->format(new \DateTime($event)); $ago = ago(new \DateTimeImmutable($event)); + $color = isInPast($event) ? 'text-danger' : 'text-muted'; foreach (['title', 'subtitle', 'description'] as $key) { while (preg_match('/%([^%]+)%/i', $config[$supplier][$key], $match))