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 // corrects a time stamp to be the local time
14 function getGMTSeconds($stamp, $gmt) {
16 if (($gmt == 'Pacific') ||
($gmt == 'PST'))
18 else if (($gmt == 'EDT'))
20 else if (($gmt == 'Eastern') ||
($gmt == 'EST') ||
($gmt == 'CDT'))
22 else if (($gmt == 'Central') ||
($gmt == 'CST') ||
($gmt == 'MDT'))
24 else if (($gmt == 'Mountain') ||
($gmt == 'MST') ||
($gmt == 'PDT'))
26 else if ($gmt == 'BST')
28 else if ($gmt == 'EET')
30 else if ($gmt == 'GMT')
32 else if ($gmt == 'HKT')
34 else if ($gmt == 'IST')
36 else if ($gmt == 'JST')
38 else if ($gmt == 'KST')
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;
71 Switch system has been intentionaly choosed for the
72 internationalization of month and day names. The reason
73 is to make sure that _("") strings will go into the
77 function getDayName( $day_number ) {
79 switch( $day_number ) {
90 $ret = _("Wednesday");
107 function getMonthName( $month_number ) {
108 switch( $month_number ) {
113 $ret = _("February");
134 $ret = _("September");
140 $ret = _("November");
143 $ret = _("December");
151 function date_intl( $date_format, $stamp ) {
153 $ret = str_replace( 'D', '$1', $date_format );
154 $ret = str_replace( 'F', '$2', $ret );
155 $ret = date( '$3'. $ret . '$3', $stamp ); // Workaround for a PHP 4.0.4 problem
156 $ret = str_replace( '$1', substr( getDayName( date( 'w', $stamp ) ), 0, 3 ), $ret );
157 $ret = str_replace( '$2', getMonthName( date( 'm', $stamp ) ), $ret );
158 $ret = str_replace( '$3', '', $ret );
163 function getLongDateString( $stamp ) {
165 return( date_intl( _("D, F j, Y g:i a"), $stamp ) );
169 function getDateString( $stamp ) {
175 $dateZ = date('Z', $now );
178 $midnight = $now - ($now %
86400) - $dateZ;
180 if ($midnight < $stamp) {
182 $date_format = _("g:i a");
183 } else if ($midnight - 518400 < $stamp) {
185 $date_format = _("D, g:i a");
188 $date_format = _("M j, Y");
191 return( date_intl( $date_format, $stamp ) );
192 // return( date( $date_i, $stamp ) );
195 function getTimeStamp($dateParts) {
196 /** $dateParts[0] == <day of week> Mon, Tue, Wed
197 ** $dateParts[1] == <day of month> 23
198 ** $dateParts[2] == <month> Jan, Feb, Mar
199 ** $dateParts[3] == <year> 1999
200 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
201 ** $dateParts[5] == <from GMT> +0100
202 ** $dateParts[6] == <zone> (EDT)
204 ** NOTE: In RFC 822, it states that <day of week> is optional.
205 ** In that case, dateParts[0] would be the <day of month>
206 ** and everything would be bumped up one.
209 // Simply check to see if the first element in the dateParts
210 // array is an integer or not.
211 // Since the day of week is optional, this check is needed.
213 // The old code used eregi('mon|tue|wed|thu|fri|sat|sun',
214 // $dateParts[0], $tmp) to find if the first element was the
215 // day of week or day of month. This is an expensive call
216 // (processing time) to have inside a loop. Doing it this way
217 // saves quite a bit of time for large mailboxes.
219 // It is also quicker to call explode only once rather than
220 // the 3 times it was getting called by calling the functions
221 // getHour, getMinute, and getSecond.
223 if (! isset($dateParts[1])) $dateParts[1] = '';
224 if (! isset($dateParts[2])) $dateParts[2] = '';
225 if (! isset($dateParts[3])) $dateParts[3] = '';
226 if (! isset($dateParts[4])) $dateParts[4] = '';
227 if (! isset($dateParts[5])) $dateParts[5] = '';
228 if (intval(trim($dateParts[0])) > 0) {
229 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
230 $dateParts[2] . ' ' . $dateParts[3];
231 return getGMTSeconds(strtotime($string), $dateParts[4]);
233 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
234 $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4];
235 if (isset($dateParts[5]))
236 return getGMTSeconds(strtotime($string), $dateParts[5]);
238 return getGMTSeconds(strtotime($string), '');
241 // I use this function for profiling. Should never be called in
242 // actual versions of squirrelmail released to public.
244 function getmicrotime() {
245 $mtime = microtime();
246 $mtime = explode(' ',$mtime);
247 $mtime = $mtime[1] + $mtime[0];