6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Takes a date and parses it into a usable format. The form that a
10 * date SHOULD arrive in is:
11 * <Tue,> 29 Jun 1999 09:52:11 -0500 (EDT)
12 * (as specified in RFC 822) -- 'Tue' is optional
17 require_once( '../functions/constants.php' );
19 // corrects a time stamp to be the local time
20 function getGMTSeconds($stamp, $gmt) {
22 if (($gmt == 'Pacific') ||
($gmt == 'PST')) {
24 } else if (($gmt == 'EDT')) {
26 } else if (($gmt == 'Eastern') ||
($gmt == 'EST') ||
($gmt == 'CDT')) {
28 } else if (($gmt == 'Central') ||
($gmt == 'CST') ||
($gmt == 'MDT')) {
30 } else if (($gmt == 'Mountain') ||
($gmt == 'MST') ||
($gmt == 'PDT')) {
32 } else if ($gmt == 'BST') {
34 } else if ($gmt == 'EET') {
36 } else if ($gmt == 'GMT') {
38 } else if ($gmt == 'HKT') {
40 } else if ($gmt == 'IST') {
42 } else if ($gmt == 'JST') {
44 } else if ($gmt == 'KST') {
46 } else if ($gmt == 'MET') {
48 } else if ($gmt == 'MET DST' ||
$gmt == 'METDST') {
52 if (substr($gmt, 0, 1) == '-') {
54 $gmt = substr($gmt, 1, strlen($gmt));
55 } else if (substr($gmt, 0, 1) == '+') {
57 $gmt = substr($gmt, 1, strlen($gmt));
62 $gmt = substr($gmt, 0, 2);
70 /** now find what the server is at **/
71 $current = date('Z', time());
73 $current = - $current;
75 $stamp = (int)$stamp - (int)$gmt +
(int)$current;
81 Switch system has been intentionaly choosed for the
82 internationalization of month and day names. The reason
83 is to make sure that _("") strings will go into the
87 function getDayName( $day_number ) {
89 switch( $day_number ) {
100 $ret = _("Wednesday");
103 $ret = _("Thursday");
109 $ret = _("Saturday");
117 function getMonthName( $month_number ) {
118 switch( $month_number ) {
123 $ret = _("February");
144 $ret = _("September");
150 $ret = _("November");
153 $ret = _("December");
161 function date_intl( $date_format, $stamp ) {
163 $ret = str_replace( 'D', '$1', $date_format );
164 $ret = str_replace( 'F', '$2', $ret );
165 $ret = date( '$3'. $ret . '$3', $stamp ); // Workaround for a PHP 4.0.4 problem
166 $ret = str_replace( '$1', substr( getDayName( date( 'w', $stamp ) ), 0, 3 ), $ret );
167 $ret = str_replace( '$2', getMonthName( date( 'm', $stamp ) ), $ret );
168 $ret = str_replace( '$3', '', $ret );
173 function getLongDateString( $stamp ) {
177 if ( $hour_format == SMPREF_TIME_12HR
) {
178 $date_format = _("D, F j, Y g:i a");
180 $date_format = _("D, F j, Y G:i");
183 return( date_intl( $date_format, $stamp ) );
187 function getDateString( $stamp ) {
189 global $invert_time, $hour_format;
193 $dateZ = date('Z', $now );
197 $midnight = $now - ($now %
86400) - $dateZ;
199 if ($midnight < $stamp) {
201 if ( $hour_format == SMPREF_TIME_12HR
) {
202 $date_format = _("g:i a");
204 $date_format = _("G:i");
206 } else if ($midnight - 518400 < $stamp) {
208 if ( $hour_format == SMPREF_TIME_12HR
) {
209 $date_format = _("D, g:i a");
211 $date_format = _("D, G:i");
214 /* before this week */
215 $date_format = _("M j, Y");
218 return( date_intl( $date_format, $stamp ) );
221 function getTimeStamp($dateParts) {
222 /** $dateParts[0] == <day of week> Mon, Tue, Wed
223 ** $dateParts[1] == <day of month> 23
224 ** $dateParts[2] == <month> Jan, Feb, Mar
225 ** $dateParts[3] == <year> 1999
226 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
227 ** $dateParts[5] == <from GMT> +0100
228 ** $dateParts[6] == <zone> (EDT)
230 ** NOTE: In RFC 822, it states that <day of week> is optional.
231 ** In that case, dateParts[0] would be the <day of month>
232 ** and everything would be bumped up one.
236 * Simply check to see if the first element in the dateParts
237 * array is an integer or not.
238 * Since the day of week is optional, this check is needed.
240 * The old code used eregi('mon|tue|wed|thu|fri|sat|sun',
241 * $dateParts[0], $tmp) to find if the first element was the
242 * day of week or day of month. This is an expensive call
243 * (processing time) to have inside a loop. Doing it this way
244 * saves quite a bit of time for large mailboxes.
246 * It is also quicker to call explode only once rather than
247 * the 3 times it was getting called by calling the functions
248 * getHour, getMinute, and getSecond.
251 if (! isset($dateParts[1])) {
254 if (! isset($dateParts[2])) {
257 if (! isset($dateParts[3])) {
260 if (! isset($dateParts[4])) {
263 if (! isset($dateParts[5])) {
266 if (intval(trim($dateParts[0])) > 0) {
267 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
268 $dateParts[2] . ' ' . $dateParts[3];
269 return getGMTSeconds(strtotime($string), $dateParts[4]);
271 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
272 $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4];
273 if (isset($dateParts[5])) {
274 return getGMTSeconds(strtotime($string), $dateParts[5]);
276 return getGMTSeconds(strtotime($string), '');
280 /* I use this function for profiling. Should never be called in
281 actual versions of squirrelmail released to public. */
283 function getmicrotime() {
284 $mtime = microtime();
285 $mtime = explode(' ',$mtime);
286 $mtime = $mtime[1] + $mtime[0];