diff options
| author | ilotterytea <iltsu@alright.party> | 2025-06-04 18:44:10 +0400 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-06-04 18:44:10 +0400 |
| commit | 8245832be8470f20091eb71946fdeff3cab79aa7 (patch) | |
| tree | be375483c1e81f0ad3e23f688efe88fea5544366 /lib/utils.php | |
| parent | 27027f5b6a9ea2a4cb5f2324018be8ce0f22cc50 (diff) | |
feat: file page
Diffstat (limited to 'lib/utils.php')
| -rw-r--r-- | lib/utils.php | 18 |
1 files changed, 18 insertions, 0 deletions
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 |
