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
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
23 * Helper plugin to assist other plugins with time manipulation, display.
25 * Any shared time-related code should go into this class.
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
33 class Phergie_Plugin_Time extends Phergie_Plugin_Abstract
36 * Returns the time interval between the current time and a given
39 * @param string $timestamp Timestamp compatible with strtotime()
43 public function getCountdown($timestamp)
45 $time = time() - strtotime($timestamp);
48 $days = floor($time / 86400);
50 $return[] = $days . 'd';
54 $hours = floor($time / 3600);
56 $return[] = $hours . 'h';
60 $minutes = floor($time / 60);
62 $return[] = $minutes . 'm';
66 if ($time > 0 || count($return) <= 0) {
67 $return[] = ($time > 0 ? $time : '0') . 's';
70 return implode(' ', $return);