Modified the formatted date/age results to be span encapsulated for later css formatting.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@548 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -35,22 +35,29 @@ class FormatHelper extends AppHelper {
|
||||
return $currency;
|
||||
}
|
||||
|
||||
function date($date, $age = false) {
|
||||
function date($date, $age = false, $class = null, $time = false) {
|
||||
if (!$date) return null;
|
||||
|
||||
$date_fmt = 'm/d/Y';
|
||||
return (self::$time->format($date_fmt, $date) .
|
||||
($age
|
||||
? ' (' . self::age($date, 60*60*24) . ')'
|
||||
: ''));
|
||||
if (empty($class))
|
||||
$class = '';
|
||||
|
||||
if ($time)
|
||||
$date_html = self::$time->nice($datetime);
|
||||
else
|
||||
$date_html = self::$time->format('m/d/Y', $date);
|
||||
|
||||
$date_html = '<span class="fmt-date '.$class.'">'.$date_html.'</span>';
|
||||
|
||||
if ($age) {
|
||||
$date_html .= ' (' . self::age($date, $class, $time ? 0 : 60*60*24) . ')';
|
||||
$date_html = '<span class="fmt-dateage '.$class.'">'.$date_html.'</span>';
|
||||
}
|
||||
|
||||
return $date_html;
|
||||
}
|
||||
|
||||
function datetime($datetime, $age = false) {
|
||||
if (!$datetime) return null;
|
||||
return (self::$time->nice($datetime) .
|
||||
($age
|
||||
? ' (' . self::age($datetime) . ')'
|
||||
: ''));
|
||||
function datetime($datetime, $age = false, $class = null) {
|
||||
return $this->date($datetime, $age, $class, true);
|
||||
}
|
||||
|
||||
function phone($phone, $ext = null) {
|
||||
@@ -81,10 +88,13 @@ class FormatHelper extends AppHelper {
|
||||
return $comment;
|
||||
}
|
||||
|
||||
function age($datetime, $min_span = 0) {
|
||||
function age($datetime, $class, $min_span = 0) {
|
||||
if (!isset($datetime))
|
||||
return null;
|
||||
|
||||
if (empty($class))
|
||||
$class = '';
|
||||
|
||||
$now = time();
|
||||
$seconds = self::$time->fromString($datetime);
|
||||
$backwards = ($seconds > $now);
|
||||
@@ -95,9 +105,11 @@ class FormatHelper extends AppHelper {
|
||||
|
||||
//pr(compact('now', 'seconds', 'backwards', 'timefrom', 'timeto', 'span', 'min_span'));
|
||||
|
||||
// If now, just return so
|
||||
if ($span === 0)
|
||||
return __('now', true);
|
||||
// If now, just use 'now'
|
||||
if ($span === 0) {
|
||||
$approx = 0;
|
||||
$unit = 'now';
|
||||
}
|
||||
|
||||
// Display seconds if under 45 seconds
|
||||
if ($span < 45 && $span >= $min_span) {
|
||||
@@ -164,20 +176,33 @@ class FormatHelper extends AppHelper {
|
||||
//pr(compact('span', 'min_span', 'approx', 'unit'));
|
||||
|
||||
if ($approx == 0) {
|
||||
if ($unit == 'day')
|
||||
return __('today', true);
|
||||
if ($unit == 'now')
|
||||
$age = 'now';
|
||||
elseif ($unit == 'day')
|
||||
$age = 'today';
|
||||
else
|
||||
$age = 'this ' . $unit;
|
||||
}
|
||||
else {
|
||||
if (isset($relative))
|
||||
$age = $relative;
|
||||
elseif ($approx > $span)
|
||||
$age = 'almost';
|
||||
elseif ($approx < $span)
|
||||
$age = 'over';
|
||||
else
|
||||
$age = '';
|
||||
|
||||
$age .= ' ' . self::_n($approx, $unit);
|
||||
|
||||
if ($backwards)
|
||||
$age .= ' ago';
|
||||
|
||||
return __('this ' . $unit, true);
|
||||
}
|
||||
|
||||
return (__(isset($relative)
|
||||
? $relative
|
||||
: ($approx == $span
|
||||
? ''
|
||||
: ($approx > $span ? 'almost' : 'over')), true)
|
||||
. ' '
|
||||
. self::_n($approx, $unit)
|
||||
. ($backwards ? '' : __(' ago', true)));
|
||||
$age = '<span class="fmt-age '.$class.'">'.__($age, true).'</span>';
|
||||
|
||||
return $age;
|
||||
}
|
||||
|
||||
/*****************************
|
||||
|
||||
Reference in New Issue
Block a user