1c894d22ecf1f5b5e60b2566af64175220dc489b
6 * Copyright (c) 1999-2003 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
15 * @package squirrelmail
18 /** Load up some useful constants */
19 require_once(SM_PATH
. 'functions/constants.php');
21 /** corrects a time stamp to be the local time */
22 function getGMTSeconds($stamp, $tzc) {
23 /* date couldn't be parsed */
27 /* timezone correction, expressed as `shhmm' */
75 if (substr($tzc, 0, 1) == '-') {
77 } else if (substr($tzc, 0, 1) != '+') {
80 $hh = substr($tzc,1,2);
81 $mm = substr($tzc,3,2);
82 $iTzc = ($hh * 60 +
$mm) * 60;
83 if ($neg) $iTzc = -1 * (int) $iTzc;
86 /** now find what the server is at **/
87 $current = date('Z', time());
88 /* stamp in local timezone */
95 Switch system has been intentionaly chosen for the
96 internationalization of month and day names. The reason
97 is to make sure that _("") strings will go into the
101 function getDayName( $day_number ) {
103 switch( $day_number ) {
114 $ret = _("Wednesday");
117 $ret = _("Thursday");
123 $ret = _("Saturday");
131 function getDayAbrv( $day_number ) {
133 switch( $day_number ) {
161 function getMonthName( $month_number ) {
162 switch( $month_number ) {
167 $ret = _("February");
188 $ret = _("September");
194 $ret = _("November");
197 $ret = _("December");
205 function getMonthAbrv( $month_number ) {
206 switch( $month_number ) {
220 $ret = _("May");
250 function date_intl( $date_format, $stamp ) {
251 $ret = str_replace( array('D','F','l','M'), array('$1','$2','$3','$4'), $date_format );
252 $ret = date('w#m#'. $ret, $stamp ); // to reduce the date calls we retrieve m and w in the same call
253 $aParts = explode('#',$ret); // extract day and month in order to replace later by intl day and month
254 $ret = str_replace(array('$1','$4','$2','$3',), array(getDayAbrv($aParts[0]),
255 getMonthAbrv($aParts[1]),
256 getMonthName($aParts[1]),
257 getDayName($aParts[0])),
262 function getLongDateString( $stamp ) {
270 if ( $hour_format == SMPREF_TIME_12HR
) {
271 $date_format = _("D, F j, Y g:i a");
273 $date_format = _("D, F j, Y G:i");
276 return( date_intl( $date_format, $stamp ) );
280 function getDateString( $stamp ) {
282 global $invert_time, $hour_format, $show_full_date;
284 if ( $stamp == -1 ) {
290 $dateZ = date('Z', $now );
294 $midnight = $now - ($now %
86400) - $dateZ;
295 $nextmid = $midnight +
86400;
297 if (($show_full_date == 1) ||
($nextmid < $stamp)) {
298 $date_format = _("M j, Y");
299 } else if ($midnight < $stamp) {
301 if ( $hour_format == SMPREF_TIME_12HR
) {
302 $date_format = _("g:i a");
304 $date_format = _("G:i");
306 } else if ($midnight - 518400 < $stamp) {
308 if ( $hour_format == SMPREF_TIME_12HR
) {
309 $date_format = _("D, g:i a");
311 $date_format = _("D, G:i");
314 /* before this week */
315 $date_format = _("M j, Y");
318 return( date_intl( $date_format, $stamp ) );
321 function getTimeStamp($dateParts) {
322 /** $dateParts[0] == <day of week> Mon, Tue, Wed
323 ** $dateParts[1] == <day of month> 23
324 ** $dateParts[2] == <month> Jan, Feb, Mar
325 ** $dateParts[3] == <year> 1999
326 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
327 ** $dateParts[5] == <from GMT> +0100
328 ** $dateParts[6] == <zone> (EDT)
330 ** NOTE: In RFC 822, it states that <day of week> is optional.
331 ** In that case, dateParts[0] would be the <day of month>
332 ** and everything would be bumped up one.
336 * Simply check to see if the first element in the dateParts
337 * array is an integer or not.
338 * Since the day of week is optional, this check is needed.
340 if (count($dateParts) <2) {
344 /* remove day of week */
345 if (!is_numeric(trim($dateParts[0]))) {
346 $dataParts = array_shift($dateParts);
348 /* calculate timestamp separated from the zone and obs-zone */
349 $stamp = strtotime(implode (' ', array_splice ($dateParts,0,4)));
350 if (!isset($dateParts[0])) {
351 $dateParts[0] = '+0000';
354 if (!preg_match('/^[+-]{1}[0-9]{4}$/',$dateParts[0])) {
355 /* zone in obs-zone format */
356 if (preg_match('/\((.+)\)/',$dateParts[0],$regs)) {
357 $obs_zone = $regs[1];
359 $obs_zone = $dateParts[0];
361 return getGMTSeconds($stamp, $obs_zone);
363 return getGMTSeconds($stamp, $dateParts[0]);
367 /* I use this function for profiling. Should never be called in
368 actual versions of squirrelmail released to public. */
370 function getmicrotime() {
371 $mtime = microtime();
372 $mtime = explode(' ',$mtime);
373 $mtime = $mtime[1] + $mtime[0];