1 | <?php |
||
23 | class RelativeTime |
||
24 | { |
||
25 | /** @var int Class constant with the current Version of this library */ |
||
26 | const VERSION = '1.5.4'; |
||
27 | |||
28 | /** @var array Array With configuration options **/ |
||
29 | protected $config = array(); |
||
30 | |||
31 | /** @var object instance of \Relativetime\Translation **/ |
||
32 | protected $translation; |
||
33 | |||
34 | /** |
||
35 | * Construct |
||
36 | * |
||
37 | * @param array $config Associative array with configuration directives |
||
38 | * |
||
39 | */ |
||
40 | 16 | public function __construct(array $config = array()) |
|
51 | |||
52 | /** |
||
53 | * Converts 2 dates to its relative time. |
||
54 | * |
||
55 | * @param string $fromTime |
||
56 | * @param string $toTime When null is given, uses the current date. |
||
57 | * @return string |
||
58 | */ |
||
59 | 16 | public function convert($fromTime, $toTime = null) |
|
66 | |||
67 | /** |
||
68 | * Tells the time passed between the current date and the given date |
||
69 | * |
||
70 | * @param string $date |
||
71 | * @return string |
||
72 | */ |
||
73 | 10 | public function timeAgo($date) |
|
82 | |||
83 | /** |
||
84 | * Tells the time until the given date |
||
85 | * |
||
86 | * @param string $date |
||
87 | * @return string |
||
88 | */ |
||
89 | 2 | public function timeLeft($date) |
|
98 | |||
99 | /** |
||
100 | * Calculates the interval between the dates and returns |
||
101 | * an array with the valid time. |
||
102 | * |
||
103 | * @param string $fromTime |
||
104 | * @param string $toTime When null is given, uses the current date. |
||
105 | * @return DateInterval |
||
106 | */ |
||
107 | 16 | protected function getInterval($fromTime, $toTime = null) |
|
114 | |||
115 | /** |
||
116 | * Normalizes a date for the DateTime class |
||
117 | * |
||
118 | * @param string $date |
||
119 | * @return string |
||
120 | */ |
||
121 | 16 | protected function normalizeDate($date) |
|
133 | |||
134 | /** |
||
135 | * Given a DateInterval, creates an array with the time |
||
136 | * units and truncates it when necesary. |
||
137 | * |
||
138 | * @param DateInterval $interval |
||
139 | * @return array |
||
140 | */ |
||
141 | 14 | protected function calculateUnits(DateInterval $interval) |
|
160 | } |
||
161 | ?> |
||
|
|||
162 |
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.