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