1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17: 18: 19: 20: 21: 22: 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: 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: 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: