]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Phergie/Plugin/Time.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / plugins / Irc / extlib / phergie / Phergie / Plugin / Time.php
1 <?php
2 /**
3  * Phergie 
4  *
5  * PHP version 5
6  *
7  * LICENSE
8  *
9  * This source file is subject to the new BSD license that is bundled
10  * with this package in the file LICENSE.
11  * It is also available through the world-wide-web at this URL:
12  * http://phergie.org/license
13  *
14  * @category  Phergie 
15  * @package   Phergie_Plugin_Time
16  * @author    Phergie Development Team <team@phergie.org>
17  * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
18  * @license   http://phergie.org/license New BSD License
19  * @link      http://pear.phergie.org/package/Phergie_Plugin_Time
20  */
21
22 /**
23  * Helper plugin to assist other plugins with time manipulation, display.
24  *
25  * Any shared time-related code should go into this class.
26  *
27  * @category Phergie
28  * @package  Phergie_Plugin_Time
29  * @author   Phergie Development Team <team@phergie.org>
30  * @license  http://phergie.org/license New BSD License
31  * @link     http://pear.phergie.org/package/Phergie_Plugin_Time
32  */
33 class Phergie_Plugin_Time extends Phergie_Plugin_Abstract 
34 {
35     /**
36      * Returns the time interval between the current time and a given 
37      * timestamp. 
38      *
39      * @param string $timestamp Timestamp compatible with strtotime()
40      *
41      * @return string
42      */
43     public function getCountdown($timestamp)
44     {
45         $time = time() - strtotime($timestamp); 
46         $return = array();
47
48         $days = floor($time / 86400);
49         if ($days > 0) {
50             $return[] = $days . 'd';
51             $time %= 86400;
52         }
53
54         $hours = floor($time / 3600);
55         if ($hours > 0) {
56             $return[] = $hours . 'h';
57             $time %= 3600;
58         }
59
60         $minutes = floor($time / 60);
61         if ($minutes > 0) {
62             $return[] = $minutes . 'm';
63             $time %= 60;
64         }
65
66         if ($time > 0 || count($return) <= 0) {
67             $return[] = ($time > 0 ? $time : '0') . 's';
68         }
69
70         return implode(' ', $return);
71     }
72 }