Files
ms1readerv4/ci4app/app/Helpers/format_helper.php
2026-07-17 11:48:07 -04:00

47 lines
1.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use CodeIgniter\I18n\Time;
/**
* format_output
* -------------------
* Transforme une valeur (ex. timestamp Unix) selon un "type" doutput.
*
* @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";
}
}