summaryrefslogtreecommitdiff
path: root/lib/utils.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils.php')
-rw-r--r--lib/utils.php18
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