backoffice/application/helpers/functions_helper.php

91 lines
1.8 KiB
PHP
Raw Normal View History

<?php
if (!function_exists('duree')) {
function duree($time)
{
$tabTemps = array("jours" => 86400,
"h" => 3600,
"m" => 60,
"s" => 1);
$result = "";
foreach ($tabTemps as $uniteTemps => $nombreSecondesDansUnite) {
$$uniteTemps = floor($time / $nombreSecondesDansUnite);
$time = $time % $nombreSecondesDansUnite;
if ($$uniteTemps > 0 || !empty($result)) {
$result .= $$uniteTemps . " $uniteTemps ";
}
}
return $result;
}
}
if (!function_exists('dateDiff')) {
function dateDiff($date1, $date2, $class = null)
{
$diff = abs($date1 - $date2); // abs pour avoir la valeur absolute, ainsi éviter d'avoir une différence négative
$retour = array();
$tmp = $diff;
$second = $tmp % 60;
$tmp = floor(($tmp - $second) / 60);
$minute = $tmp % 60;
$tmp = floor(($tmp - $minute) / 60);
$heure = $tmp % 24;
$tmp = floor(($tmp - $heure) / 24);
$jour = $tmp;
return $class->lang->line('since') . ' ' . $jour . ' ' . $class->lang->line('days') . ' ' . $heure . ' ' . $class->lang->line('hours') . ' ' . $minute . ' ' . $class->lang->line('minutes') . ' ' . $second . ' ' . $class->lang->line('seconds');
}
}
if (!function_exists('traitementTemps')) {
function traitementTemps($time, $dateAjout, $class = null)
{
if ($time == null) {
$now = time();
$date2 = strtotime($dateAjout);
return dateDiff($now, $date2, $class);
} else {
return duree($time);
}
}
}
if (!function_exists('getDelayOfTreatmentInSeconds')) {
function getDelayOfTreatmentInSeconds($time, $dateAjout)
{
if ($time == null) {
$now = time();
$date2 = strtotime($dateAjout);
return abs($now - $date2);
} else {
return $time;
}
}
}
if ( ! function_exists('line_with_arguments'))
{
function line_with_arguments($line, $args = array())
{
return vsprintf($line, $args);
// return str_replace('%s', $swap, $line);
}
}