]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/includes/utils/ctimeutils.class.php
cd3b13a4df9992d804101ed9ec0af01ffc157bec
[bacula/bacula] / gui / bacula-web / includes / utils / ctimeutils.class.php
1 <?php
2 /* 
3 +-------------------------------------------------------------------------+
4 | Copyright 2010-2011, Davide Franco                                              |
5 |                                                                         |
6 | This program is free software; you can redistribute it and/or           |
7 | modify it under the terms of the GNU General Public License             |
8 | as published by the Free Software Foundation; either version 2          |
9 | of the License, or (at your option) any later version.                  |
10 |                                                                         |
11 | This program is distributed in the hope that it will be useful,         |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
14 | GNU General Public License for more details.                            |
15 +-------------------------------------------------------------------------+ 
16 */
17
18 class TimeUtils {
19         static public function Get_Elapsed_Time( $start_time, $end_time)
20         {
21                 $start = '';
22                 $end   = '';
23                 
24                 if( $start_time == '0000-00-00 00:00:00' )
25                         return 'N/A';
26                 else
27                         $start = strtotime( $start_time );                                      
28         
29                 if( $end_time == '0000-00-00 00:00:00' )
30                         $end = mktime();
31                 else
32                         $end   = strtotime( $end_time );
33                 
34                 $diff = $end - $start;
35
36         $daysDiff = sprintf("%02d", floor($diff/60/60/24) );
37         $diff -= $daysDiff*60*60*24;
38
39         $hrsDiff = sprintf("%02d", floor($diff/60/60) );
40         $diff -= $hrsDiff*60*60;
41
42         $minsDiff = sprintf("%02d", floor($diff/60) );
43         $diff -= $minsDiff*60;
44         $secsDiff = sprintf("%02d", $diff );
45
46         if( $daysDiff > 0 )
47                         return $daysDiff . 'day(s) ' . $hrsDiff.':' . $minsDiff . ':' . $secsDiff;
48         else
49                         return $hrsDiff . ':' . $minsDiff . ':' . $secsDiff;
50         }
51 }
52
53 ?>