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 // corrects a time stamp to be the local time
15 function getGMTSeconds($stamp, $gmt) {
17 if (($gmt == "Pacific") ||
($gmt == "PST"))
19 else if (($gmt == "EDT"))
21 else if (($gmt == "Eastern") ||
($gmt == "EST") ||
($gmt == "CDT"))
23 else if (($gmt == "Central") ||
($gmt == "CST") ||
($gmt == "MDT"))
25 else if (($gmt == "Mountain") ||
($gmt == "MST") ||
($gmt == "PDT"))
27 else if ($gmt == "BST")
29 else if ($gmt == "EET")
31 else if ($gmt == "GMT")
33 else if ($gmt == "HKT")
35 else if ($gmt == "IST")
37 else if ($gmt == "JST")
39 else if ($gmt == "MET")
41 else if ($gmt == "MET DST" ||
$gmt == "METDST")
44 if (substr($gmt, 0, 1) == "-") {
46 $gmt = substr($gmt, 1, strlen($gmt));
47 } else if (substr($gmt, 0, 1) == "+") {
49 $gmt = substr($gmt, 1, strlen($gmt));
53 $gmt = substr($gmt, 0, 2);
60 /** now find what the server is at **/
61 $current = date("Z", time());
63 $current = - $current;
64 $stamp = (int)$stamp - (int)$gmt +
(int)$current;
69 function getLongDateString($stamp) {
70 return date("D, F j, Y g:i a", $stamp);
73 function getDateString($stamp) {
76 $dateZ = date("Z", $now);
79 $midnight = $now - ($now %
86400) - $dateZ;
81 if ($midnight < $stamp) {
83 return date("g:i a", $stamp);
84 } else if ($midnight - (60 * 60 * 24 * 6) < $stamp) {
86 return date("D, g:i a", $stamp);
89 return date("M j, Y", $stamp);
93 function getTimeStamp($dateParts) {
94 /** $dateParts[0] == <day of week> Mon, Tue, Wed
95 ** $dateParts[1] == <day of month> 23
96 ** $dateParts[2] == <month> Jan, Feb, Mar
97 ** $dateParts[3] == <year> 1999
98 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
99 ** $dateParts[5] == <from GMT> +0100
100 ** $dateParts[6] == <zone> (EDT)
102 ** NOTE: In RFC 822, it states that <day of week> is optional.
103 ** In that case, dateParts[0] would be the <day of month>
104 ** and everything would be bumped up one.
107 // Simply check to see if the first element in the dateParts
108 // array is an integer or not.
109 // Since the day of week is optional, this check is needed.
111 // The old code used eregi("mon|tue|wed|thu|fri|sat|sun",
112 // $dateParts[0], $tmp) to find if the first element was the
113 // day of week or day of month. This is an expensive call
114 // (processing time) to have inside a loop. Doing it this way
115 // saves quite a bit of time for large mailboxes.
117 // It is also quicker to call explode only once rather than
118 // the 3 times it was getting called by calling the functions
119 // getHour, getMinute, and getSecond.
121 if (intval(trim($dateParts[0])) > 0) {
122 $string = $dateParts[0] . " " . $dateParts[1] . " " . $dateParts[2] . " " . $dateParts[3];
123 return getGMTSeconds(strtotime($string), $dateParts[4]);
125 $string = $dateParts[0] . " " . $dateParts[1] . " " . $dateParts[2] . " " . $dateParts[3] . " " . $dateParts[4];
126 return getGMTSeconds(strtotime($string), $dateParts[5]);
129 // I use this function for profiling. Should never be called in
130 // actual versions of squirrelmail released to public.
131 function getmicrotime() {
132 $mtime = microtime();
133 $mtime = explode(" ",$mtime);
134 $mtime = $mtime[1] +
$mtime[0];