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 $difference = substr($gmt, 2, 2);
63 $gmt = substr($gmt, 0, 2);
64 $gmt = ($gmt +
($difference / 60)) * 3600;
71 /** now find what the server is at **/
72 $current = date('Z', time());
74 $current = - $current;
76 $stamp = (int)$stamp - (int)$gmt +
(int)$current;
82 Switch system has been intentionaly choosed for the
83 internationalization of month and day names. The reason
84 is to make sure that _("") strings will go into the
88 function getDayName( $day_number ) {
90 switch( $day_number ) {
101 $ret = _("Wednesday");
104 $ret = _("Thursday");
110 $ret = _("Saturday");
118 function getMonthName( $month_number ) {
119 switch( $month_number ) {
124 $ret = _("February");
145 $ret = _("September");
151 $ret = _("November");
154 $ret = _("December");
162 function date_intl( $date_format, $stamp ) {
164 $ret = str_replace( 'D', '$1', $date_format );
165 $ret = str_replace( 'F', '$2', $ret );
166 $ret = str_replace( 'l', '$4', $ret );
167 $ret = str_replace( 'M', '$5', $ret );
168 $ret = date( '$3'. $ret . '$3', $stamp ); // Workaround for a PHP 4.0.4 problem
169 $ret = str_replace( '$1', substr( getDayName( date( 'w', $stamp ) ), 0, 3 ), $ret );
170 $ret = str_replace( '$5', substr( getMonthName( date( 'm', $stamp ) ), 0, 3 ), $ret );
171 $ret = str_replace( '$2', getMonthName( date( 'm', $stamp ) ), $ret );
172 $ret = str_replace( '$4', getDayName( date( 'w', $stamp ) ), $ret );
173 $ret = str_replace( '$3', '', $ret );
178 function getLongDateString( $stamp ) {
182 if ( $hour_format == SMPREF_TIME_12HR
) {
183 $date_format = _("D, F j, Y g:i a");
185 $date_format = _("D, F j, Y G:i");
188 return( date_intl( $date_format, $stamp ) );
192 function getDateString( $stamp ) {
194 global $invert_time, $hour_format;
198 $dateZ = date('Z', $now );
202 $midnight = $now - ($now %
86400) - $dateZ;
204 if ($midnight < $stamp) {
206 if ( $hour_format == SMPREF_TIME_12HR
) {
207 $date_format = _("g:i a");
209 $date_format = _("G:i");
211 } else if ($midnight - 518400 < $stamp) {
213 if ( $hour_format == SMPREF_TIME_12HR
) {
214 $date_format = _("D, g:i a");
216 $date_format = _("D, G:i");
219 /* before this week */
220 $date_format = _("M j, Y");
223 return( date_intl( $date_format, $stamp ) );
226 function getTimeStamp($dateParts) {
227 /** $dateParts[0] == <day of week> Mon, Tue, Wed
228 ** $dateParts[1] == <day of month> 23
229 ** $dateParts[2] == <month> Jan, Feb, Mar
230 ** $dateParts[3] == <year> 1999
231 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
232 ** $dateParts[5] == <from GMT> +0100
233 ** $dateParts[6] == <zone> (EDT)
235 ** NOTE: In RFC 822, it states that <day of week> is optional.
236 ** In that case, dateParts[0] would be the <day of month>
237 ** and everything would be bumped up one.
241 * Simply check to see if the first element in the dateParts
242 * array is an integer or not.
243 * Since the day of week is optional, this check is needed.
245 * The old code used eregi('mon|tue|wed|thu|fri|sat|sun',
246 * $dateParts[0], $tmp) to find if the first element was the
247 * day of week or day of month. This is an expensive call
248 * (processing time) to have inside a loop. Doing it this way
249 * saves quite a bit of time for large mailboxes.
251 * It is also quicker to call explode only once rather than
252 * the 3 times it was getting called by calling the functions
253 * getHour, getMinute, and getSecond.
256 if (! isset($dateParts[1])) {
259 if (! isset($dateParts[2])) {
262 if (! isset($dateParts[3])) {
265 if (! isset($dateParts[4])) {
268 if (! isset($dateParts[5])) {
271 if (intval(trim($dateParts[0])) > 0) {
272 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
273 $dateParts[2] . ' ' . $dateParts[3];
274 return getGMTSeconds(strtotime($string), $dateParts[4]);
276 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
277 $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4];
278 if (isset($dateParts[5])) {
279 return getGMTSeconds(strtotime($string), $dateParts[5]);
281 return getGMTSeconds(strtotime($string), '');
285 /* I use this function for profiling. Should never be called in
286 actual versions of squirrelmail released to public. */
288 function getmicrotime() {
289 $mtime = microtime();
290 $mtime = explode(' ',$mtime);
291 $mtime = $mtime[1] + $mtime[0];