5 ** Takes a date and parses it into a usable format. The form that a
6 ** date SHOULD arrive in is:
7 ** <Tue,> 29 Jun 1999 09:52:11 -0500 (EDT)
8 ** (as specified in RFC 822) -- "Tue" is optional
14 function getMinutes($hour) {
17 if (($hour == 0) ||
($hour == "00"))
19 else if (($hour == 1) ||
($hour == "01"))
21 else if (($hour == 2) ||
($hour == "02"))
23 else if (($hour == 3) ||
($hour == "03"))
25 else if (($hour == 4) ||
($hour == "04"))
27 else if (($hour == 5) ||
($hour == "05"))
29 else if (($hour == 6) ||
($hour == "06"))
31 else if (($hour == 7) ||
($hour == "07"))
33 else if (($hour == 8) ||
($hour == "08"))
35 else if (($hour == 9) ||
($hour == "09"))
41 // corrects a time stamp to be the local time
42 function getGMTSeconds($stamp, $gmt) {
43 if (($gmt == "Pacific") ||
($gmt == "PST"))
45 else if (($gmt == "EDT"))
47 else if (($gmt == "Eastern") ||
($gmt == "EST") ||
($gmt == "CDT"))
49 else if (($gmt == "Central") ||
($gmt == "CST") ||
($gmt == "MDT"))
51 else if (($gmt == "Mountain") ||
($gmt == "MST") ||
($gmt == "PDT"))
53 else if ($gmt == "BST")
55 else if ($gmt == "EET")
57 else if ($gmt == "GMT")
59 else if ($gmt == "HKT")
61 else if ($gmt == "IST")
63 else if ($gmt == "JST")
65 else if ($gmt == "MET")
67 else if ($gmt == "MET DST" ||
$gmt == "METDST")
74 if (substr($gmt, 0, 1) == "-") {
76 $gmt = substr($gmt, 1, strlen($gmt));
77 } else if (substr($gmt, 0, 1) == "+") {
79 $gmt = substr($gmt, 1, strlen($gmt));
83 $gmt = substr($gmt, 0, 2);
91 /** now find what the server is at **/
92 $current = date("Z", time());
93 $stamp = (int)$stamp - (int)$gmt +
(int)$current;
98 function getHour($hour) {
99 $time = explode(":", $hour);
103 function getMinute($min) {
104 $time = explode(":", $min);
108 function getSecond($sec) {
109 $time = explode(":", $sec);
113 function getMonthNum($month) {
114 if (eregi("jan|january", $month, $tmp))
116 else if (eregi("feb|february|febuary", $month, $tmp))
118 else if (eregi("mar|march", $month, $tmp))
120 else if (eregi("apr|april", $month, $tmp))
122 else if (eregi("may", $month, $tmp))
124 else if (eregi("jun|june", $month, $tmp))
126 else if (eregi("jul|july", $month, $tmp))
128 else if (eregi("aug|august", $month, $tmp))
130 else if (eregi("sep|sept|september", $month, $tmp))
132 else if (eregi("oct|october", $month, $tmp))
134 else if (eregi("nov|november", $month, $tmp))
136 else if (eregi("dec|december", $month, $tmp))
142 function getDayOfWeek($day) {
145 if (eregi("(mon|monday)", $day, $tmp))
147 else if (eregi("(tue|tuesday)", $day, $tmp))
149 else if (eregi("(wed|wednesday)", $day, $tmp))
151 else if (eregi("(thurs|thu|thursday)", $day, $tmp))
153 else if (eregi("(fri|friday)", $day, $tmp))
155 else if (eregi("(sat|saturday)", $day, $tmp))
157 else if (eregi("(sun|sunday)", $day, $tmp))
163 function getDayOfMonth($day) {
164 return ereg_replace("^0", "", $day); /* remove a preceeding 0 */
167 function getMonth($month) {
169 if (eregi("jan|january", $month, $tmp))
171 else if (eregi("feb|february|febuary", $month, $tmp))
173 else if (eregi("mar|march", $month, $tmp))
175 else if (eregi("apr|april", $month, $tmp))
177 else if (eregi("may", $month, $tmp))
179 else if (eregi("jun|june", $month, $tmp))
181 else if (eregi("jul|july", $month, $tmp))
183 else if (eregi("aug|august", $month, $tmp))
185 else if (eregi("sep|sept|september", $month, $tmp))
187 else if (eregi("oct|october", $month, $tmp))
189 else if (eregi("nov|november", $month, $tmp))
191 else if (eregi("dec|december", $month, $tmp))
197 function getYear($year) {
201 function getLongDateString($stamp) {
202 return date("D, F j, Y g:i a", $stamp);
205 function getDateString($stamp) {
207 $midnight = $now - ($now %
86400) - date("Z", $now);
209 if ($midnight < $stamp) {
211 return date("g:i a", $stamp);
212 } else if ($midnight - (60 * 60 * 24 * 6) < $stamp) {
214 return date("D, g:i a", $stamp);
217 return date("M j, Y", $stamp);
221 function getTimeStamp($dateParts) {
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)
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.
235 // Simply check to see if the first element in the dateParts
236 // array is an integer or not.
237 // Since the day of week is optional, this check is needed.
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.
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.
249 if (intval(trim($dateParts[0])) > 0) {
250 $time = explode(":", $dateParts[3]);
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]);
259 $time = explode(":", $dateParts[4]);
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]);
269 // I use this function for profiling. Should never be called in
270 // actual versions of squirrelmail released to public.
271 function getmicrotime() {
272 $mtime = microtime();
273 $mtime = explode(" ",$mtime);
274 $mtime = $mtime[1] +
$mtime[0];