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) {
23 /* date couldn't be parsed */
74 if (substr($gmt, 0, 1) == '-') {
76 $gmt = substr($gmt, 1, strlen($gmt));
77 } else if (substr($gmt, 0, 1) == '+') {
79 $gmt = substr($gmt, 1, strlen($gmt));
84 $difference = substr($gmt, 2, 2);
85 $gmt = substr($gmt, 0, 2);
86 $gmt = ($gmt +
($difference / 60)) * 3600;
93 /** now find what the server is at **/
94 $current = date('Z', time());
96 $current = - $current;
98 $stamp = (int)$stamp - (int)$gmt +
(int)$current;
104 Switch system has been intentionaly chosen for the
105 internationalization of month and day names. The reason
106 is to make sure that _("") strings will go into the
110 function getDayName( $day_number ) {
112 switch( $day_number ) {
123 $ret = _("Wednesday");
126 $ret = _("Thursday");
132 $ret = _("Saturday");
140 function getMonthName( $month_number ) {
141 switch( $month_number ) {
146 $ret = _("February");
167 $ret = _("September");
173 $ret = _("November");
176 $ret = _("December");
184 function date_intl( $date_format, $stamp ) {
186 $ret = str_replace( 'D', '$1', $date_format );
187 $ret = str_replace( 'F', '$2', $ret );
188 $ret = str_replace( 'l', '$4', $ret );
189 $ret = str_replace( 'M', '$5', $ret );
190 $ret = date( '$3'. $ret . '$3', $stamp ); // Workaround for a PHP 4.0.4 problem
191 $ret = str_replace( '$1', substr( getDayName( date( 'w', $stamp ) ), 0, 3 ), $ret );
192 $ret = str_replace( '$5', substr( getMonthName( date( 'm', $stamp ) ), 0, 3 ), $ret );
193 $ret = str_replace( '$2', getMonthName( date( 'm', $stamp ) ), $ret );
194 $ret = str_replace( '$4', getDayName( date( 'w', $stamp ) ), $ret );
195 $ret = str_replace( '$3', '', $ret );
200 function getLongDateString( $stamp ) {
208 if ( $hour_format == SMPREF_TIME_12HR
) {
209 $date_format = _("D, F j, Y g:i a");
211 $date_format = _("D, F j, Y G:i");
214 return( date_intl( $date_format, $stamp ) );
218 function getDateString( $stamp ) {
220 global $invert_time, $hour_format;
222 if ( $stamp == -1 ) {
228 $dateZ = date('Z', $now );
232 $midnight = $now - ($now %
86400) - $dateZ;
234 if ($midnight < $stamp) {
236 if ( $hour_format == SMPREF_TIME_12HR
) {
237 $date_format = _("g:i a");
239 $date_format = _("G:i");
241 } else if ($midnight - 518400 < $stamp) {
243 if ( $hour_format == SMPREF_TIME_12HR
) {
244 $date_format = _("D, g:i a");
246 $date_format = _("D, G:i");
249 /* before this week */
250 $date_format = _("M j, Y");
253 return( date_intl( $date_format, $stamp ) );
256 function getTimeStamp($dateParts) {
257 /** $dateParts[0] == <day of week> Mon, Tue, Wed
258 ** $dateParts[1] == <day of month> 23
259 ** $dateParts[2] == <month> Jan, Feb, Mar
260 ** $dateParts[3] == <year> 1999
261 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
262 ** $dateParts[5] == <from GMT> +0100
263 ** $dateParts[6] == <zone> (EDT)
265 ** NOTE: In RFC 822, it states that <day of week> is optional.
266 ** In that case, dateParts[0] would be the <day of month>
267 ** and everything would be bumped up one.
271 * Simply check to see if the first element in the dateParts
272 * array is an integer or not.
273 * Since the day of week is optional, this check is needed.
276 $string = implode (' ', $dateParts);
278 if (! isset($dateParts[4])) {
281 if (! isset($dateParts[5])) {
285 if (intval(trim($dateParts[0])) > 0) {
286 return getGMTSeconds(strtotime($string), $dateParts[4]);
289 return getGMTSeconds(strtotime($string), $dateParts[5]);
292 /* I use this function for profiling. Should never be called in
293 actual versions of squirrelmail released to public. */
295 function getmicrotime() {
296 $mtime = microtime();
297 $mtime = explode(' ',$mtime);
298 $mtime = $mtime[1] + $mtime[0];