blob: 28cec7917e4dfb75297c9a5c3e53de1bf94f7b87 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
<?php
namespace Bitweaver\Plugins;
/**
* Smarty plugin modifier duration
*
* Type: modifier
* Name: duration
* Purpose: formats a duration from seconds
*
* @package Smarty
* @subpackage plugins
*/
/**
* Function body.
*
* @param string $string Number of seconds
* @return string in format days,hours,minutes,seconds
*/
function smarty_modifier_duration($string)
{
$result=[];
if($string > 60*60*24) {
$days = floor($string/(60*60*24));
$result[]="$days days";
$string %= 60*60*24;
}
if($string > 60*60) {
$hours = floor($string/(60*60));
$result[]="$hours hours";
$string %= 60*60;
}
if($string > 60) {
$mins = floor($string/60);
$result[]="$mins minutes";
$string %= 60;
}
if($string > 0) {
$result[]="$string seconds";
}
return implode(' ',$result);
}
|