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;
75 Switch system has been intentionaly choosed for the
76 internationalization of month and day names. The reason
77 is to make sure that _("") strings will go into the
81 function getDayName( $day_number ) {
83 switch( $day_number ) {
94 $ret = _("Wednesday");
103 $ret = _("Saturday");
111 function getMonthName( $week_number ) {
112 switch( $week_number ) {
117 $ret = _("February");
138 $ret = _("September");
144 $ret = _("November");
147 $ret = _("December");
155 function date_intl( $date_format ) {
157 $date_format = str_replace( 'D', '[D]', $date_format );
158 $date_format = str_replace( 'F', '[F]', $date_format );
159 $date_format = str_replace( '[D]',
160 ereg_replace( "([a-zA-Z])", "\\\\1", substr( getDayName( date( 'w', $stamp ) ), 0, 3 ) ),
162 $date_format = str_replace( '[F]',
163 ereg_replace( "([a-zA-Z])", "\\\\1", getMonthName( date( 'n', $stamp ) ) ),
165 return( $date_format . ' ' );
168 function getLongDateString($stamp) {
170 $date_format = date_intl( _("D, F j, Y g:i a") );
171 return date( $date_format, $stamp );
175 function getDateString($stamp) {
180 $dateZ = date('Z', $now);
183 $midnight = $now - ($now %
86400) - $dateZ;
185 if ($midnight < $stamp) {
187 $date_format = _("g:i a");
188 } else if ($midnight - 518400 < $stamp) {
190 $date_format = _("D, g:i a");
193 $date_format = _("M j, Y");
196 return( date( date_intl( $date_format ), $stamp ) );
199 function getTimeStamp($dateParts) {
200 /** $dateParts[0] == <day of week> Mon, Tue, Wed
201 ** $dateParts[1] == <day of month> 23
202 ** $dateParts[2] == <month> Jan, Feb, Mar
203 ** $dateParts[3] == <year> 1999
204 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
205 ** $dateParts[5] == <from GMT> +0100
206 ** $dateParts[6] == <zone> (EDT)
208 ** NOTE: In RFC 822, it states that <day of week> is optional.
209 ** In that case, dateParts[0] would be the <day of month>
210 ** and everything would be bumped up one.
213 // Simply check to see if the first element in the dateParts
214 // array is an integer or not.
215 // Since the day of week is optional, this check is needed.
217 // The old code used eregi('mon|tue|wed|thu|fri|sat|sun',
218 // $dateParts[0], $tmp) to find if the first element was the
219 // day of week or day of month. This is an expensive call
220 // (processing time) to have inside a loop. Doing it this way
221 // saves quite a bit of time for large mailboxes.
223 // It is also quicker to call explode only once rather than
224 // the 3 times it was getting called by calling the functions
225 // getHour, getMinute, and getSecond.
227 if (! isset($dateParts[1])) $dateParts[1] = '';
228 if (! isset($dateParts[2])) $dateParts[2] = '';
229 if (! isset($dateParts[3])) $dateParts[3] = '';
230 if (! isset($dateParts[4])) $dateParts[4] = '';
231 if (! isset($dateParts[5])) $dateParts[5] = '';
232 if (intval(trim($dateParts[0])) > 0) {
233 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
234 $dateParts[2] . ' ' . $dateParts[3];
235 return getGMTSeconds(strtotime($string), $dateParts[4]);
237 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
238 $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4];
239 if (isset($dateParts[5]))
240 return getGMTSeconds(strtotime($string), $dateParts[5]);
242 return getGMTSeconds(strtotime($string), '');
245 // I use this function for profiling. Should never be called in
246 // actual versions of squirrelmail released to public.
247 function getmicrotime() {
248 $mtime = microtime();
249 $mtime = explode(' ',$mtime);
250 $mtime = $mtime[1] +
$mtime[0];