diff --git a/index.php b/index.php
index 3079b3c..f837102 100644
--- a/index.php
+++ b/index.php
@@ -25,6 +25,19 @@ if (preg_match(REQUEST_REGEX, $requestUrl, $match)) {
$requestEvent = null;
}
+function ago($value) {
+ $now = new \DateTimeImmutable('now 00:00:00');
+ $value = (clone $value)->setTime(0, 0, 0);
+ $diff = $now->diff($value, false);
+ if (abs($diff->y) > 0) $output = sprintf('%d an%s', $diff->y, $diff->y > 1 ? 's' : '');
+ elseif (abs($diff->m) > 0) $output = sprintf('%d mois', $diff->m);
+ elseif (abs($diff->d) > 1) $output = sprintf('%d jours', $diff->d);
+ if (isset($output)) $output = sprintf('%s %s', ($diff->invert === 1 ? 'il y a' : 'dans'), $output);
+ elseif (abs($diff->d) > 0) $output = $diff->invert ? 'hier' : 'demain';
+ else $output = 'aujourd\'hui';
+ return $output;
+}
+
function generatePassword($length = 20) {
$chars = array_merge(
range('A', 'Z'),
@@ -109,7 +122,7 @@ if ($hasSupplier) {
$config[$supplier] = array_merge(
[
'title' => '',
- 'subtitle' => '%date%',
+ 'subtitle' => '%date% (%ago%)',
'description' => '',
'choices' => [],
'start' => 'now 00:00:00',
@@ -308,6 +321,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));
foreach (['title', 'subtitle', 'description'] as $key) {
while (preg_match('/%([^%]+)%/i', $config[$supplier][$key], $match))