Adds a centralized datetime helper

main
Yasen Pramatarov 2026-01-28 19:30:56 +02:00
parent c418337736
commit 79f06f9f04
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
<?php
/**
* Datetime helper utilities.
*
* Centralized formatting for UTC timestamps into a specified timezone.
*/
if (!function_exists('app_format_local_datetime')) {
function app_format_local_datetime(?string $value, string $format, string $timezone): string
{
if (empty($value) || $value === '0000-00-00 00:00:00') {
return '';
}
try {
$utc = new DateTimeZone('UTC');
$tz = new DateTimeZone($timezone ?: 'UTC');
$date = new DateTimeImmutable($value, $utc);
return $date->setTimezone($tz)->format($format);
} catch (Throwable $e) {
return '';
}
}
}