Welcome to mirror list, hosted at ThFree Co, Russian Federation.

modifier.sumtime.php « SmartyPlugins « modules - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3126946cdc93faed3d1ea14a7b361911a8b86449 (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
45
46
47
48
49
50
51
52
53
54
<?php
/**
 * Piwik - Open source web analytics
 * 
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
 * @version $Id$
 * 
 * @package SmartyPlugins
 */

/**
 * Returns a string that displays the number of days and hours from a number of seconds
 * 
 * How to use:
 * {4200|sumtime} will display '1h 10min'
 * 
 * Examples:
 * - 10 gives "10s"
 * - 4200 gives "1h 10min"
 * - 86400 gives "1 day"
 * - 90600 gives "1 day 1h" (it is exactly 1day 1h 10min but we truncate)
 * 
 * @return string
 * 
 */
function smarty_modifier_sumtime($string)
{
	$seconds = (double)$string;
	$days = floor($seconds / 86400);
	
	$minusDays = $seconds - $days * 86400;
	$hours = floor($minusDays / 3600);
	
	$minusDaysAndHours = $minusDays - $hours * 3600;
	$minutes = floor($minusDaysAndHours / 60 );
	
	$minusDaysAndHoursAndMinutes = $minusDaysAndHours - $minutes * 60;
	$secondsMod = $minusDaysAndHoursAndMinutes; // should be same as $seconds % 60 
	
	if($days > 0)
	{
		return sprintf("%d days %d hours", $days, $hours);
	}
	elseif($hours > 0)
	{
		return sprintf("%d hours %d min", $hours, $minutes);
	}
	else
	{
		return sprintf("%d min %d s", $minutes, $seconds);		
	}
}