summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorilotterytea <me@ilotterytea.kz>2025-10-10 20:55:37 +0500
committerilotterytea <me@ilotterytea.kz>2025-10-10 20:55:37 +0500
commitb1a885ac229892bac528e6fea4e011a1b240867b (patch)
tree48152aa48c41defe7f850390ea1c99db2c725438 /lib
initial commit
Diffstat (limited to 'lib')
-rw-r--r--lib/time.php21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/time.php b/lib/time.php
new file mode 100644
index 0000000..dc8b54f
--- /dev/null
+++ b/lib/time.php
@@ -0,0 +1,21 @@
+<?php
+function format_timestamp(int $timestamp)
+{
+ $days = (int) floor($timestamp / (60.0 * 60.0 * 24.0));
+ $years = (int) floor($days / 365);
+ $hours = (int) floor(round($timestamp / (60 * 60)) % 24);
+ $minutes = (int) floor(round($timestamp % (60 * 60)) / 60);
+ $seconds = (int) floor($timestamp % 60);
+
+ if ($years == 0 && $days == 0 && $hours == 0 && $minutes == 0) {
+ return "$seconds second" . ($seconds > 1 ? "s" : "");
+ } else if ($years == 0 && $days == 0 && $hours == 0) {
+ return "$minutes minute" . ($minutes > 1 ? "s" : "");
+ } else if ($years == 0 && $days == 0) {
+ return "$hours hour" . ($hours > 1 ? "s" : "");
+ } else if ($years == 0) {
+ return "$days day" . ($days > 1 ? "s" : "");
+ } else {
+ return "$years year" . ($years > 1 ? "s" : "");
+ }
+} \ No newline at end of file