diff options
| author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-08-19 11:35:09 +0000 |
|---|---|---|
| committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-08-19 11:35:09 +0000 |
| commit | 84a4272b58e6bcc5be3366adc5771851c522eae3 (patch) | |
| tree | e088fd336667817dda9b8b89ddb3ea0ee6a327b8 /frontends/php/include/func.inc.php | |
| parent | c18881cf3bf1288bff75ecb10df386ec25a0cab9 (diff) | |
| download | zabbix-84a4272b58e6bcc5be3366adc5771851c522eae3.tar.gz zabbix-84a4272b58e6bcc5be3366adc5771851c522eae3.tar.xz zabbix-84a4272b58e6bcc5be3366adc5771851c522eae3.zip | |
- [DEV-137] improvements in sqls (Artem)
git-svn-id: svn://svn.zabbix.com/trunk@5926 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include/func.inc.php')
| -rw-r--r-- | frontends/php/include/func.inc.php | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/frontends/php/include/func.inc.php b/frontends/php/include/func.inc.php index 253b731e..f01797be 100644 --- a/frontends/php/include/func.inc.php +++ b/frontends/php/include/func.inc.php @@ -187,22 +187,50 @@ function zbx_date2str($format, $timestamp){ * * author: Aly */ -function zbx_date2age($start_date,$end_date=0){ - - $start_date=date('U',$start_date); - if($end_date) - $end_date=date('U',$end_date); - else - $end_date = time(); +function zbx_date2age($start_date,$end_date=0,$utime = false){ + + if(!$utime){ + $start_date=date('U',$start_date); + if($end_date) + $end_date=date('U',$end_date); + else + $end_date = time(); + } $time = abs($end_date-$start_date); - //SDI($start_date.' - '.$end_date.' = '.$time); - + + $years = (int) ($time / (365*86400)); + $time -= $years*365*86400; + + $months = (int ) ($time / (30*86400)); + $time -= $months*30*86400; + $days = (int) ($time / 86400); - $hours = (int) (($time - $days*86400) / 3600); - $minutes = (int) ((($time - $days*86400) - ($hours*3600)) / 60); - $str = (($days)?$days.'d ':'').(($hours)?$hours.'h ':'').$minutes.'m'; + $time -= $days*86400; + + $hours = (int) ($time / 3600); + $time -= $hours*3600; + + $minutes = (int) ($time / 60); + $time -= $minutes*60; + + if($time > 1){ + $seconds = round($time,2); + $ms = 0; + } + else{ + $seconds = 0; + $ms = round($time,3) * 1000; + } + + $str = (($years)?$years.'y ':''). + (($months)?$months.'m ':''). + (($days)?$days.'d ':''). + (($hours && !$years)?$hours.'h ':''). + (($minutes && !$years && !$months)?$minutes.'m ':''). + ((!$years && !$months && !$days && (!$ms || $seconds))?$seconds.'s ':''). + (($ms && !$years && !$months && !$days && !$hours)?$ms.'ms':''); return $str; } |
