Overview

Packages

  • View
    • Helper

Classes

  • Horde_View_Helper_Base
  • Horde_View_Helper_Benchmark
  • Horde_View_Helper_Benchmark_Timer
  • Horde_View_Helper_Block
  • Horde_View_Helper_Capture
  • Horde_View_Helper_Capture_Base
  • Horde_View_Helper_Capture_ContentFor
  • Horde_View_Helper_Date
  • Horde_View_Helper_Debug
  • Horde_View_Helper_Form
  • Horde_View_Helper_Form_Builder
  • Horde_View_Helper_Form_InstanceTag_Base
  • Horde_View_Helper_Form_InstanceTag_Form
  • Horde_View_Helper_FormTag
  • Horde_View_Helper_Javascript
  • Horde_View_Helper_Number
  • Horde_View_Helper_Tag
  • Horde_View_Helper_Text
  • Horde_View_Helper_Text_Cycle
  • Horde_View_Helper_Url
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Copyright 2007-2008 Maintainable Software, LLC
 4:  * Copyright 2006-2012 Horde LLC (http://www.horde.org/)
 5:  *
 6:  * @author     Mike Naberezny <mike@maintainable.com>
 7:  * @author     Derek DeVries <derek@maintainable.com>
 8:  * @author     Chuck Hagenbuch <chuck@horde.org>
 9:  * @license    http://www.horde.org/licenses/bsd
10:  * @category   Horde
11:  * @package    View
12:  * @subpackage Helper
13:  */
14: 
15: /**
16:  * @author     Mike Naberezny <mike@maintainable.com>
17:  * @author     Derek DeVries <derek@maintainable.com>
18:  * @author     Chuck Hagenbuch <chuck@horde.org>
19:  * @license    http://www.horde.org/licenses/bsd
20:  * @category   Horde
21:  * @package    View
22:  * @subpackage Helper
23:  */
24: class Horde_View_Helper_Date extends Horde_View_Helper_Base
25: {
26:     private $_instanceTag = 'Horde_View_Helper_Form_InstanceTag_Date';
27: 
28:     /**
29:      * @todo possibly convert from time object
30:      */
31:     public function distanceOfTimeInWords($fromTime, $toTime = 0,
32:                                           $includeSeconds = false)
33:     {
34:         $distanceInMinutes = round(abs($toTime - $fromTime) / 60);
35:         $distanceInSeconds = round(abs($toTime - $fromTime));
36: 
37:         if ($distanceInMinutes >= 0 && $distanceInMinutes <= 1) {
38:             if (!$includeSeconds) {
39:                 return ($distanceInMinutes == 0)
40:                     ? 'less than a minute'
41:                     : '1 minute';
42:             }
43: 
44:             if ($distanceInSeconds >= 0 && $distanceInSeconds <= 4) {
45:                 return 'less than 5 seconds';
46:             } elseif ($distanceInSeconds >= 5 && $distanceInSeconds <= 9) {
47:                 return 'less than 10 seconds';
48:             } elseif ($distanceInSeconds >= 10 && $distanceInSeconds <= 19) {
49:                 return 'less than 20 seconds';
50:             } elseif ($distanceInSeconds >= 20 && $distanceInSeconds <= 39) {
51:                 return 'half a minute';
52:             } elseif ($distanceInSeconds >= 40 && $distanceInSeconds <= 59) {
53:                 return 'less than a minute';
54:             } else {
55:                 return '1 minute';
56:             }
57:         } elseif ($distanceInMinutes >= 2 && $distanceInMinutes <= 44) {
58:             return "$distanceInMinutes minutes";
59:         } elseif ($distanceInMinutes >= 45 && $distanceInMinutes <= 89) {
60:             return 'about 1 hour';
61:         } elseif ($distanceInMinutes >= 90 && $distanceInMinutes <= 1439) {
62:             return 'about ' . round($distanceInMinutes / 60) . ' hours';
63:         } elseif ($distanceInMinutes >= 1440 && $distanceInMinutes <= 2879) {
64:             return '1 day';
65:         } elseif ($distanceInMinutes >= 2880 && $distanceInMinutes <= 43199) {
66:             return intval($distanceInMinutes / 1440) . ' days';
67:         } elseif ($distanceInMinutes >= 43200 && $distanceInMinutes <= 86399) {
68:             return 'about 1 month';
69:         } elseif ($distanceInMinutes >= 86400 && $distanceInMinutes <= 525959) {
70:             return round(($distanceInMinutes / 43200)) . ' months';
71:         } elseif ($distanceInMinutes >= 525960 && $distanceInMinutes <= 1051919) {
72:             return 'about 1 year';
73:         } else {
74:             return 'over ' . round($distanceInMinutes / 525600) . ' years';
75:         }
76:     }
77: 
78:     /**
79:      * Like distanceOfTimeInWords(), but where $toTime is fixed to now.
80:      */
81:     public function timeAgoInWords($fromTime, $includeSeconds = false)
82:     {
83:         return $this->distanceOfTimeInWords($fromTime, time(), $includeSeconds);
84:     }
85: 
86:     public function dateSelect($objectName, $method, $options = array())
87:     {
88:         $object = isset($options['object']) ? $options['object'] : null;
89:         unset($options['object']);
90:         $tag = new $this->_instanceTag($objectName, $method, $this->_view, $object);
91:         return $tag->toDateSelectTag($options);
92:     }
93: }
94: 
API documentation generated by ApiGen