-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeelapsed_helper.php
More file actions
65 lines (58 loc) · 1.73 KB
/
Copy pathtimeelapsed_helper.php
File metadata and controls
65 lines (58 loc) · 1.73 KB
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
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Codeigniter Time Elapsed Helper
*
* This is a small helper to show Diff Human Time.
*
* @author Unknown (Core Method)
* @author Matheus de Lima (Helper create and adjustments)
*
* @copyright Public Domain
* @license http://matheusdelima.com/license.txt
*
*/
// time_elapsed_string() ------------------------------------------------------------------------
if ( ! function_exists('time_elapsed_string'))
{
/**
* Time Elapsed
*
* @author Unknown <me@ramonlapenta.com>
* @author Matheus De Lima Gomes <matheusdelimagomes@gmail.com>
* @param $ptime = Timestamp with STRTOTIME()
*
* @return String
*/
function time_elapsed_string($ptime)
{
$etime = time() - $ptime;
if ($etime < 1)
{
return '0 seconds';
}
$a = array( 365 * 24 * 60 * 60 => 'year',
30 * 24 * 60 * 60 => 'month',
24 * 60 * 60 => 'day',
60 * 60 => 'hour',
60 => 'minute',
1 => 'second'
);
$a_plural = array( 'ano' => 'years',
'mês' => 'months',
'dia' => 'days',
'hora' => 'times',
'minuto' => 'minutes',
'secundo' => 'seconds'
);
foreach ($a as $secs => $str)
{
$d = $etime / $secs;
if ($d >= 1)
{
$r = round($d);
return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' atrás.';
}
}
}
}
/* End of file timeelapsed_helper.php */