Fixing code formatting

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3114 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2006-06-15 15:29:06 +00:00
parent 3d4d5e4388
commit 79ba4fa94d

View file

@ -34,7 +34,7 @@
* @package cake
* @subpackage cake.cake.libs.view.helpers
*/
class TimeHelper extends Helper{
class TimeHelper extends Helper {
/**
* Returns given string trimmed to given length, adding an ending (default: "..") if necessary.
*
@ -75,7 +75,7 @@ class TimeHelper extends Helper{
$date = time();
}
$ret=date("D, M jS Y, H:i", $date);
$ret = date("D, M jS Y, H:i", $date);
return $this->output($ret, $return);
}
@ -92,9 +92,9 @@ class TimeHelper extends Helper{
* @return string Described, relative date string
*/
function niceShort($date_string = null, $return = false) {
$date=$date_string ? $this->fromString($date_string) : time();
$date = $date_string ? $this->fromString($date_string) : time();
$y=$this->isThisYear($date) ? '' : ' Y';
$y = $this->isThisYear($date) ? '' : ' Y';
if ($this->isToday($date)) {
$ret = "Today, " . date("H:i", $date);
@ -115,9 +115,8 @@ class TimeHelper extends Helper{
* @return boolean True if datetime string is today
*/
function isToday($date_string, $return = false) {
$date=$this->fromString($date_string);
$ret =date('Y-m-d', $date) == date('Y-m-d', time());
$date = $this->fromString($date_string);
$ret = date('Y-m-d', $date) == date('Y-m-d', time());
return $this->output($ret, $return);
}
@ -131,13 +130,12 @@ class TimeHelper extends Helper{
* @return string Partial SQL string.
*/
function daysAsSql($begin, $end, $field_name, $return = false) {
$begin=$this->fromString($begin);
$end =$this->fromString($end);
$begin=date('Y-m-d', $begin) . ' 00:00:00';
$end =date('Y-m-d', $end) . ' 23:59:59';
$begin = $this->fromString($begin);
$end = $this->fromString($end);
$begin = date('Y-m-d', $begin) . ' 00:00:00';
$end = date('Y-m-d', $end) . ' 23:59:59';
$ret ="($field_name >= '$begin') AND ($field_name <= '$end')";
return $this->output($ret, $return);
}
@ -151,9 +149,8 @@ class TimeHelper extends Helper{
* @return string Partial SQL string.
*/
function dayAsSql($date_string, $field_name, $return = false) {
$date=$this->fromString($date_string);
$ret =$this->daysAsSql($date_string, $date_string, $field_name);
$date = $this->fromString($date_string);
$ret = $this->daysAsSql($date_string, $date_string, $field_name);
return $this->output($ret, $return);
}
@ -165,8 +162,8 @@ class TimeHelper extends Helper{
* @return boolean True if datetime string is within current year
*/
function isThisYear($date_string, $return = false) {
$date=$this->fromString($date_string);
$ret =date('Y', $date) == date('Y', time());
$date = $this->fromString($date_string);
$ret = date('Y', $date) == date('Y', time());
return $this->output($ret, $return);
}
@ -179,9 +176,8 @@ class TimeHelper extends Helper{
* @return boolean True if datetime string was yesterday
*/
function wasYesterday($date_string, $return = false) {
$date=$this->fromString($date_string);
$ret =date('Y-m-d', $date) == date('Y-m-d', strtotime('yesterday'));
$date = $this->fromString($date_string);
$ret = date('Y-m-d', $date) == date('Y-m-d', strtotime('yesterday'));
return $this->output($ret, $return);
}
@ -193,12 +189,10 @@ class TimeHelper extends Helper{
* @return boolean True if datetime string was yesterday
*/
function isTomorrow($date_string, $return = false) {
$date=$this->fromString($date_string);
$ret =date('Y-m-d', $date) == date('Y-m-d', strtotime('tomorrow'));
$date = $this->fromString($date_string);
$ret = date('Y-m-d', $date) == date('Y-m-d', strtotime('tomorrow'));
return $this->output($ret, $return);
}
/**
* Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
*
@ -207,11 +201,9 @@ class TimeHelper extends Helper{
* @return int Unix timestamp
*/
function toUnix($date_string, $return = false) {
$ret=strtotime($date_string);
$ret = strtotime($date_string);
return $this->output($ret, $return);
}
/**
* Returns a date formatted for Atom RSS feeds.
*
@ -220,12 +212,10 @@ class TimeHelper extends Helper{
* @return string Formatted date string
*/
function toAtom($date_string, $return = false) {
$date=$this->fromString($date_string);
$ret =date('Y-m-d\TH:i:s\Z', $date);
$date = $this->fromString($date_string);
$ret = date('Y-m-d\TH:i:s\Z', $date);
return $this->output($ret, $return);
}
/**
* Formats date for RSS feeds
*
@ -234,12 +224,10 @@ class TimeHelper extends Helper{
* @return string Formatted date string
*/
function toRSS($date_string, $return = false) {
$date=TimeHelper::fromString($date_string);
$ret =date("r", $date);
$date = TimeHelper::fromString($date_string);
$ret = date("r", $date);
return $this->output($ret, $return);
}
/**
* Returns either a relative date or a formatted date depending
* on the difference between the current time and given datetime.
@ -271,62 +259,54 @@ class TimeHelper extends Helper{
$diff = time() - $in_seconds;
}
$months=floor($diff / 2419200);
$months = floor($diff / 2419200);
$diff -= $months * 2419200;
$weeks=floor($diff / 604800);
$weeks = floor($diff / 604800);
$diff -= $weeks * 604800;
$days=floor($diff / 86400);
$days = floor($diff / 86400);
$diff -= $days * 86400;
$hours=floor($diff / 3600);
$hours = floor($diff / 3600);
$diff -= $hours * 3600;
$minutes=floor($diff / 60);
$minutes = floor($diff / 60);
$diff -= $minutes * 60;
$seconds=$diff;
$seconds = $diff;
if ($months > 0) {
// over a month old, just show date (mm/dd/yyyy format)
$relative_date='on ' . date($format, $in_seconds);
$old=true;
$relative_date = 'on ' . date($format, $in_seconds);
$old = true;
} else {
$relative_date='';
$old =false;
$relative_date = '';
$old = false;
if ($weeks > 0) {
// weeks and days
$relative_date .= ($relative_date ? ', ' : '') . $weeks . ' week' . ($weeks > 1 ? 's' : '');
$relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '')
: '';
$relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '') : '';
} elseif($days > 0) {
// days and hours
$relative_date .= ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '');
$relative_date .= $hours > 0
? ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : '') : '';
$relative_date .= $hours > 0 ? ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : '') : '';
} elseif($hours > 0) {
// hours and minutes
$relative_date .= ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : '');
$relative_date .= $minutes > 0
? ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : '') : '';
$relative_date .= $minutes > 0 ? ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : '') : '';
} elseif($minutes > 0) {
// minutes only
$relative_date .= ($relative_date ? ', ' : '') . $minutes . ' minute'
. ($minutes > 1 ? 's' : '');
$relative_date .= ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : '');
} else {
// seconds only
$relative_date .= ($relative_date ? ', ' : '') . $seconds . ' second'
. ($seconds != 1 ? 's' : '');
$relative_date .= ($relative_date ? ', ' : '') . $seconds . ' second' . ($seconds != 1 ? 's' : '');
}
}
$ret=$relative_date;
$ret = $relative_date;
// show relative date and add proper verbiage
if (!$backwards && !$old) {
$ret .= ' ago';
}
return $this->output($ret, $return);
}
/**
* Alias for timeAgoInWords
* @param string $date_string Datetime string or Unix timestamp
@ -336,7 +316,7 @@ class TimeHelper extends Helper{
* @see timeAgoInWords
*/
function relativeTime($datetime_string, $format = 'j/n/y', $return = false) {
$date=strtotime($datetime_string);
$date = strtotime($datetime_string);
if (strtotime("now") > $date) {
$ret = $this->timeAgoInWords($datetime_string, $format, false);
@ -346,7 +326,6 @@ class TimeHelper extends Helper{
return $this->output($ret, $return);
}
/**
* Returns true if specified datetime was within the interval specified, else false.
*
@ -356,68 +335,60 @@ class TimeHelper extends Helper{
* @return boolean
*/
function wasWithinLast($timeInterval, $date_string, $return = false) {
$date =$this->fromString($date_string);
$result =preg_split('/\\s/', $timeInterval);
$numInterval =$result[0];
$textInterval=$result[1];
$currentTime =floor(time());
$seconds =($currentTime - floor($date));
$date = $this->fromString($date_string);
$result = preg_split('/\\s/', $timeInterval);
$numInterval = $result[0];
$textInterval = $result[1];
$currentTime = floor(time());
$seconds = ($currentTime - floor($date));
switch($textInterval)
{
switch($textInterval) {
case "seconds":
case "second":
$timePeriod=$seconds;
$ret =$return;
$timePeriod = $seconds;
$ret = $return;
break;
case "minutes":
case "minute":
$minutes=floor($seconds / 60);
$timePeriod=$minutes;
$minutes = floor($seconds / 60);
$timePeriod = $minutes;
break;
case "hours":
case "hour":
$hours=floor($seconds / 3600);
$timePeriod=$hours;
$hours = floor($seconds / 3600);
$timePeriod = $hours;
break;
case "days":
case "day":
$days=floor($seconds / 86400);
$timePeriod=$days;
$days = floor($seconds / 86400);
$timePeriod = $days;
break;
case "weeks":
case "week":
$weeks=floor($seconds / 604800);
$weeks = floor($seconds / 604800);
$timePeriod=$weeks;
$timePeriod = $weeks;
break;
case "months":
case "month":
$months=floor($seconds / 2629743.83);
$timePeriod=$months;
$months = floor($seconds / 2629743.83);
$timePeriod = $months;
break;
case "years":
case "year":
$years=floor($seconds / 31556926);
$timePeriod=$years;
$years = floor($seconds / 31556926);
$timePeriod = $years;
break;
default:
$days=floor($seconds / 86400);
$timePeriod=$days;
$days = floor($seconds / 86400);
$timePeriod = $days;
break;
}
@ -430,4 +401,5 @@ class TimeHelper extends Helper{
return $this->output($ret, $return);
}
}
?>