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;
|
return $currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
function date($date, $age = false) {
|
function date($date, $age = false, $class = null, $time = false) {
|
||||||
if (!$date) return null;
|
if (!$date) return null;
|
||||||
|
|
||||||
$date_fmt = 'm/d/Y';
|
if (empty($class))
|
||||||
return (self::$time->format($date_fmt, $date) .
|
$class = '';
|
||||||
($age
|
|
||||||
? ' (' . self::age($date, 60*60*24) . ')'
|
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) {
|
function datetime($datetime, $age = false, $class = null) {
|
||||||
if (!$datetime) return null;
|
return $this->date($datetime, $age, $class, true);
|
||||||
return (self::$time->nice($datetime) .
|
|
||||||
($age
|
|
||||||
? ' (' . self::age($datetime) . ')'
|
|
||||||
: ''));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function phone($phone, $ext = null) {
|
function phone($phone, $ext = null) {
|
||||||
@@ -81,10 +88,13 @@ class FormatHelper extends AppHelper {
|
|||||||
return $comment;
|
return $comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
function age($datetime, $min_span = 0) {
|
function age($datetime, $class, $min_span = 0) {
|
||||||
if (!isset($datetime))
|
if (!isset($datetime))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
if (empty($class))
|
||||||
|
$class = '';
|
||||||
|
|
||||||
$now = time();
|
$now = time();
|
||||||
$seconds = self::$time->fromString($datetime);
|
$seconds = self::$time->fromString($datetime);
|
||||||
$backwards = ($seconds > $now);
|
$backwards = ($seconds > $now);
|
||||||
@@ -95,9 +105,11 @@ class FormatHelper extends AppHelper {
|
|||||||
|
|
||||||
//pr(compact('now', 'seconds', 'backwards', 'timefrom', 'timeto', 'span', 'min_span'));
|
//pr(compact('now', 'seconds', 'backwards', 'timefrom', 'timeto', 'span', 'min_span'));
|
||||||
|
|
||||||
// If now, just return so
|
// If now, just use 'now'
|
||||||
if ($span === 0)
|
if ($span === 0) {
|
||||||
return __('now', true);
|
$approx = 0;
|
||||||
|
$unit = 'now';
|
||||||
|
}
|
||||||
|
|
||||||
// Display seconds if under 45 seconds
|
// Display seconds if under 45 seconds
|
||||||
if ($span < 45 && $span >= $min_span) {
|
if ($span < 45 && $span >= $min_span) {
|
||||||
@@ -164,20 +176,33 @@ class FormatHelper extends AppHelper {
|
|||||||
//pr(compact('span', 'min_span', 'approx', 'unit'));
|
//pr(compact('span', 'min_span', 'approx', 'unit'));
|
||||||
|
|
||||||
if ($approx == 0) {
|
if ($approx == 0) {
|
||||||
if ($unit == 'day')
|
if ($unit == 'now')
|
||||||
return __('today', true);
|
$age = 'now';
|
||||||
|
elseif ($unit == 'day')
|
||||||
return __('this ' . $unit, true);
|
$age = 'today';
|
||||||
|
else
|
||||||
|
$age = 'this ' . $unit;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (isset($relative))
|
||||||
|
$age = $relative;
|
||||||
|
elseif ($approx > $span)
|
||||||
|
$age = 'almost';
|
||||||
|
elseif ($approx < $span)
|
||||||
|
$age = 'over';
|
||||||
|
else
|
||||||
|
$age = '';
|
||||||
|
|
||||||
return (__(isset($relative)
|
$age .= ' ' . self::_n($approx, $unit);
|
||||||
? $relative
|
|
||||||
: ($approx == $span
|
if ($backwards)
|
||||||
? ''
|
$age .= ' ago';
|
||||||
: ($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