Browse Source

ajoute l'ago

master
vince vince 3 years ago
parent
commit
9307d58ece
1 changed files with 15 additions and 1 deletions
  1. +15
    -1
      index.php

+ 15
- 1
index.php View File

@ -25,6 +25,19 @@ if (preg_match(REQUEST_REGEX, $requestUrl, $match)) {
$requestEvent = null; $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) { function generatePassword($length = 20) {
$chars = array_merge( $chars = array_merge(
range('A', 'Z'), range('A', 'Z'),
@ -109,7 +122,7 @@ if ($hasSupplier) {
$config[$supplier] = array_merge( $config[$supplier] = array_merge(
[ [
'title' => '', 'title' => '',
'subtitle' => '<small class="text-muted text-nowrap d-block d-sm-inline">%date%</small>',
'subtitle' => '<small class="text-muted text-nowrap d-block d-sm-inline">%date% (%ago%)</small>',
'description' => '', 'description' => '',
'choices' => [], 'choices' => [],
'start' => 'now 00:00:00', '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)); $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) { foreach (['title', 'subtitle', 'description'] as $key) {
while (preg_match('/%([^%]+)%/i', $config[$supplier][$key], $match)) while (preg_match('/%([^%]+)%/i', $config[$supplier][$key], $match))


Loading…
Cancel
Save