47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
||
|
||
use CodeIgniter\I18n\Time;
|
||
|
||
/**
|
||
* format_output
|
||
* -------------------
|
||
* Transforme une valeur (ex. timestamp Unix) selon un "type" d’output.
|
||
*
|
||
* @param string|int|float $value La valeur à convertir (souvent un timestamp)
|
||
* @param string $type Le type de format ("AMJHMS", etc.)
|
||
* @param string $tz Fuseau horaire (défaut = America/Toronto)
|
||
* @return string
|
||
*/
|
||
function format_output($value, string $type, string $tz = 'America/Toronto'): string
|
||
{
|
||
if ($value === null || $value === '') {
|
||
return '';
|
||
}
|
||
|
||
// Convertir la valeur en timestamp entier
|
||
$timestamp = (int) $value;
|
||
|
||
// Créer un objet Time à partir de ce timestamp
|
||
$time = Time::createFromTimestamp($timestamp, $tz);
|
||
|
||
switch (strtoupper($type)) {
|
||
|
||
// -------------------------
|
||
// AMJHMS = Année-Mois-Jour Heure:Minute:Seconde
|
||
// Exemple: 2025-08-05 14:03:00
|
||
// -------------------------
|
||
case 'AMJHMS':
|
||
return $time->format('Y/m/d H:i:s');
|
||
|
||
// -------------------------
|
||
// Tu vas pouvoir ajouter d'autres types ici :
|
||
// AMJ = Y-m-d
|
||
// HMS = H:i:s
|
||
// etc.
|
||
// -------------------------
|
||
|
||
default:
|
||
return "FORMAT_INCONNU";
|
||
}
|
||
}
|