Files
coolify/bootstrap/helpers/timezone.php
peaklabs-dev 85f38b7cb5 refactor: improve data formatting and UI
- move date and duration functions to a shared function
- remove duplicate code
- redesigned the deployment executions tab
- added start and end times for backups, scheduled tasks, deployments and docker cleanup executions
- calculated the duration for backups, scheduled tasks, deployments and Docker cleanup executions
- redesigned status badges with colors to make it easier to see your current status
- removed dependency on dayjs
- fixed calculation of execution time was sometimes incorrect
2025-01-15 18:35:20 +01:00

43 lines
989 B
PHP

<?php
function getServerTimezone($server = null)
{
if (! $server) {
return 'UTC';
}
return data_get($server, 'settings.server_timezone', 'UTC');
}
function formatDateInServerTimezone($date, $server = null)
{
$serverTimezone = getServerTimezone($server);
$dateObj = new \DateTime($date);
try {
$dateObj->setTimezone(new \DateTimeZone($serverTimezone));
} catch (\Exception) {
$dateObj->setTimezone(new \DateTimeZone('UTC'));
}
return $dateObj->format('Y-m-d H:i:s T');
}
function calculateDuration($startDate, $endDate = null)
{
if (! $endDate) {
return null;
}
$start = new \DateTime($startDate);
$end = new \DateTime($endDate);
$interval = $start->diff($end);
if ($interval->days > 0) {
return $interval->format('%dd %Hh %Im %Ss');
} elseif ($interval->h > 0) {
return $interval->format('%Hh %Im %Ss');
} else {
return $interval->format('%Im %Ss');
}
}