-
Notifications
You must be signed in to change notification settings - Fork 0
/
MicrotimeExtension.php
75 lines (64 loc) · 1.46 KB
/
MicrotimeExtension.php
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Twig extension for displaying microtimes in a human readable way
*
* @author Gonzalo Vilaseca
* @date 04/04/2014
*/
namespace Foo\Bar;
/**
* Class MicrotimeExtension
* @package Sylius\Bundle\JobSchedulerBundle\Twig
*/
class MicrotimeExtension extends \Twig_Extension{
/**
*
* @return array
*/
public function getFilters()
{
return array(
new \Twig_SimpleFilter('microtime_date', array($this, 'microtimeDateFilter')),
new \Twig_SimpleFilter('microtime_exec_time', array($this, 'microtimeExecTimeFilter')),
);
}
/**
* Returns microtime in a human readable format
*
* @param $microtime
*
* @return null|string
*/
public function microtimeDateFilter($microtime)
{
if (is_null($microtime)){
return null;
}
$date = date("Y-m-d H:i:s",$microtime);
return "$date";
}
/**
* Returns duration
*
* @param $microtimeStart
* @param $microtimeEnd
*
* @return string
*/
public function microtimeExecTimeFilter($microtimeStart, $microtimeEnd)
{
if (is_null($microtimeStart) || is_null($microtimeEnd)){
return '0:0';
}
$duration = date('i:s', $microtimeEnd - $microtimeStart);
return "$duration";
}
/**
*
* @return string
*/
public function getName()
{
return 'microtime_extension';
}
}