X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fdate.php;h=f38deda1bd2006eb0e769ec6bffbca62eec7949c;hb=cdf82d4a03ace568f23522ca11a9641216696c8a;hp=ef3f0fadfd008f1baf43742afed6121cd50cad51;hpb=15e6162eacc97158393bc75aed3afeb7b19c24a6;p=squirrelmail.git diff --git a/functions/date.php b/functions/date.php index ef3f0fad..f38deda1 100644 --- a/functions/date.php +++ b/functions/date.php @@ -14,39 +14,60 @@ * $Id$ */ -require_once( '../functions/constants.php' ); +require_once(SM_PATH . 'functions/constants.php'); -// corrects a time stamp to be the local time +/* corrects a time stamp to be the local time */ function getGMTSeconds($stamp, $gmt) { global $invert_time; - if (($gmt == 'Pacific') || ($gmt == 'PST')) { - $gmt = '-0800'; - } else if (($gmt == 'EDT')) { - $gmt = '-0400'; - } else if (($gmt == 'Eastern') || ($gmt == 'EST') || ($gmt == 'CDT')) { - $gmt = '-0500'; - } else if (($gmt == 'Central') || ($gmt == 'CST') || ($gmt == 'MDT')) { - $gmt = '-0600'; - } else if (($gmt == 'Mountain') || ($gmt == 'MST') || ($gmt == 'PDT')) { - $gmt = '-0700'; - } else if ($gmt == 'BST') { - $gmt = '+0100'; - } else if ($gmt == 'EET') { - $gmt = '+0200'; - } else if ($gmt == 'GMT') { - $gmt = '+0000'; - } else if ($gmt == 'HKT') { - $gmt = '+0800'; - } else if ($gmt == 'IST') { - $gmt = '+0200'; - } else if ($gmt == 'JST') { - $gmt = '+0900'; - } else if ($gmt == 'KST') { - $gmt = "+0900"; - } else if ($gmt == 'MET') { - $gmt = '+0100'; - } else if ($gmt == 'MET DST' || $gmt == 'METDST') { - $gmt = '+0200'; + + /* date couldn't be parsed */ + if ($stamp == -1) { + return -1; + } + + switch($gmt) + { + case 'Pacific': + case 'PST': + $gmt = '-0800'; + break; + case 'Mountain': + case 'MST': + case 'PDT': + $gmt = '-0700'; + break; + case 'Central': + case 'CST': + case 'MDT': + $gmt = '-0600'; + break; + case 'Eastern': + case 'EST': + case 'CDT': + $gmt = '-0500'; + break; + case 'EDT': + $gmt = '-0400'; + break; + case 'GMT': + $gmt = '+0000'; + break; + case 'BST': + case 'MET': + $gmt = '+0100'; + case 'EET': + case 'IST': + case 'MET DST': + case 'METDST': + $gmt = '+0200'; + break; + case 'HKT': + $gmt = '+0800'; + break; + case 'JST': + case 'KST': + $gmt = '+0900'; + break; } if (substr($gmt, 0, 1) == '-') { @@ -58,10 +79,11 @@ function getGMTSeconds($stamp, $gmt) { } else { $neg = false; } - + + $difference = substr($gmt, 2, 2); $gmt = substr($gmt, 0, 2); - $gmt = $gmt * 3600; - if ($neg == true) { + $gmt = ($gmt + ($difference / 60)) * 3600; + if ($neg) { $gmt = "-$gmt"; } else { $gmt = "+$gmt"; @@ -78,7 +100,7 @@ function getGMTSeconds($stamp, $gmt) { } /** - Switch system has been intentionaly choosed for the + Switch system has been intentionaly chosen for the internationalization of month and day names. The reason is to make sure that _("") strings will go into the main po. @@ -162,9 +184,13 @@ function date_intl( $date_format, $stamp ) { $ret = str_replace( 'D', '$1', $date_format ); $ret = str_replace( 'F', '$2', $ret ); + $ret = str_replace( 'l', '$4', $ret ); + $ret = str_replace( 'M', '$5', $ret ); $ret = date( '$3'. $ret . '$3', $stamp ); // Workaround for a PHP 4.0.4 problem $ret = str_replace( '$1', substr( getDayName( date( 'w', $stamp ) ), 0, 3 ), $ret ); + $ret = str_replace( '$5', substr( getMonthName( date( 'm', $stamp ) ), 0, 3 ), $ret ); $ret = str_replace( '$2', getMonthName( date( 'm', $stamp ) ), $ret ); + $ret = str_replace( '$4', getDayName( date( 'w', $stamp ) ), $ret ); $ret = str_replace( '$3', '', $ret ); return( $ret ); @@ -174,6 +200,10 @@ function getLongDateString( $stamp ) { global $hour_format; + if ($stamp == -1) { + return ''; + } + if ( $hour_format == SMPREF_TIME_12HR ) { $date_format = _("D, F j, Y g:i a"); } else { @@ -187,6 +217,10 @@ function getLongDateString( $stamp ) { function getDateString( $stamp ) { global $invert_time, $hour_format; + + if ( $stamp == -1 ) { + return ''; + } $now = time(); @@ -235,46 +269,23 @@ function getTimeStamp($dateParts) { /* * Simply check to see if the first element in the dateParts * array is an integer or not. - * Since the day of week is optional, this check is needed. - * - * The old code used eregi('mon|tue|wed|thu|fri|sat|sun', - * $dateParts[0], $tmp) to find if the first element was the - * day of week or day of month. This is an expensive call - * (processing time) to have inside a loop. Doing it this way - * saves quite a bit of time for large mailboxes. - * - * It is also quicker to call explode only once rather than - * the 3 times it was getting called by calling the functions - * getHour, getMinute, and getSecond. + * Since the day of week is optional, this check is needed. */ - if (! isset($dateParts[1])) { - $dateParts[1] = ''; - } - if (! isset($dateParts[2])) { - $dateParts[2] = ''; - } - if (! isset($dateParts[3])) { - $dateParts[3] = ''; - } + $string = implode (' ', $dateParts); + if (! isset($dateParts[4])) { $dateParts[4] = ''; } if (! isset($dateParts[5])) { $dateParts[5] = ''; } + if (intval(trim($dateParts[0])) > 0) { - $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' . - $dateParts[2] . ' ' . $dateParts[3]; return getGMTSeconds(strtotime($string), $dateParts[4]); } - $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' . - $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4]; - if (isset($dateParts[5])) { - return getGMTSeconds(strtotime($string), $dateParts[5]); - } else { - return getGMTSeconds(strtotime($string), ''); - } + + return getGMTSeconds(strtotime($string), $dateParts[5]); } /* I use this function for profiling. Should never be called in