From 8245832be8470f20091eb71946fdeff3cab79aa7 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 4 Jun 2025 18:44:10 +0400 Subject: feat: file page --- lib/utils.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/utils.php') diff --git a/lib/utils.php b/lib/utils.php index 2dab763..31d8778 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -21,4 +21,22 @@ function generate_random_char_sequence(array $chars, int $length): string } return $o; +} + +function format_timestamp(int $timestamp_secs) +{ + $days = (int) floor($timestamp_secs / (60.0 * 60.0 * 24.0)); + $hours = (int) floor(round($timestamp_secs / (60 * 60)) % 24); + $minutes = (int) floor(round($timestamp_secs % (60 * 60)) / 60); + $seconds = (int) floor($timestamp_secs % 60); + + if ($days == 0 && $hours == 0 && $minutes == 0) { + return "$seconds second" . ($seconds > 1 ? "s" : ""); + } else if ($days == 0 && $hours == 0) { + return "$minutes minute" . ($minutes > 1 ? "s" : ""); + } else if ($days == 0) { + return "$hours hour" . ($hours > 1 ? "s" : ""); + } else { + return "$days day" . ($days > 1 ? "s" : ""); + } } \ No newline at end of file -- cgit v1.2.3