summaryrefslogtreecommitdiffstats
path: root/application/helpers
diff options
context:
space:
mode:
authorHrvoje Hodak <me@tribly.de>2018-01-26 15:09:29 +0100
committerFlorian Pritz <bluewind@xinu.at>2018-01-31 17:05:35 +0100
commit1c015d938ed4f31ffa647bcbcaaa8fd1ecf72c9f (patch)
tree04d4616e0a3860d39bc8ed05d65eb83df0606208 /application/helpers
parent283b4a4a1d8246c180a5be75558aa88847a1d6c5 (diff)
Proper display of expiration duration for less than a day
Diffstat (limited to 'application/helpers')
-rw-r--r--application/helpers/filebin_helper.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php
index ffecec98d..b89fe9bb3 100644
--- a/application/helpers/filebin_helper.php
+++ b/application/helpers/filebin_helper.php
@@ -1,5 +1,31 @@
<?php
+function expiration_duration($duration)
+{
+ $total = $duration;
+ $days = floor($total / 86400);
+ $total -= $days * 86400;
+ $hours = floor($total / 3600);
+ $total -= $hours * 3600;
+ $minutes = floor($total / 60);
+ $seconds = $total - $minutes * 60;
+ $times = array($days, $hours, $minutes, $seconds);
+ $suffixes = array(' day', ' hour', ' minute', ' second');
+ $expiration = array();
+
+ for ($i = 0; $i < count($suffixes); $i++) {
+ if ($times[$i] != 0) {
+ $duration = $times[$i].$suffixes[$i];
+ if ($times[$i] > 1) {
+ $duration .= "s";
+ }
+ array_push($expiration, $duration);
+ }
+ }
+
+ return join(", ", $expiration);
+}
+
function format_bytes($size)
{
$suffixes = array('B', 'KiB', 'MiB', 'GiB', 'TiB' , 'PiB' , 'EiB', 'ZiB', 'YiB');