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
15 // corrects a time stamp to be the local time
16 function getGMTSeconds($stamp, $gmt) {
18 if (($gmt == 'Pacific') ||
($gmt == 'PST'))
20 else if (($gmt == 'EDT'))
22 else if (($gmt == 'Eastern') ||
($gmt == 'EST') ||
($gmt == 'CDT'))
24 else if (($gmt == 'Central') ||
($gmt == 'CST') ||
($gmt == 'MDT'))
26 else if (($gmt == 'Mountain') ||
($gmt == 'MST') ||
($gmt == 'PDT'))
28 else if ($gmt == 'BST')
30 else if ($gmt == 'EET')
32 else if ($gmt == 'GMT')
34 else if ($gmt == 'HKT')
36 else if ($gmt == 'IST')
38 else if ($gmt == 'JST')
40 else if ($gmt == 'MET')
42 else if ($gmt == 'MET DST' ||
$gmt == 'METDST')
45 if (substr($gmt, 0, 1) == '-') {
47 $gmt = substr($gmt, 1, strlen($gmt));
48 } else if (substr($gmt, 0, 1) == '+') {
50 $gmt = substr($gmt, 1, strlen($gmt));
54 $gmt = substr($gmt, 0, 2);
61 /** now find what the server is at **/
62 $current = date('Z', time());
64 $current = - $current;
65 $stamp = (int)$stamp - (int)$gmt +
(int)$current;
70 function getLongDateString($stamp) {
71 return date('D, F j, Y g:i a', $stamp);
74 function getDateString($stamp) {
77 $dateZ = date('Z', $now);
80 $midnight = $now - ($now %
86400) - $dateZ;
82 if ($midnight < $stamp) {
84 return date('g:i a', $stamp);
85 } else if ($midnight - (60 * 60 * 24 * 6) < $stamp) {
87 return date('D, g:i a', $stamp);
90 return date('M j, Y', $stamp);
94 function getTimeStamp($dateParts) {
95 /** $dateParts[0] == <day of week> Mon, Tue, Wed
96 ** $dateParts[1] == <day of month> 23
97 ** $dateParts[2] == <month> Jan, Feb, Mar
98 ** $dateParts[3] == <year> 1999
99 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
100 ** $dateParts[5] == <from GMT> +0100
101 ** $dateParts[6] == <zone> (EDT)
103 ** NOTE: In RFC 822, it states that <day of week> is optional.
104 ** In that case, dateParts[0] would be the <day of month>
105 ** and everything would be bumped up one.
108 // Simply check to see if the first element in the dateParts
109 // array is an integer or not.
110 // Since the day of week is optional, this check is needed.
112 // The old code used eregi('mon|tue|wed|thu|fri|sat|sun',
113 // $dateParts[0], $tmp) to find if the first element was the
114 // day of week or day of month. This is an expensive call
115 // (processing time) to have inside a loop. Doing it this way
116 // saves quite a bit of time for large mailboxes.
118 // It is also quicker to call explode only once rather than
119 // the 3 times it was getting called by calling the functions
120 // getHour, getMinute, and getSecond.
122 if (intval(trim($dateParts[0])) > 0) {
123 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
124 $dateParts[2] . ' ' . $dateParts[3];
125 return getGMTSeconds(strtotime($string), $dateParts[4]);
127 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
128 $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4];
129 if (isset($dateParts[5]))
130 return getGMTSeconds(strtotime($string), $dateParts[5]);
132 return getGMTSeconds(strtotime($string), '');
135 // I use this function for profiling. Should never be called in
136 // actual versions of squirrelmail released to public.
137 function getmicrotime() {
138 $mtime = microtime();
139 $mtime = explode(' ',$mtime);
140 $mtime = $mtime[1] +
$mtime[0];