Switch to gettext for i18n
[gitphp.git] / include / smartyplugins / modifier.agestring.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
<?php
/*
 *  modifier.agestring.php
 *  gitphp: A PHP git repository browser
 *  Component: Utility - convert age to a readable string
 *
 *  Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
 */
 
function smarty_modifier_agestring($age)
{
        if ($age > 60*60*24*365*2)
                return sprintf(GitPHP_Resource::GetInstance()->GetResource('%1$d years ago'), (int)($age/60/60/24/365));
        else if ($age > 60*60*24*(365/12)*2)
                return sprintf(GitPHP_Resource::GetInstance()->GetResource('%1$d months ago'), (int)($age/60/60/24/(365/12)));
        else if ($age > 60*60*24*7*2)
                return sprintf(GitPHP_Resource::GetInstance()->GetResource('%1$d weeks ago'), (int)($age/60/60/24/7));
        else if ($age > 60*60*24*2)
                return sprintf(GitPHP_Resource::GetInstance()->GetResource('%1$d days ago'), (int)($age/60/60/24));
        else if ($age > 60*60*2)
                return sprintf(GitPHP_Resource::GetInstance()->GetResource('%1$d hours ago'), (int)($age/60/60));
        else if ($age > 60*2)
                return sprintf(GitPHP_Resource::GetInstance()->GetResource('%1$d min ago'), (int)($age/60));
        else if ($age > 2)
                return sprintf(GitPHP_Resource::GetInstance()->GetResource('%1$d sec ago'), (int)$age);
        return GitPHP_Resource::GetInstance()->GetResource('right now');
}
 
?>
 
comments