59177427 |
1 | <?php |
3302d0d4 |
2 | /** |
a09387f4 |
3 | ** date.php |
3302d0d4 |
4 | ** |
5 | ** Takes a date and parses it into a usable format. The form that a |
6 | ** date SHOULD arrive in is: |
5b10f02a |
7 | ** <Tue,> 29 Jun 1999 09:52:11 -0500 (EDT) |
8 | ** (as specified in RFC 822) -- "Tue" is optional |
3302d0d4 |
9 | ** |
10 | **/ |
11 | |
d068c0ec |
12 | $date_php = true; |
13 | |
aceb0d5c |
14 | function getMinutes($hour) { |
15 | $date = $hour; |
16 | |
17 | if (($hour == 0) || ($hour == "00")) |
18 | $date = "00"; |
19 | else if (($hour == 1) || ($hour == "01")) |
20 | $date = "01"; |
21 | else if (($hour == 2) || ($hour == "02")) |
22 | $date = "02"; |
23 | else if (($hour == 3) || ($hour == "03")) |
24 | $date = "03"; |
25 | else if (($hour == 4) || ($hour == "04")) |
26 | $date = "04"; |
27 | else if (($hour == 5) || ($hour == "05")) |
28 | $date = "05"; |
29 | else if (($hour == 6) || ($hour == "06")) |
30 | $date = "06"; |
31 | else if (($hour == 7) || ($hour == "07")) |
32 | $date = "07"; |
33 | else if (($hour == 8) || ($hour == "08")) |
34 | $date = "08"; |
35 | else if (($hour == 9) || ($hour == "09")) |
36 | $date = "09"; |
37 | |
38 | return $date; |
39 | } |
40 | |
0f1835f3 |
41 | // corrects a time stamp to be the local time |
42 | function getGMTSeconds($stamp, $gmt) { |
e5b4c610 |
43 | if (($gmt == "Pacific") || ($gmt == "PST")) |
ddd32bad |
44 | $gmt = "-0800"; |
e5b4c610 |
45 | else if (($gmt == "EDT")) |
46 | $gmt = "-0400"; |
47 | else if (($gmt == "Eastern") || ($gmt == "EST") || ($gmt == "CDT")) |
ddd32bad |
48 | $gmt = "-0500"; |
e5b4c610 |
49 | else if (($gmt == "Central") || ($gmt == "CST") || ($gmt == "MDT")) |
ddd32bad |
50 | $gmt = "-0600"; |
e5b4c610 |
51 | else if (($gmt == "Mountain") || ($gmt == "MST") || ($gmt == "PDT")) |
ddd32bad |
52 | $gmt = "-0700"; |
e5b4c610 |
53 | else if ($gmt == "BST") |
54 | $gmt = "+0100"; |
55 | else if ($gmt == "EET") |
56 | $gmt = "+0200"; |
57 | else if ($gmt == "GMT") |
58 | $gmt = "+0000"; |
59 | else if ($gmt == "HKT") |
60 | $gmt = "+0800"; |
61 | else if ($gmt == "IST") |
62 | $gmt = "+0200"; |
63 | else if ($gmt == "JST") |
64 | $gmt = "+0900"; |
65 | else if ($gmt == "MET") |
66 | $gmt = "+0100"; |
67 | else if ($gmt == "MET DST" || $gmt == "METDST") |
68 | $gmt = "+0200"; |
47654bfb |
69 | |
70 | if ($gmt = "") |
71 | $gmt = "+0000"; |
ddd32bad |
72 | |
47654bfb |
73 | /* |
0f1835f3 |
74 | if (substr($gmt, 0, 1) == "-") { |
75 | $neg = true; |
76 | $gmt = substr($gmt, 1, strlen($gmt)); |
77 | } else if (substr($gmt, 0, 1) == "+") { |
78 | $neg = false; |
79 | $gmt = substr($gmt, 1, strlen($gmt)); |
80 | } else |
81 | $neg = false; |
82 | |
83 | $gmt = substr($gmt, 0, 2); |
84 | $gmt = $gmt * 3600; |
85 | if ($neg == true) |
86 | $gmt = "-$gmt"; |
87 | else |
88 | $gmt = "+$gmt"; |
47654bfb |
89 | */ |
0f1835f3 |
90 | |
91 | /** now find what the server is at **/ |
92 | $current = date("Z", time()); |
0f1835f3 |
93 | $stamp = (int)$stamp - (int)$gmt + (int)$current; |
94 | |
95 | return $stamp; |
96 | } |
97 | |
3302d0d4 |
98 | function getHour($hour) { |
99 | $time = explode(":", $hour); |
100 | return $time[0]; |
101 | } |
102 | |
103 | function getMinute($min) { |
104 | $time = explode(":", $min); |
105 | return $time[1]; |
106 | } |
107 | |
108 | function getSecond($sec) { |
109 | $time = explode(":", $sec); |
110 | return $time[2]; |
111 | } |
112 | |
113 | function getMonthNum($month) { |
114 | if (eregi("jan|january", $month, $tmp)) |
115 | $date = "01"; |
116 | else if (eregi("feb|february|febuary", $month, $tmp)) |
117 | $date = "02"; |
118 | else if (eregi("mar|march", $month, $tmp)) |
119 | $date = "03"; |
120 | else if (eregi("apr|april", $month, $tmp)) |
121 | $date = "04"; |
122 | else if (eregi("may", $month, $tmp)) |
123 | $date = "05"; |
124 | else if (eregi("jun|june", $month, $tmp)) |
125 | $date = "06"; |
126 | else if (eregi("jul|july", $month, $tmp)) |
127 | $date = "07"; |
128 | else if (eregi("aug|august", $month, $tmp)) |
129 | $date = "08"; |
130 | else if (eregi("sep|sept|september", $month, $tmp)) |
131 | $date = "09"; |
132 | else if (eregi("oct|october", $month, $tmp)) |
133 | $date = "10"; |
134 | else if (eregi("nov|november", $month, $tmp)) |
135 | $date = "11"; |
136 | else if (eregi("dec|december", $month, $tmp)) |
137 | $date = "12"; |
138 | |
139 | return $date; |
140 | } |
141 | |
142 | function getDayOfWeek($day) { |
143 | $date = "{WEEKDAY}"; |
144 | |
145 | if (eregi("(mon|monday)", $day, $tmp)) |
146 | $date = "Mon"; |
147 | else if (eregi("(tue|tuesday)", $day, $tmp)) |
148 | $date = "Tue"; |
149 | else if (eregi("(wed|wednesday)", $day, $tmp)) |
150 | $date = "Wed"; |
151 | else if (eregi("(thurs|thu|thursday)", $day, $tmp)) |
152 | $date = "Thu"; |
153 | else if (eregi("(fri|friday)", $day, $tmp)) |
154 | $date = "Fri"; |
155 | else if (eregi("(sat|saturday)", $day, $tmp)) |
156 | $date = "Sat"; |
157 | else if (eregi("(sun|sunday)", $day, $tmp)) |
158 | $date = "Sun"; |
159 | |
160 | return $date; |
161 | } |
162 | |
163 | function getDayOfMonth($day) { |
164 | return ereg_replace("^0", "", $day); /* remove a preceeding 0 */ |
165 | } |
166 | |
167 | function getMonth($month) { |
168 | $date = "{MONTH}"; |
169 | if (eregi("jan|january", $month, $tmp)) |
170 | $date = "Jan"; |
171 | else if (eregi("feb|february|febuary", $month, $tmp)) |
172 | $date = "Feb"; |
173 | else if (eregi("mar|march", $month, $tmp)) |
174 | $date = "Mar"; |
175 | else if (eregi("apr|april", $month, $tmp)) |
176 | $date = "Apr"; |
177 | else if (eregi("may", $month, $tmp)) |
178 | $date = "May"; |
179 | else if (eregi("jun|june", $month, $tmp)) |
180 | $date = "Jun"; |
181 | else if (eregi("jul|july", $month, $tmp)) |
182 | $date = "Jul"; |
183 | else if (eregi("aug|august", $month, $tmp)) |
184 | $date = "Aug"; |
185 | else if (eregi("sep|sept|september", $month, $tmp)) |
186 | $date = "Sep"; |
187 | else if (eregi("oct|october", $month, $tmp)) |
188 | $date = "Oct"; |
189 | else if (eregi("nov|november", $month, $tmp)) |
190 | $date = "Nov"; |
191 | else if (eregi("dec|december", $month, $tmp)) |
192 | $date = "Dec"; |
193 | |
194 | return $date; |
195 | } |
196 | |
197 | function getYear($year) { |
198 | return $year; |
199 | } |
200 | |
0f1835f3 |
201 | function getLongDateString($stamp) { |
202 | return date("D, F j, Y g:i a", $stamp); |
203 | } |
204 | |
205 | function getDateString($stamp) { |
d68a3926 |
206 | $now = time(); |
069b4374 |
207 | $midnight = $now - ($now % 86400) - date("Z", $now); |
d68a3926 |
208 | |
209 | if ($midnight < $stamp) { |
210 | // Today |
211 | return date("g:i a", $stamp); |
069b4374 |
212 | } else if ($midnight - (60 * 60 * 24 * 6) < $stamp) { |
d68a3926 |
213 | // This week |
214 | return date("D, g:i a", $stamp); |
215 | } else { |
216 | // before this week |
217 | return date("M j, Y", $stamp); |
218 | } |
0f1835f3 |
219 | } |
220 | |
221 | function getTimeStamp($dateParts) { |
3302d0d4 |
222 | /** $dateParts[0] == <day of week> Mon, Tue, Wed |
223 | ** $dateParts[1] == <day of month> 23 |
224 | ** $dateParts[2] == <month> Jan, Feb, Mar |
225 | ** $dateParts[3] == <year> 1999 |
226 | ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS) |
227 | ** $dateParts[5] == <from GMT> +0100 |
228 | ** $dateParts[6] == <zone> (EDT) |
229 | ** |
230 | ** NOTE: In RFC 822, it states that <day of week> is optional. |
231 | ** In that case, dateParts[0] would be the <day of month> |
232 | ** and everything would be bumped up one. |
233 | **/ |
234 | |
d068c0ec |
235 | // Simply check to see if the first element in the dateParts |
236 | // array is an integer or not. |
5e90d34a |
237 | // Since the day of week is optional, this check is needed. |
238 | // |
d068c0ec |
239 | // The old code used eregi("mon|tue|wed|thu|fri|sat|sun", |
240 | // $dateParts[0], $tmp) to find if the first element was the |
241 | // day of week or day of month. This is an expensive call |
242 | // (processing time) to have inside a loop. Doing it this way |
243 | // saves quite a bit of time for large mailboxes. |
5e90d34a |
244 | // |
d068c0ec |
245 | // It is also quicker to call explode only once rather than |
246 | // the 3 times it was getting called by calling the functions |
247 | // getHour, getMinute, and getSecond. |
5e90d34a |
248 | // |
249 | if (intval(trim($dateParts[0])) > 0) { |
250 | $time = explode(":", $dateParts[3]); |
251 | $d[0] = $time[0]; |
252 | $d[1] = $time[1]; |
253 | $d[2] = $time[2]; |
254 | $d[3] = getMonthNum(trim($dateParts[1])); |
255 | $d[4] = getDayOfMonth(trim($dateParts[0])); |
256 | $d[5] = getYear(trim($dateParts[2])); |
257 | return getGMTSeconds(mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]), $dateParts[4]); |
5b10f02a |
258 | } |
5e90d34a |
259 | $time = explode(":", $dateParts[4]); |
260 | $d[0] = $time[0]; |
261 | $d[1] = $time[1]; |
262 | $d[2] = $time[2]; |
263 | $d[3] = getMonthNum(trim($dateParts[2])); |
264 | $d[4] = getDayOfMonth(trim($dateParts[1])); |
265 | $d[5] = getYear(trim($dateParts[3])); |
266 | return getGMTSeconds(mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]), $dateParts[5]); |
267 | } |
268 | |
d068c0ec |
269 | // I use this function for profiling. Should never be called in |
270 | // actual versions of squirrelmail released to public. |
5e90d34a |
271 | function getmicrotime() { |
272 | $mtime = microtime(); |
273 | $mtime = explode(" ",$mtime); |
274 | $mtime = $mtime[1] + $mtime[0]; |
275 | return ($mtime); |
9774bdef |
276 | } |
3302d0d4 |
277 | ?> |